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

Namespace package not detected if installed in site-packages #2635

Open
DingXuefeng opened this issue Nov 16, 2024 · 3 comments
Open

Namespace package not detected if installed in site-packages #2635

DingXuefeng opened this issue Nov 16, 2024 · 3 comments
Labels
Bug 🪳 High effort 🏋 Difficult solution or problem to solve

Comments

@DingXuefeng
Copy link

DingXuefeng commented Nov 16, 2024

pylint does not respect namespace pacakge. after debugging I found it's because is_namespace function defined in astroid.interpreter._import.util.py returns False if the submodule search location is in STD_AND_EXT_LIB_DIRS.

        if found_spec and found_spec.submodule_search_locations:
            # But immediately return False if we can detect we are in stdlib
            # or external lib (e.g site-packages)
            if any(
                any(location.startswith(lib_dir) for lib_dir in STD_AND_EXT_LIB_DIRS)
                for location in found_spec.submodule_search_locations
            ):
                return False

this is not a valid assumption. PEP 420 does not say this.

We are working on a big project as many teams. Our project lives in a namespace, say myproj. Different groups work on subproject, such as myproj.simulation and myproj.plot and myproj.calculation. These 3 packages are 3 different git repo and can be pip installed separately but they all goes to site-packages/myproj folder as site-packages/myproj/simulation, site-pacakges/myproj/plot etc. the myproj itself is a namespace package.

We have this need and I believe this is compatible with PEP420, but not with astroid.

I suggest remove line 96-102 of astroid/interpreter/_import/util.py.

@Pierre-Sassoulas
Copy link
Member

Thank you for looking into it, do you mind opening a pull request for it ?

@jacobtylerwalls
Copy link
Member

We can't just do a straight revert of #1756 without having another solution in hand for not recausing pylint-dev/pylint#7365.

@jacobtylerwalls jacobtylerwalls changed the title PEP 420 namespace package not respected by is_namespace Namespace package not detected if installed in site-packages Nov 17, 2024
@jacobtylerwalls jacobtylerwalls added the High effort 🏋 Difficult solution or problem to solve label Nov 17, 2024
@DingXuefeng
Copy link
Author

We can't just do a straight revert of #1756 without having another solution in hand for not recausing pylint-dev/pylint#7365.

Thanks, and I get it. It seems it's not easy to fix it. Let me see if I can fix both with a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪳 High effort 🏋 Difficult solution or problem to solve
Projects
None yet
Development

No branches or pull requests

3 participants