basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

Ignores **/venv/** successfully but not **/Lib/**

Open bro69noscope opened this issue 2 years ago • 12 comments

Cannot figure out how to tell basedpyright to ignore Lib modules

pyproject.toml:

[tool.basedpyright]
ignore = [
  "**/venv/**",            # works
  "**/Lib/**",             # doesn't
]

Tried brute forcing many possible variations with no sucess. I know the .toml is picked up on (works for other options)

bro69noscope avatar Oct 01 '24 23:10 bro69noscope

it should be ignoring those automatically. where is your venv located relative to your project?

DetachHead avatar Oct 01 '24 23:10 DetachHead

it should be ignoring those automatically. where is your venv located relative to your project?

Well venv is on project root, and is ignored but not automatically. Lib is on Appdata\Local etc... but even ignore = ["**\\Users\\Username\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\**"] will not work

(forgot to specify I was on windows)

bro69noscope avatar Oct 01 '24 23:10 bro69noscope

what if you use exclude instead of ignore?

DetachHead avatar Oct 01 '24 23:10 DetachHead

what if you use exclude instead of ignore?

No luck either, altough I never really know what semantics I've tried, but I've been inserting variations of those paths for the past 2 hours 😅.

EDIT: interstingly, exclude fails with the working ignore **/venv/** path

bro69noscope avatar Oct 01 '24 23:10 bro69noscope

hmm, some more questions:

  • what commands are you using to create your venv?
  • are you using the basedpyright CLI (if so, what command are you running exactly and is it in the same working directory as your pyproject.toml)?
  • are you using the language server? if so which editor are you using?
  • what version of basedpyright are you using?

DetachHead avatar Oct 01 '24 23:10 DetachHead

what commands are you using to create your venv?

create ? venv venv and then venv\scripts\activate

are you using the basedpyright CLI (if so, what command are you running exactly and is it in the same working directory as your pyproject.toml)? are you using the language server? if so which editor are you using? ...

Lang serv. Nvim. All defaults. installed version 1.18.2 (Using Mason)

bro69noscope avatar Oct 01 '24 23:10 bro69noscope

ah, usually i call my venv .venv which (based)pyright automatically excludes. thanks for the info, will investigate this

DetachHead avatar Oct 01 '24 23:10 DetachHead

My venv ignore is not an issue at all tho ^^ its the Lib modules I can't figure out how to ignore

bro69noscope avatar Oct 01 '24 23:10 bro69noscope

oh right. in that case i have no clue what it could be lol. are you able to try the CLI and if possible, another editor just to see if the issue is specific to neovim?

DetachHead avatar Oct 01 '24 23:10 DetachHead

Yeah I'll have a try with CLI and see but I need to do something else for a while and comeback cause I'm burned out rn

bro69noscope avatar Oct 01 '24 23:10 bro69noscope

I can say that running basedpyright "C:\Users\ville\AppData\Local\Programs\Python\Python312\Lib\dataclasses.py"

with

ignore = [
  "**/venv/**",
  "../../../AppData/Local/Programs/Python/Python312/Lib/**",
] 

in the pyproject.toml in "C:\users\ville\Project" does provide diagnostics, wich i think it shouldn't ?

I'm pretty confused by the path difference and don't really undsertand how it works tbh, did not seem to be able to pass an --ingore or --ignorepattern argument in the cli command itself, maybe doing it wrong idk, I'd need steps by steps to really know what I'm doing

bro69noscope avatar Oct 02 '24 16:10 bro69noscope

oh yeah i see now. not sure why that's not working, but either way it should ignore any errors from the standard library by default

DetachHead avatar Oct 03 '24 05:10 DetachHead

this was partially addressed upstream. in the next release you can specify an absolute path. but i'll leave this issue open as it's not a full solution to the problem. it should ignore standard library modules by default and you shouldn't need an absolute path in your config file (which would obviously be different for other users)

DetachHead avatar Oct 23 '24 09:10 DetachHead

I report with great shame that a simple change to ignore = ["../**/Lib/**", "**/venv/**"] managed to fix the issue. I thought that I would need a set of ../ per levels up the directory until the root disk, hence why the past attempts did not work...

On the rare chance of some other noob having the same issue as me:

in the case of your pyproject being in C:/Users/Username/Project

ignore = [
  "**/venv/**",
  "../../../AppData/Local/Programs/Python/Python312/Lib/**", # BAD
] 
ignore = [
  "**/venv/**",
  "../AppData/Local/Programs/Python/Python312/Lib/**", # GOOD
] 

bro69noscope avatar Nov 29 '24 07:11 bro69noscope

thanks for the update. i'm gonna leave this issue open though because you shouldn't have to manually configure this in the first place. it should ignore the standard library by default

DetachHead avatar Nov 29 '24 07:11 DetachHead

Can't figure out how to ignore Lib directories again after my previous solution stopped working.. aergh.

EDIT: found a way, coul not use the .toml for this one but not gonna mind. Ignoring Lib works with in my case the neovim code:

local lspconfig = require("lspconfig")
lspconfig.basedpyright.setup({
        settings = {
          basedpyright = {
            analysis = {
              ignore = { "c:/Users/ville/appdata/local/programs/python/python312/lib/**" },
            },
          },
        },
      })

bro69noscope avatar May 31 '25 11:05 bro69noscope

So I would like to come back to this to close and maybe help another beginner ...

After having some struggles again but this time setting up ruff... I realized my problem is likely just about a NeoVim "issue" (it's probably working as intended really) and I dont think basedpyright has much to do with it.

Buffer in Neovim don't operate the same way most code editors "tabs" do, when going to definition on an imported symbol, the nvim goes to the absolute path of that module and open the file in a buffer with the current neovim configuration, if lsp server are setup, they might run into that new "workspace" unless explicitely told not to do so... which I have no idea how to do, because nvim can be complicated.

In short, rules from a project's root pyproject.toml are likely to apply only to that directory for NeoVim LSPs (assuming you use a popular setup with lspconfig.nvim ) therefore, you can only exclude files which are childs of that pyproject root folder.

I have no idea how I still originally managed to ignore my Lib directory from the toml, but we can just cast that as unreliable and not the way to go.

TLDR for the whole Issue:

Any exclusion outside the project root (typically StdLib, but not .venv) from the typical NeoVim setup has to be done on the lspconfig side of things and and not pyproject.toml :

local lspconfig = require("lspconfig")

      lspconfig.ruff.setup({
        init_options = {
          settings = {
            exclude = {
              "/usr/lib/python*/**",
            },
          },
        },
      })

      lspconfig.basedpyright.setup({
        settings = {
          basedpyright = {
            analysis = {
              ignore = {
                "/usr/lib/python*/**",
              },
            },
          },
        },
      })

bro69noscope avatar Jun 17 '25 21:06 bro69noscope

thanks for the update, i still think it's an issue that errors from the standard library are not ignored by default (which happens in vscode as well) but since this seems like a neovim-specific issue, i'll open a separate issue for that

DetachHead avatar Jun 18 '25 00:06 DetachHead