Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore flag for files and folders #422

Closed
pikeas opened this issue Sep 25, 2020 · 19 comments
Closed

Ignore flag for files and folders #422

pikeas opened this issue Sep 25, 2020 · 19 comments
Labels
waiting for user response Requires more information from user

Comments

@pikeas
Copy link

pikeas commented Sep 25, 2020

It's very common to have a virtualenv folder in a project directory. Python files in a virtualenv should be skipped by Pylance, either by default (.venv, site-packages, etc) or via a configurable ignore/exclude setting.

@jakebailey
Copy link
Member

jakebailey commented Sep 25, 2020

We already ignore these files for purposes of workspace symbols, and the rest of the analysis is lazy and will only load files as needed to analyze the code you've written. Workspaces that contain their virtual environments are the main thing that we test with ourselves as that's the most common setup.

Can you describe what it is that isn't working about Pylance for you? Are you finding something to be slow? Are results showing up that shouldn't be there in a search? Are diagnostics appearing in the wrong files?

@jakebailey jakebailey added the waiting for user response Requires more information from user label Sep 25, 2020
@github-actions github-actions bot removed the triage label Sep 25, 2020
@pikeas
Copy link
Author

pikeas commented Sep 25, 2020

Thanks for the quick reply, @jakebailey!

I have VS Code 1.49.2 (latest release) open into a folder containing a .venv folder, which is set as my active Python environment. Here's what I see in the Problems pane when I open, for example, .venv/lib/python3.8/site-packages/pytest/__init__.py:

Screen Shot 2020-09-25 at 15 47 29

Pylance appears to be analyzing this file. This happens for any site-packages/**/*.py file and is rather distracting. Loving Pylance generally, however! If this is unexpected behavior, what setting(s) should I check? I don't see anything that seems relevant in settings.json.

@jakebailey
Copy link
Member

Is your diagnostic mode set to "openFilesOnly"? That should be the default, though even in that mode I wouldn't expect it to behave this way.

@pikeas
Copy link
Author

pikeas commented Sep 25, 2020

Is your diagnostic mode set to "openFilesOnly"? That should be the default, though even in that mode I wouldn't expect it to behave this way.

Yes, I have: "python.analysis.diagnosticMode": "openFilesOnly".

@jakebailey
Copy link
Member

Did you open that file, or does the diagnostic appear if you've only opened one of the files in your project that imports it?

@pikeas
Copy link
Author

pikeas commented Sep 25, 2020

I did some digging and found a clue. It matters whether the file/module has been imported into the project.

Open via file explorer: ❌ Pylance analyzes it
Add as import in project, close and reopen via explorer: ✅ Pylance ignores it
Add as import in project, open via cmd-click jump: ✅ Pylance ignores it
Remove import, close and reopen: ❌ Pylance analyzes it

@jakebailey jakebailey added needs investigation Could be an issue - needs investigation and removed waiting for user response Requires more information from user labels Sep 28, 2020
@benblo
Copy link

benblo commented Nov 5, 2020

I too would like the option to exclude some directories.

I have a site-packages embedded in a subdir of my workspace directory (not a venv because reasons), set as excluded in the workspace settings, but added in python.analysis.extraPaths for autocompletion.
Today I tried enabling "python.analysis.diagnosticMode": "workspace" and was instantly flooded by errors from packages, making it extremely cumbersome to find reports from my own codebase.

The "hide excluded files" filter has no effect:
image

I tried adding a .vscode/settings.json file to set "python.analysis.diagnosticMode": "openFilesOnly" only for that directory, to no avail... that would have been nice and generic.
Alternatively, it would be nice to have a way to declare something "python.analysis.diagnosticMode.exclude": = ["directory", "list"] (or maybe a whitelist instead?)

@memeplex
Copy link

memeplex commented Jun 6, 2021

I'm getting spurious warnings from linting in my conda environments:

image

I get openFilesOnly set and pickle.py is not open. Moreover the environment is not inside my workspace nor repo. This is not an isolated occurrence, it happens very often.

@memeplex
Copy link

memeplex commented Jun 6, 2021

This might be useful: the reports appear after I run unit tests from inside vscode. I use pytest.

@noxasaxon
Copy link

It would be great if we could have a setting for the analyzer to be a bit more selective about the paths that it analyzes. If providing an ignorePaths field is too much, the VSCode Search feature at least can use the .gitignore to ignore files and inheriting that for pylance would be super helpful.

Its a testament to pylance's usefulness that the analyzer is too important for me to only run it against open files.

This is a huge issue right now for our local deployments, which can generate thousands of files in a temporary ./build directory and drastically slow down the editor for 10+ minutes even on the latest hardware

@jakebailey
Copy link
Member

You can already achieve this with an excludes in pyrightconfig.json: https://github.com/microsoft/pyright/blob/main/docs/configuration.md#main-pyright-config-options

See #1150 for the request to add this as a VS Code configuration.

@jakebailey
Copy link
Member

As far as I'm concerned, the above two things cover this issue; anything else I think is a bug (but all of the comments from this thread are months old and likely do not reproduce).

@pikeas
Copy link
Author

pikeas commented Aug 26, 2021

As far as I'm concerned, the above two things cover this issue; anything else I think is a bug (but all of the comments from this thread are months old and likely do not reproduce).

I'm the original submitter. This is still happening, including with "python.analysis.diagnosticMode": "openFilesOnly". To reproduce, open any Python file in .venv/lib/python3.x/site-packages.

Two other exclusions to consider:

  • A setting or default behavior to exclude unsaved files
  • Interactives from VS Code's built-in #%% Jupyter should never be checked.

@pikeas
Copy link
Author

pikeas commented Aug 26, 2021

You can already achieve this with an excludes in pyrightconfig.json: https://github.com/microsoft/pyright/blob/main/docs/configuration.md#main-pyright-config-options

I can't get this to work.

[tool.pyright]
exclude = [".venv"]

Tried .venv, **/.venv, .venv/, .venv/**.

@jakebailey
Copy link
Member

A setting or default behavior to exclude unsaved files

This wouldn't make sense given the main purpose of a language server like Pylance is to do live analysis of unsaved files; otherwise we're going back in time to running pylint at the CLI on save.

Interactives from VS Code's built-in #%% Jupyter should never be checked.

I don't think that's right; people do typecheck these sorts of files (even notebooks, #1541). You can stick a # type: ignore on the first line to disable the diagnostics; excludes is largely for excluding files in workspace diagnostic mode.

I can't get this to work.

Can you restate what it is you're looking for? Are you trying to ensure that the files aren't analyzed in the workspace diagnostic mode, or are you trying to get diagnostics to not show up for these files ever? The latter won't be true for opened files, but we should never offer diagnostics up for unopened files if you're in the default openFile diagnostic mode.

If you want to bulk ignore diagnostics for certain files, you can use ignores for that.

@jakebailey jakebailey reopened this Aug 26, 2021
@jakebailey jakebailey added waiting for user response Requires more information from user and removed needs investigation Could be an issue - needs investigation labels Aug 26, 2021
@pikeas
Copy link
Author

pikeas commented Aug 26, 2021

A setting or default behavior to exclude unsaved files

This wouldn't make sense given the main purpose of a language server like Pylance is to do live analysis of unsaved files; otherwise we're going back in time to running pylint at the CLI on save.

I phrased this imprecisely. I meant to say files that have never been saved. It's common to paste WIP code snippets into a new file. Being snippets, they usually don't pass linting or typechecking. Pylance should skip these files.

Interactives from VS Code's built-in #%% Jupyter should never be checked.

I don't think that's right; people do typecheck these sorts of files (even notebooks, #1541). You can stick a # type: ignore on the first line to disable the diagnostics; excludes is largely for excluding files in workspace diagnostic mode.

The Interactive itself is being linted.

Screen Shot 2021-08-26 at 10 07 40

Screen Shot 2021-08-26 at 10 07 34

Can you restate what it is you're looking for? Are you trying to ensure that the files aren't analyzed in the workspace diagnostic mode, or are you trying to get diagnostics to not show up for these files ever? The latter won't be true for opened files, but we should never offer diagnostics up for unopened files if you're in the default openFile diagnostic mode.

I would like for files in my virtualenv to never display diagnostics in the editor, while remaining available to Pylance to use for diagnostics in other files.

# .venv/lib/python3.9/site-packages/somelib/foo.py

def important_function(a, b):
    ...

# src/mycode.py
from somelib.foo import important_function

important_function(5)

My project file should have a diagnostic error because I'm missing an argument. If I then Go To Definition (cmd+click) to read the 3rd party source, that file shouldn't display any diagnostics.

@jakebailey
Copy link
Member

Thanks. The behavior you're seeing with the venv is intended; when you jump to a file, we reveal the diagnostics for it, then when it's closed, they disappear. Most users don't hit this because the default type checking mode in Pylance is "off".

If you don't want to ever show diagnostics for these files, then ignore is the config you'd use. I suggested excludes assuming we were mistakenly loading these files in workspace mode, but if you're navigating to the files, we show the diagnostics from them regardless of exclude. exclude is just about defining which files are a part of the project and should be (or not be) type checked.

You can use ignore to ignore diagnostics in those interactive files, if that's your preference, but I don't think we're planning on treating these files differently than other files in the project; if type checking is enabled, we will type check.

@pikeas
Copy link
Author

pikeas commented Aug 26, 2021

Thanks for the thorough response, I'll take ignore for a spin. Are diagnostics for interactives intended behavior per my screenshots?

@jakebailey
Copy link
Member

Yes, if you have type checking enabled. It looks like you've enabled the "strict" mode, which is going to strongly complain about missing stubs (if the library is not py.typed, which scipy is not) and unknown types. Using this mode on notebooks in the current state of the numerics library ecosystem is probably not a good idea at the moment; the libraries are only recently starting to work on getting strong types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for user response Requires more information from user
Projects
None yet
Development

No branches or pull requests

5 participants