-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add way to disable module caching for specific files #2095
Comments
It's kind of hard to reproduce this without an actual reproduction case. As far as I can tell, we don't cache any script/filename/package so I'm not sure what you mean by that. Feel free to reopen if you have a particular example that I can use to reproduce this. |
I created a test repo: https://github.com/bpedersen2/pylint_reproduce export PYTHONPATH='.'
pylint bin/project project/test_package/test_mod2.py
Versus pylint project/test_package/test_mod2.py bin/project
|
The seen modules are cached e.g. for the circular dep. check. The problem is that bin/project is seen internally as a module 'project', while it is not a module resolvable via a valid pythonpath. If I add an _init.py to bin (making it a package), everything works correctly, as the module then becomes 'bin.project', which does not collide with the toplevel project. |
I think the correct logic would be: |
this is due to
so lint find the outter one instead of the inner one |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
We are having a similar issue, and @bpedersen2 's reproduction seems valid. Could you consider reopening this issue? |
Generally, the issue seems to be that some repos have python files that are never intended to be imported (e.g., tests, scripts) and these can cause naming collisions with importable packages. |
Thanks! I'm wondering if it makes sense to cache only when an actual import is encountered in code? This would mirror importlib behavior. But I don't know enough about Pylint internals to know if what I just said makes any sense... |
Does astroid have knobs pylint could use to say when pylint wants the ast to be cached? |
I don't think there is a mecanism to restrict the caching to some portion of the code, right now it's all or nothing. |
Right, I think we're wondering if it makes sense to add such a thing due to the real-world problems described above. |
This might be fixed with a better discovery of file to analyses. Making |
Excluding some files would mean they wouldn't get checked? That's not what we'd want. But I agree that caching against the abspath (or even just the relpath from the CWD), and not the module name, would solve the problem. Is this cache conserved across runs? Or is it just used within the scope of a single run? If it is then may I suggest caching against the relpath from the CWD, so that the cache is portable? |
I don't think the cache is conserved across runs. We do have a cache for the previous score (in order to do |
In that case caching against the abspath seems fine. |
I'm having this issue on a work project too. It's quite annoying because the project is structured around microservices and AWS lambdas + layers, so there are quite a few imports that rely on specific things being in the pythonpath which aren't necessarily reflected in the directory structure. In the end Python itself doesn't rely on directory structure alone, so linters probably shouldn't do that either. Is there any way I can help short of contributing myself (which I can't do right now since I don't know the codebase at all and don't have time to learn it currently)? |
a script bin/packagename
a package packagename with some modules
2a. run
pylint bin/packagename packagename/somemodule
2b. run
pylint packagename/somemodule bin/packagename
or pylint individuallyCurrent behavior
2a results in complaints about non-name-in-package
2b runs without warnings
Expected behavior
Both runs can run without warning. The problem seems that in 2a the script is cached/kept loaded as a package.
Possibly related to #689
The text was updated successfully, but these errors were encountered: