VS Code ignores global `tabSize` setting - python

Relevant user settings:
"editor.tabSize": 2,
"editor.detectIndentation": false,
Workspace settings are empty. Using VS Code 1.52.0.
.cpp files get formatted properly (using the Format Document option), yet in .py files it changes all indents to 4 spaces and inserts some unnecessary vertical spacing (like, double empty lines in some places). The only settings specific to Python are pythonPath and condaPath.
Edit: Inserting this:
"python.formatting.autopep8Args": [
"--ignore",
"E301, E302, E305, E306, E101, E11"
],
into settings.json stops it from changing 2 space indents into 4 space indents, but now it just ignores indentation altogether. I want it to correct indentation to 2 spaces. Used this for reference.
Edit: I want this:
to be fixed to this:
but it gets fixed like this instead:

Please use the following settings in "settings.json":
"python.formatting.autopep8Args": ["--indent-size=2"],
Related settings I use:
"editor.tabSize": 2,
"editor.detectIndentation": false,
"editor.renderWhitespace": "all",
"python.formatting.provider": "autopep8",
"python.formatting.autopep8Args": ["--indent-size=2"],

Related

How do i remove the unnecessary text in the terminal in vscode?

Hi i'm new into vscode and when i run a program there is some text that i want to get rid of.
i mainly want to remove the first two paragraphs, but also removing the path would be ideal
i tried code runner but thats not the solution i'm looking for
i also tried changing the color to black but i reckon there is a way to remove it
Adding the "-NoLogo" start parameter will remove the paragraph of text; If you open your settings file (Ctrl+Shift+P and then type "Settings" -> User Settings JSON), you can use the following bit of configuration:
// should go in the main JSON object with the other keys
"terminal.integrated.profiles.windows": {
// it might generate some more profiles automatically, but powershell is what matters
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": ["-NoLogo"]
}
}
I believe by default those lines will always appear because those are the one that show up when you open cmd on Windows.
Also, by default, the path open to the current project folder, that the reason why you see the path.
You can do a cls to clear the terminal, but the path will remain unless you change the directory.
You can read more about VS Code integrated terminal here and about terminal profiles here
First go to terminal settings and then the add -nologo arg

Render lambda keyword as the greek symbol in VSCode?

I want vscode to render lambda as λ in my editor. I do not want it to replace the word with the symbol, as that will just break my code since Python doesn't interpet λ as a keyword. It needs to purely be a rendering change, with the actual code still being lambda.
Are there any extensions that do this? Is it possible within the VSCode environment to do this?
The extension Prettify Symbols Mode allows you to do this. You'll have to edit your settings.json to specify this particular subsitution. To do this install the extension then go to the extension's settings page -> "Prettify Symbols Mode: Substitutions" -> edit in settings.json. Then add this:
"prettifySymbolsMode.substitutions": [
{
"language": "python",
"substitutions": [
{
"ugly": "lambda",
"pretty": "λ"
},
]
}
]
to the file.
There are more complete options and details available on the extension's page, and here is a more complete example of a Python config (with a lambda expression).

Why aren't my sublime-anaconda gutter marks showing up?

I was watching Corey Schafer's video on YouTube on 'Setting up a Python Developer Environment in sublime Text'.
I installed the anaconda package, but for some reason, the gutter marks (for linting) are not showing in the line number column.
I have not altered the default settings.
I have added Corey's user settings to the sublime-anaconda user settings file:
{
"auto_formatting": true,
"autoformat_ignore":
[
],
"pep8_ignore":
[
"E501"
],
"anaconda_linter_underlines": false,
"anaconda_gutter_marks": true,
"anaconda_linter_mark_style": "none",
"display_signatures": false,
"disable_anaconda_completion": true,
"python_interpreter": "/usr/local/bin/python3"
}
I should note that I have also tried adding:
"anaconda_gutter_marks": true,
to no avail.
I have also saved the settings and restarted sublime text.
You need to change your "python_interpreter" setting to the actual path of the python.exe executable on your system. Opening cmd and entering which python may be helpful in finding it. Once you've found it, change and \ characters to / - for example, C:\Python38\python.exe would become C:/Python38/python.exe.
Where you've copied the code from correy's GitHub there is a line called "python_interpreter": "/usr/local/bin/python3" just delete that line and restart sublime and the errors should be showing again.
Check the screenshot:

How can I auto-format a Python file that contains long strings to pass when I run flake8?

I have a lot of json style data that I am storing for some unit test api mocking I am working on. The data is stored in a .py file in the form of a Python dictionary, I didn't write it so I had no control over the line length when it was created.
I am now under going code review and this file is failing flake8 because some of the lines are +1000 chars. I've tried autopep8, pep8 and black, I've tried changing the line wrap in VS Code and I've tried searching for an answer online but am not getting anywhere.
Is there a way of auto formatting this kind of file because doing it manually will take ages and be very tedious. Thanks
EDIT
I have this config in my settings.json
{
"python.pythonPath": "C:\\Users\\andre_2d8wovo\\.virtualenvs\\asana_data-LIIUPrbn\\Scripts\\python.exe",
"editor.detectIndentation": false,
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.tabSize": 4,
"python.formatting.autopep8Args": ["--max-line-length=80"],
"python.formatting.provider": "autopep8",
"python.linting.enabled": true,
"python.linting.lintOnSave": true,
"python.linting.pycodestyleArgs": ["--max-line-length=80"],
"python.linting.pycodestyleEnabled": true,
"python.linting.pylintEnabled": false
}
If you prefer the line to be very long, you can use a comment to tell flake8 to ignore the fact that the line is long by writing # noqa: E501 at the end of the line.
Black currently does not split strings, there is an open issue for this on their github.

Visual Studio code with PyLint and autoPep8: How can I avoid PyLint to complain about my line length?

I recently switched to Visual Studio Code and I have to say I love it so far.
I'm working on a Python project, which includes the pip packages pylint and autopep8 and I configured VSCode to format the code according to these packages.
Only problem is: In the Python project I'm working on the line length is 100. So all my code looks like this:
The error says: E501:line too long (97 > 79 characters). Here are my VSCode settings:
{
"python.pythonPath": "~/.envs/myProject/bin/python",
"python.linting.pep8Enabled": true,
"python.linting.pylintPath": "~/.envs/myProject/bin/pylint",
"python.linting.pylintArgs": ["--load-plugins", "pylint_django", "--max-line-length=100"],
"python.formatting.autopep8Args": ["--max-line-length=100"],
"python.linting.pylintEnabled": true,
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
".vscode": true,
"**/*.pyc": true
}
}
These settings at least now ensure that format on save keeps the lines at 100 max and does not wrap all my files lines to 79. Still it would be awesome without the warnings.
How do I disable these linter warnings?
I figured out how to do this. Add this line to your settings:
"python.linting.pep8Args": ["--max-line-length=100"],
For pycodestyle in Vscode 1.15.1:
"python.linting.pycodestyleArgs": ["--max-line-length=100"],
As of 2021 (Pylint reference), add this to your .vscode/settings.json file:
"python.linting.pylintArgs": ["--max-line-length=100"]
2020 version:
Add the following entry to your settings.json file
"python.linting.pylintArgs": ["-d", "C0301"],
If you haven't disabled these errors, and encounter a line too long warning, under "Problems" in VSCode, or by hovering over the underlined error, you will see VSCode say something along the lines of:
Line too long (188/100)Pylint(C0301:line-too-long)
As you can see, the value C0301 comes directly from this warning message. You can additionally disable other warnings by their error code as well.
For me the following worked. (VSCode version == 1.73.0)
Go to Settings.
Search "pylint".
Scroll down to "Pylint : Args"
Click "Add Item"
Type this in, --max-line-length=200
Adjust the max-line-length to your desired length.

Categories