-
-
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
First-party import incorrectly resolved to site-packages
rather than source
#7365
Comments
This has something to do with how we infer the name of the package to lint. I'm not quite sure why we are regressing on this in I'm not sure if this is a namespace package issue but rather something with the specific way this CI installs the |
I noticed you're invoking flake8 as Regarding what made the prior behavior work with
|
site-packages
unexpectedly linted rather than cloned source
@jacobtylerwalls That sounds exactly like I would expect. Well done noticing that! |
That's on purpose. I've been doing it that way for long time, tools like flake8 wants to run under the actual sources, they do not search for packages, and they do not do introspection of extension modules. pylint does perform introspection but I'm not building in-place, so yes, pylint has to search for the installed package.
yes, indeed.
Expected, the package is not installed, and I use a
Yes, but you should get tons of warnings due to the missing C extension module
Sorry! Yes, mpi4py's extension modules have C header and library dependencies. In short, you can install the following way:
See GitHub Actions's workflow file right here, you can see that's the way I install the package for linting. |
Thanks for your patience with me. The additional instructions were extremely helpful--I can reproduce locally now. The behavior changed in pylint-dev/astroid@5067f08 as I think other maintainers suspected. I'm having a look now. |
Something like this should do, I'll work up a PR: diff --git a/astroid/interpreter/_import/util.py b/astroid/interpreter/_import/util.py
index f082e9c4..3fa5b1b3 100644
--- a/astroid/interpreter/_import/util.py
+++ b/astroid/interpreter/_import/util.py
@@ -13,6 +13,8 @@ from importlib.util import _find_spec_from_path # type: ignore[attr-defined]
@lru_cache(maxsize=4096)
def is_namespace(modname: str) -> bool:
+ from astroid.modutils import EXT_LIB_DIRS
+
if modname in sys.builtin_module_names:
return False
@@ -70,6 +72,8 @@ def is_namespace(modname: str) -> bool:
# Update last_submodule_search_locations
if found_spec and found_spec.submodule_search_locations:
+ if any(location in EXT_LIB_DIRS for location in found_spec.submodule_search_locations):
+ return False
last_submodule_search_locations = found_spec.submodule_search_locations
return ( |
site-packages
unexpectedly linted rather than cloned sourcesite-packages
rather than source
@dalcinl, I've put up a PR at pylint-dev/astroid#1756, so I would be very grateful if you had an opportunity to test the fix. Thanks again for the report! |
@jacobtylerwalls Where you able to reproduce the issue using either a virtual environment or a user-site install? Could you share the exacts steps you used? As I said before, I was not able to reproduce the issue locally. Testing your PR without being able to reproduce the failure on my side first is not so useful. |
This reproduces for me without a virtual env on MacOS: git clone https://github.com/mpi4py/mpi4py
cd mpi4py
MPICFG=nompi-fast CFLAGS=-00 pip install .
pip install pylint==2.15.0
pip install astroid==2.12.4
pylint mpi4py |
I cannot reproduce!! I'm using Homebrew Python 3.10.6 on macOS. Do you have any clue about what could be going on? |
No, sorry. I might try a python.org python. |
Bug description
Please see the following logs. Note the strange
site-packages.
prefix in the package/module namespace. I cannot reproduce this issue locally using virtual environments (running viatox
) or installing into user site-packages.Configuration
I'm using the following .pylintrc file.
Command used
After installing the
mpi4py
package withpip install .
on a git checkout.Pylint output
... and so on.
Expected behavior
No output other than the final evaluation.
Pylint version
OS / Environment
Ubuntu 22.04 or 20.04 (GitHub Actions runner images)
Additional dependencies
N/A, see logs.
As I mentioned before, I cannot reproduce locally.
Any tips about how to debug this issue within the GitHub Actions runner environment?
The text was updated successfully, but these errors were encountered: