I am trying to get PEP8-naming working on my VSCode (Version: 1.72.2 (Universal)) without luck.
I have flake8, isort and mypy enabled in my code and this all works as expected. I have installed pep8-naming (conda install -c conda-forge pep8-naming) and it shows in my flake8 version info:
flake8 --version
4.0.1 (mccabe: 0.7.0, naming: 0.13.2, pycodestyle: 2.8.0, pyflakes: 2.4.0) CPython 3.8.13 on Darwin
However, I am not seeing the errors for naming conventions showing in my VSCode editor.
I have the following set in my settings.json file
{
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.linting.mypyEnabled": true,
"python.linting.pycodestyleEnabled": true,
"python.linting.pycodestyleArgs": ["--max-line-length=120"]
}
What am I missing so as to be able to see (for instance) that variables are named in Camel case rather than lower case with underscores?
I have tried this without any luck.
Related
I have been using flake8 for linting but somehow it stopped showing me errors in the code in any of my workspaces (the squiggly underlines in the editor).
flake8 is installed in my conda environment.
Here is my settings.json:
{
"python.linting.enabled": true,
"python.linting.lintOnSave": true,
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": [
"--max-line-length=80",
"--docstring-convention=google",
"--verbose"
]
}
When I run flake8 from the console, it does show me the errors.
I am using VS Code version 1.72.2 on Windows, and I installed flake8 version 5.0.4. Any idea what could be wrong with it?
Open Command Palette and type in Linter. Select the option Python: Select Linter and it opens up all the available linters.
In the drop down, select Flake8 and if required install it.
That should work now!
Background
In a repo, we have a pre-commit configuration that requires version 2.2.1 of prettier:
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.2.1"
hooks:
- id: prettier
And in my .devcontainer I specify use of prettier, so that my code gets formatted on save:
{
// ...
"settings": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
// ...
}
}
Prettier is installed by the vscode extension, not globally, so doing:
npm list -g | grep prettier
in my dev container doesn't list anything installed.
The problem
A different version of prettier is being used, and I get a conflict in how it formats arrays in json files. Every time I open up a particular json file, it gets reformatted by my editor.
Also, if I rebuild my devcontainer, I'm then liable to unknowingly switch the version of code formatter I use, leading to git hell.
The question
How can I specify that my devcontainer use an exact prettier version so I can enforce the same behaviour in my dev environment as in our code quality tools?
I have already tried this:
You can set up the prettier extension to use a resolved version of prettier, according to the instructions under "Prettier Resolution" here.
So I added to the Dockerfile:
# Ensure prettier is installed globally so the esbenp.prettier-vscode can find a specific version
# as discussed here:
# https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
# NB You can remove the -g flag if you have a node project. I install globally because I use prettier on all projects, whether they have a node_modules folder or not.
RUN npm install prettier#2.2.1 -g -D --save-exact
And in the .devcontainer.json settings, told the extension to resolve the prettier module instead of using its own:
{
// ...
"settings": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"prettier.resolveGlobalModules": true,
// ...
}
}
That didn't work so I also tried adding:
"prettier.prettierPath": "$(npm root -g)/prettier",
Which also didn't work; the prettier extension is still using it's own version.
You can set the version in the .devcontainer like this:
"extensions": ["esbenp.prettier-vscode#8.0.1"],
The trick is you also have to turn off extension automatic updates:
"settings": {
"extensions.autoCheckUpdates": false,
"extensions.autoUpdate": false
},
Note: This turns off automatic updates for all extensions.
Also, RUN npm install prettier#2.2.1 -g -D --save-exact in the Dockerfile adds the prettier CLI to the environment, not the VS Code extension.
I'm setting up a new macOS Catalina machine and I am receiving the following errors in the Problems window which appear to be originating from the Python Language Server (as opposed to a linter). All imports are failing, these are just some examples.
_helpers.py
unresolved import 'datetime' Python(unresolved-import) [2, 8]
unresolved import 'json' Python(unresolved-import) [3, 8]
unresolved import 'logging' Python(unresolved-import) [4, 8]
These are showing up for built-in libraries as well as third party libraries I'm importing, most notably Google App Engine via the Gcloud SDK. All of the searching I've done suggests it's a problem with the paths, but nothing I've tried works. Also worth noting that if I go into the Terminal window in vscode, open an interactive Python shell and import these libraries, everything works.
My system:
macOS Catalina 10.15.6
Python installed via pyenv (pyenv installed via homebrew)
Pyenv global version: 3.8.3
Pyenv local version for current repository: 2.7.18 + 3.8.3 (The repo is still on Python 2 but some of our build tools require Python 3)
Here's my settings files:
// User settings.json
{
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"python.languageServer": "Microsoft",
"python.pythonPath": "~/.pyenv/shims/python",
"python.analysis.downloadChannel": "stable",
}
// Workspace settings.json (in .vscode)
{
"files.exclude": {
"**/*.pyc": true
},
"python.pythonPath": "${workspaceFolder}/Venv/bin/python",
"python.autoComplete.extraPaths": [
"${workspaceFolder}/lib/",
"~/google-cloud-sdk/",
"~/google-cloud-sdk/platform/google_appengine",
"~/google-cloud-sdk/platform/google_appengine/lib/",
"~/google-cloud-sdk/lib"
],
"files.associations": {
"*.html": "jinja-html"
}
}
I'm losing my mind here. Any help would be greatly appreciated.
I'm going crazy, VSCode is giving me this error EVERYWHERE (including js files and .gitignore .dockerignore files, even for simple lines such as node_modules in .gitignore)
I need some ideas
my config file
{
"workbench.iconTheme": "vscode-icons",
"workbench.colorTheme": "One Monokai",
"vsicons.dontShowNewVersionMessage": true,
"editor.formatOnSave": true,
"editor.tabSize": 4,
"prettier.tabWidth": 4,
"editor.tabCompletion": "on",
"prettier.singleQuote": true,
"prettier.printWidth": 80,
"window.zoomLevel": 0,
"editor.acceptSuggestionOnEnter": "off",
"editor.minimap.enabled": false
}
My extensions are pretty standard
prettier
react snippets
docker
sass
eslint
some random themes
editor config
graphql
auto-import
This issue randomly appeared for me today as well.
This process worked to solve it on my system, although I don't know what actually caused the issue.
restart vscode
check for a vscode update
(optional) Restart system
If 1-3 don't work you can try
In the command palette run Extensions: Disable All Installed Extension
These steps worked for me when this issue started popping up after installing macOS 10.15 Catalina.
Reinstall node.js using nvm, e.g. nvm install 10 && nvm use 10 to install and use the latest node.js 10.x version (pick your preferred version)
Reinstall eslint via npm i -g eslint
Restart VS Code
I am new to python and writing my first python file using Visual Studio Code. Till yesterday the code was working fine. But today it is starting to give ModuleNotFoundError. I double-checked the package and the package is there under lib folder of the virtual environment. Moreover, IntelliSense is also working fine, whenever I write import it shows the requests module in the available list. I am facing problems with IntelliSense also, as sometimes it stops working for no reason.
The major change that I did before executing the code is the integration of GitLab with my project.
Python Version: 3.6.2
Operating System: Windows
Git Version: 2.23.0
Pylint Version: 2.3.1
pip Version: 19.2.2
Requests Version: 2.22.0
Pytest Version: 5.1.1
Enabled Extensions:
Npm
Npm Intellisense
Ayu
Code Runner
AYU
Markdownlint
Predawn Themekit
Python by Microsoft
Can anyone have gone through with the same problem? Please help me to resolve this issue.
Attachments
Issue resolved I was running it using Ctrl+Alt+N (code-runner shortcut to run a project)which was creating this issue. But running the file in terminal using Run Python File in Terminal (option in the context menu when we do right-click in source .py file) giving me the expected result without any error.
Then I googled for how to alter this behavior so that I can get the same results by using Ctrl+Alt+N as well.
I found that; I need to add the following script under user's settings.json.
"code-runner.executorMap": {
"python": "h:\\practice\\virtualenv\\Scripts\\activate.bat && python -u"
}
Here is my complete user's settings.json
{
"workbench.colorTheme": "Predawn",
"workbench.iconTheme": "ayu",
"window.zoomLevel": 0,
"code-runner.executorMap": {
"python": "h:\\practice\\virtualenv\\Scripts\\activate.bat && python -u"
}
}