Although I seem to have configured both linitng and formatting properly, the linting runs but the black formatting does not.
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": [
"--max-line-length=110"
],
"python.linting.lintOnSave": true,
"python.formatting.provider": "black",
"python.formatting.blackPath": "/usr/local/bin/black",
"python.formatting.blackArgs": [
"--line-length",
"110"
],
"editor.formatOnSave": true,
I have checked, that black is properly configured and I can run the formatting from the command-line without issues.
But when saved in the IDE, black does not format the file. It also does not complain, there are no error-messages that pop up and nothing showing up in the logs. It just does not run the formatting at all.
I am running this insisde a docker-container using remote-editing: not sure, if this makes a difference.
The black-version is:
black>=19.3b0
and the vscode-version is 1.36.1.
Thx for any help, as right now I am pretty clueless, why the black-formatting does not run...
The line argument for black is wrong, it should be
--line-length=120
according to https://stackoverflow.com/a/58048911/4435175.
Late answer, in case it helps anybody. I had the same problem and resolved it as below
I needed to have this line in user settings.json
"editor.defaultFormatter": "ms-python.python"
Otherwise, I guess, the formatting was overwritten by my default formatting option which was
"editor.defaultFormatter": "esbenp.prettier-vscode",
So my overall settings for formatting related stuff were as below
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "ms-python.python"
},
"[javascript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"python.formatting.provider": "black",
"python.formatting.blackPath": "/home/<user>/anaconda3/bin/black",
This line "editor.defaultFormatter": "ms-python.python" could also have been activated as below from VS-Code command-pallette (Ctrl + shift + P).
Format Document with > Configure Default formatter > Select Python
But here is a wild guess: I started the dockerd manually from the command-line using sudo: This gave me all kind of weird issues (files created from inside the container e.g. migrations or cache-files ended up being owned by root. I recently moved the dockerd into a service, now suddenly black is running on save. The root of all evil could have been rights-issues, that come from the fact that the dockerd was run as sudo and not as a service.
I add the blackPath:
"python.formatting.provider": "black",
"python.formatting.blackPath": "C:/conda/Scripts/black.exe",
and solve this issue.
I use miniconda.
Related
I have reinstalled my PC and get crazy about initialising VScode correctly.
I want to use syntax highlighting in Python, I use tabs instead of space and I don't want to see pep8 warnings.
After ours of debugging, I dont have syntax highlighting, errors due to tabs and I see all pep8 warnings.🙈
I have installed Python and Pylance as extensions and currently, my settings.json looks like this:
{
"[python]": {
"editor.insertSpaces": true,
"editor.tabSize": 4
},
"python.linting.enabled": false,
"files.exclude": {
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true
},
"java.semanticHighlighting.enabled": true,
"terminal.integrated.enableMultiLinePasteWarning": false
}
Is there anybody who can knows what to do?
Edit: After reloading, the messages about space vs tabs have disappeared.
If you want to ignore the messages prompted by the pylint you can add this in the settings.json:
"python.linting.pylintArgs": ["--disable", "C"],
And it means this:
Convention (C)
Refactor (R)
Warning (W)
Error (E)
Fatal (F)
And you can do it like this to disable multi types of the message:
"python.linting.pylintArgs": ["--disable", "C,R,W"],
I have a Pulumi script to deploy few services. Everything is fine except I don't understand how to apply a runtime to Functions App
api_function_app = azure.appservice.FunctionApp("ApiFunctionApp",
location=resource_group.location,
enabled= True,
enable_builtin_logging = True,
resource_group_name=resource_group.name,
app_service_plan_id=functionStoragePlan.id,
storage_account_name=functionStorageAccount.name,
storage_account_access_key=functionStorageAccount.primary_access_key, os_type="linux", version="~3")
Has anyone seen any example of this?
I believe you need to set a value for FUNCTIONS_WORKER_RUNTIME application setting
...
app_settings={
"FUNCTIONS_WORKER_RUNTIME": "python"
},
...
I'm having an issue regarding Visual Studio Code OneDark Pro theme. I would like to change the color of variables (only variables I declare, not method calls, etc. but when I try to do this using
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "source.python",
"settings": {
"foreground": "#E06C75"
}
}
]
}
I get this (I wrote a code sample to illustrate what is happening):
As you can see, colons are in red, every variables even the "for i in..." and the full "os.system.getcwd()" are in red.
I only want the variables I declare to be in red. How can I do that ?
Thank you in advance!
You can modify the editor color in VSCode with Syntax Highlighting like this:
"editor.tokenColorCustomizations": {
"variables": "#c3e01f"
},
Or the Semantic Highlighting like this:
"editor.semanticTokenColorCustomizations": {
"[The Theme Name]": {
"rules": {
"variable.declaration": "#c3e01f"
}
}
},
If you don't know the scope of the object which you want to customize, you can use the built-in tool in VSCode: Developer: Inspect Editor Tokens and Scopes(Command Palette).
And I think this article and this one can help you understand the color customization in the VSCode.
I've been searching online for quite a while now and can't seem to find a solution for my problem. I installed Pylance (the newest Microsoft interpreter for Python) and can't seem to disable linting at all. I've tried a lot of options but none worked. Here's a screenshot of how annoying linting is in my code now.
Here's how my VSCode Settings file looks like:
{
// "python.pythonPath": "C://Anaconda3//envs//py34//python.exe",
// "python.pythonPath": "C://Anaconda3_2020//python.exe",
// "python.pythonPath": "C://Anaconda3_2020_07//python.exe",
"python.pythonPath": "C://Anaconda3//python.exe",
"python.analysis.disabled": [
"unresolved-import"
],
"editor.suggestSelection": "first",
"editor.fontSize": 15,
"typescript.tsserver.useSeparateSyntaxServer": false,
"workbench.colorTheme": "Monokai ST3",
"workbench.colorCustomizations": {
"editor.background": "#000000",
"statusBar.background": "#000000",
"statusBar.noFolderBackground": "#212121",
"statusBar.debuggingBackground": "#263238"
},
"window.zoomLevel": 0,
"editor.renderLineHighlight": "none",
"editor.fontFamily": "Meslo LG L",
"editor.tabCompletion": "on",
"editor.parameterHints.enabled": true,
"python.terminal.executeInFileDir": true,
"python.terminal.launchArgs": [
"-u"
],
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"editor.lineHeight": 0,
"workbench.editor.scrollToSwitchTabs": true,
"python.autoComplete.showAdvancedMembers": false,
"python.languageServer": "Pylance",
"python.linting.enabled": false,
"python.linting.pylintEnabled": false,
"python.linting.lintOnSave": false,
"python.linting.flake8Enabled": false,
"python.linting.mypyEnabled": false,
"python.linting.banditEnabled": false,
"python.linting.pylamaEnabled": false,
"python.linting.pylintArgs": [
"--unsafe-load-any-extension=y",
"--load-plugin",
"pylint_protobuf",
"--disable=all",
"--disable=undefined-variable",
],
"python.linting.mypyArgs": [
"--ignore-missing-imports",
"--follow-imports=silent",
"--show-column-numbers",
"--extension-pkg-whitelist=all",
"--disable=all",
"--disable=undefined-variable",
],
}
Any thoughts?
Any help is much appreciated.
You can disable the language server with:
"python.languageServer": "None"
I was able to click on the Extensions within VSC, search for Pylance and then right click to uninstall. You can also disable.
One way of getting rid of those warnings in your picture is to disable the Pylance by setting "python.languageServer": "None"(already mentioned by the accepted answer).
But you are basically disabling the language server which means you will lose all the help from Pylance. I don't think this is what you want.
Instead you can exclude some paths and those won't get type-checking at all. I usually do it for Python's standard library.
In previous versions of Pylance, you could create a pyrightconfig.json(Pylance is built on top of Pyright, that's why) in the root of your workspace and put this inside(for more information - click):
{
"ignore": [
"path to your third-party package or stdlib or ..."
],
}
But since now (October 2022), you can directly set it in settings.json:
"python.analysis.ignore": ["path to your third-party package or stdlib or ...", ]
Remember you can use wild-cards in paths. This way your custom modules are only getting checked.
If you want to completely disable type-checking:
"python.analysis.typeCheckingMode": "off"
Disabling language server works as answered by maxm. This will also disable other features.
Instead, just ignore the warnings and errors of pylance by setting below in settings.json of .vscode.
"python.analysis.ignore": [
"*"
]
The other features will be present with out disabling pylance.
I had to disable the format on save setting, because Python PEP8 Autoformat plugin reformatted my code, causing a syntax error.
My code (focus on last lines):
from typing import List, Tuple
from my_enent import MyEvent
def my_preprocessor(raw_event, context: object, env: MyEnv) \
-> Tuple[dict, VideoFreezeEvent]:
if isinstance(raw_event, dict) and 'Output' in raw_event:
# comments
raw_state_machine_event = json.loads(raw_state_machine_event['Output'])
# comments
parallel_outputs = raw_state_machine_event.get(
'my_data').get('parallel_outputs')
if len(parallel_outputs) > 0:
state_machine_event = parallel_outputs[0]
my_list: List[MyEvent] = [
my_util.populate_dataclass(MyEvent, event)
for event in parallel_outputs
]
another_event = events_list[0]
After the plugin reformats the code, the relevant part of the code that causes the syntax error becomes:
if len(parallel_outputs) > 0:
state_machine_event = parallel_outputs[0]
my_list:
List[MyEvent] = [
my_util.populate_dataclass(MyEvent, event)
for event in parallel_outputs
]
another_event = events_list[0]
How can I prevent/teach the plugin to not break this code please?
Some package settings that might be the way through, if a passage exists in the first place:
{
// list codes for fixes; used by --ignore and --select
"list-fixes": false,
// do not fix these errors / warnings (e.g. [ "E501" , "E4" , "W"])
"ignore": [],
// select errors / warnings (e.g. ["E4", "W"])
"select": [],
// Maximum line length
"max-line-length": 79
}
Your linter sounds like it is rather out of date, as it neither recognizes the walrus operator := or your type annotations. Looking at the plugin's Package Control page, you can see that up at the top it says "MISSING", which means the source code repo is gone, most likely because it's not being maintained anymore. The package was last modified 5 years ago, and there are no recent installations, so there's very strong evidence it's dead.
As a replacement plugin, I'd highly recommend Anaconda
(not related to the Anaconda Python distribution). It works great (mostly), is under active development with frequent updates, bugfixes, and new features, and does code completion and code intelligence along with linting/autoformatting. The website goes through all the configuration you need to do, and how to turn off and on the different features. There are several different linting/formatting options to choose from, including AutoPEP8, PyFlakes, and PyLint. I really like it.
(And no, I'm not associated with it or its author in any way.)
I found workaround. Go to plugin settings (Preferences -> Package Settings -> Python PEP8 Autoformat -> …), add ignore rule, e.g.:
{
// Workaround for typing hints
"ignore": ["E701"],
}
I guess it ignores this warning: https://www.flake8rules.com/rules/E701.html
Seems not very harmful.
I installed Black via pip, and used sublack Sublime plugin, which appears to be running smoothly.
Anaconda Sublime plugin suggested by MattDMo is cool, but a bit slow (with the default settings at least), any my Mac laptop is fairly new.