Open DetachHead opened 1 year ago
I think it just depends on whether the packages are in the same environment as currently-running interpreter (notice your first example vs. the next two). I would assume that the isort and all other Python extensions have the same behavior. I'm not sure there's really a good way to avoid this.
Respecting ignorePatterns
would help with this but still wouldn't catch your typing.py
example. (See: https://github.com/astral-sh/ruff-vscode/issues/175.)
I recommend adding something like this to your configuration:
{
"ruff.args": [
"--extend-exclude=.vscode/**/*.py",
"--extend-exclude=Python/lib/**/*.py",
]
}
unfortunately that doesn't seem to work due to https://github.com/microsoft/vscode-black-formatter/issues/251#issuecomment-1595019087 :(
@DetachHead Adding ruff.args
to the global User settings.json
file worked for me:
This is what I'm using right now:
"ruff.args": [
"--extend-ignore=E501",
"--extend-exclude=/**/3rdparty_repositories/**/*.py",
"--extend-exclude=/**/site-packages/**/*.py",
],
Only tangentially related, but I also use this to quickly toggle python analysis & type checking:
https://github.com/Diogo-Rossi/vscode-settings-switcher
"settingsSwitcher.lists": {
"Python analysis & linting": {
"Full": {
"description": "Pylance + Pyright + ruff",
"python.analysis.typeCheckingMode": "strict",
"python.languageServer": "Pylance",
},
"Minimal": {
"description": "Only ruff stays on",
"python.analysis.typeCheckingMode": "off",
"python.languageServer": "None",
},
},
},
Being able to set these up depending on file patterns would be great as well!
@charliermarsh What prevents ruff-vscode to ship these as standard settings?
@TheRealBecks - Are you referring to settings like --extend-exclude
? Exposing those in the VS Code UI?
The ruff-vscode
extension is trying to lint files like:
/usr/lib64/python3.10
/home/becks/.local/share/virtualenvs/my_project-Gchh4Lgq/lib/python3.10/site-packages/django/urls/base.py
(site-packages
)That only happens with the extension, but the command line tool ruff
works just fine. So it seems that the extensions settings need to exclude additional files by default?
@DetachHead I've been dealing with this issue as well, and the extension has been linting standard library modules even when they are excluded with --extend-exclude
. However, I discovered today that I could get the directories to be properly excluded by making the c drive in my --extend-exclude
lowercase instead of uppercase.
Simply changing from:
"ruff.lint.args": [
"--extend-exclude=C:/Users/username/AppData/**/*",
"--extend-exclude=C:/Users/username/.vscode/**/*",
],
to
"ruff.lint.args": [
"--extend-exclude=c:/Users/username/AppData/**/*",
"--extend-exclude=c:/Users/username/.vscode/**/*",
],
fixes the issue.
Would it be possible to exclude the standard library within the vscode extension, independent to the current environment per default?
The problem with using something like --extend-exclude=
is that it breaks as soon the environment changes though using devcontainers, multi device/OS etc.
yeah, ideally you'd be able to commit this config but you can't because those paths will be different for each user
Why does ruff
even run outside of the ./
folder? When I execute ruff check ./
in my repository the output is fine. With the VS Code extension seems to be using another folder for ruff. Do we know which command will be used by VS Code?
This is extremely annoying. I get output about files I do not even have open nor do I want to know about their issues. I think shipping a default to ignore */site-packages/*
and others would be good.
@Tatsh -- That does seem reasonable to me, although it won't necessarily cover opening files from Python standard library.
@Tatsh -- Added in the next Ruff release: https://github.com/astral-sh/ruff/pull/9188
This seems to be partially fixed with Ruff 0.1.9 but the defaults in Ruff (as far as I can tell) still allow for stdlib to be checked unnecessarily.
I'd love to improve the situation here, though it's not clear to me how we can definitively detect that a file is a stdlib file.
Ruff would be the best place to detect this rather than trying to make exclude filters. The best way is to inspect where some library like sys is located. If it comes back as an invalid parh that most likely means the stdlib is in a zip file.
For now to cover system stdlib:
For Linux and macOS: /usr/**/*.py
and /opt/**/*.py
The latter is to cover the standard location for MacPorts.
On Windows it's a bit more complicated. First is escaping \ but also that the stdlib that python.org ships is in a zip file to hopefully speed up IO. I think this means Ruff is not analysing it at all (and sadly VS Code cannot open these libs either for examination with ctrl+click). Assuming we can use / on Windows:
c:/msys/**/*.py
c:/program*/**/*.py
And you may need to cover the virtualenv path stdlib which is where inspection is needed.
it seems like ruff tries to avoid standard library files:
but it only seems to work on third party packages. it still runs on standard library and typeshed files: