# -*- coding: utf-8 -*-
from setuphelpers import *
import json
r"""
Usable WAPT package functions: install(), uninstall(), session_setup(), audit(), update_package()
Configuration procedure: https://supunkavinda.blog/vscode-editing-settings-json
File -> Preferences -> Settings -> Extensions -> Scroll down and find "Edit in settings.json"
Or in these paths in your OS :
Windows : %APPDATA%\Code\User\settings.json
macOS : $HOME/Library/Application Support/Code/User/settings.json
Linux : $HOME/.config/Code/User/settings.json
https://code.visualstudio.com/docs/editor/extension-marketplace#_workspace-recommended-extensions
"""
def install():
pass
def session_setup():
print("Applying: VSCode configuration")
# Initializing variables
if get_os_name() == "Windows":
user_conf_dir = makepath(user_appdata, "Code", "User")
elif get_os_name() == "Linux":
user_conf_dir = makepath(user_home_directory(), ".config", "Code", "User")
elif get_os_name() == "Darwin":
user_conf_dir = makepath(user_home_directory(), "Library", "Application Support", "Code", "User")
user_conf_file = makepath(user_conf_dir, "settings.json")
user_conf_content = r"""{
"update.mode": "none",
"update.enableWindowsBackgroundUpdates": false,
"update.showReleaseNotes": false,
"powershell.promptToUpdatePowerShell": false,
"extensions.autoCheckUpdates": false,
"extensions.autoUpdate": false,
"extensions.ignoreRecommendations": true,
"telemetry.telemetryLevel": "off",
"redhat.telemetry.enabled": false,
"npm.fetchOnlinePackageInfo": false,
"json.schemaDownload.enable": false,
"editor.wordWrap": "on",
"editor.minimap.enabled": false,
"workbench.activityBar.visible": true,
"workbench.startupEditor": "none",
"restructuredtext.preview.scrollEditorWithPreview": false,
"restructuredtext.preview.scrollPreviewWithEditor": false,
"markdown.preview.scrollEditorWithPreview": false,
"markdown.preview.scrollPreviewWithEditor": false,
"files.autoSave": "afterDelay",
"git.openRepositoryInParentFolders": "always",
"git.autofetch": true,
"files.associations": {
"control": "yaml"
}
}"""
user_conf_data = json.loads(user_conf_content)
if isfile(user_conf_file):
user_conf_data = json_load_file(user_conf_file)
mkdirs(user_conf_dir)
print("Updating: %s" % user_conf_file)
user_conf_data.update(json.loads(user_conf_content))
user_conf_data.pop("python.formatting.blackPath", None)
user_conf_data.pop("python.formatting.provider", None)
user_conf_data.pop("python.formatting.blackArgs", None)
user_conf_data.pop("python.formatting.blackPath", None)
user_conf_data.pop("python.languageServer", None)
json_write_file(user_conf_file, user_conf_data)
def json_load_file(json_file, encoding="utf-8"):
r"""Get content of a json file
Args:
path (str): path to the file
Returns:
dictionary (dict)
"""
with open(json_file, encoding=encoding) as read_file:
return json.load(read_file, cls=TrailingCommaJSONDecoder)
class TrailingCommaJSONDecoder(json.JSONDecoder):
def decode(self, s, *args, **kwargs):
# Remove trailing commas before decoding
s = self._remove_trailing_commas(s)
return super().decode(s, *args, **kwargs)
def _remove_trailing_commas(self, s):
# A simple implementation to remove trailing commas
# This might not handle all edge cases, but it works for most common cases
return s.replace(",}", "}").replace(",]", "]")