-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
sitecustomize/full sys.path support #5701
Comments
We should probably support this. I am a little concerned that it will be hard to figure out when packages passed via command line are on the path, but I will have to think more about this. I also want to refactor sitepkgs.py to be a more general script used to get all the information we need from an external Python executable (version, location, etc). |
As long as we filter by the presence of An alternative could be to search for these on all of |
Thanks for the consideration. Just to make sure I'm explicit about it, it's not just PYTHONPATH that I'd like to see, but the full site.py logic that includes sitecustomize.py or maybe usercustomize.py. I would probably go with the "filter things out from sys.path" rather than the "recreate the logic in site.py" approach, so that future changes in site.py will likely work without replicating the logic in mypy, but there may be nuances I'm not considering. |
I don't think this is the correct thing to do here. The directories added to the |
Circling back: if I modify |
I'm not sure if this is safe or not, I'll have to think about that. I'm very busy this week so I won't be able to review anything until Saturday at the earliest, but feel free to open a PR now or then if you want to. |
Any progress here? This impact nix users which uses sitecustomize to create reproducible development environments. Mypy is actually barely usable in this context. We're plagged with these unexpected |
Ok, it seems there is significant need for this, bumping to priority high. |
I took a stab at testing the proposed approach (just return diff --git a/mypy/sitepkgs.py b/mypy/sitepkgs.py
index 2a13e4b2..56444006 100644
--- a/mypy/sitepkgs.py
+++ b/mypy/sitepkgs.py
@@ -7,8 +7,9 @@ library found in Python 2. This file is run each mypy run, so it should be kept
possible.
"""
+import sys
+
if __name__ == '__main__':
- import sys
sys.path = sys.path[1:] # we don't want to pick up mypy.types
from distutils.sysconfig import get_python_lib
@@ -20,6 +21,11 @@ if MYPY:
def getsitepackages():
+ # type: () -> List[str]
+ return _get_site_packages() + sys.path
+
+
+def _get_site_packages():
# type: () -> List[str]
if hasattr(site, 'getusersitepackages') and hasattr(site, 'getsitepackages'):
user_dir = site.getusersitepackages() But this led to early failures in basic tests (among others):
I also tried simply returning diff --git a/mypy/sitepkgs.py b/mypy/sitepkgs.py
index 2a13e4b2..744aef9d 100644
--- a/mypy/sitepkgs.py
+++ b/mypy/sitepkgs.py
@@ -7,13 +7,11 @@ library found in Python 2. This file is run each mypy run, so it should be kept
possible.
"""
+import sys
+
if __name__ == '__main__':
- import sys
sys.path = sys.path[1:] # we don't want to pick up mypy.types
-from distutils.sysconfig import get_python_lib
-import site
-
MYPY = False
if MYPY:
from typing import List
@@ -21,11 +19,7 @@ if MYPY:
def getsitepackages():
# type: () -> List[str]
- if hasattr(site, 'getusersitepackages') and hasattr(site, 'getsitepackages'):
- user_dir = site.getusersitepackages()
- return site.getsitepackages() + [user_dir]
- else:
- return [get_python_lib()]
+ return sys.path
if __name__ == '__main__': Is that because the test suite is tuned to the prior assumption and one other tweak would cause the tests to stop failing? Or does this change break some other fundamental assumption? |
The patch provided by @jaraco completely works for me (ofek/hatch-mypyc#2) as a workaround for #10829 when being built by |
The same is also true for GNU Guix users, another non-file hierarchy standard distribution. |
And in my case I can't seem to workaround it easily via the https://github.com/python/mypy/blob/master/mypy/main.py#L1034
|
Fixes python#5701. * mypy/pyinfo.py (getsitepackages): Use sys.path to discover packages. * mypy/modulefinder.py (get_site_packages_dirs): Adjust accordingly. (expand_site_packages, _parse_pth_file, _make_abspath): Remove procedures. (compute_search_paths): Adjust accordingly. * mypy/main.py (process_options): Likewise.
Closes #5701 This replaces the old hand crafted search code that was more fragile.
Looking at sitepkgs.py, the current implementation only looks for PEP 561 packages in
site.usersitepackages()
andsite.getsitepackages()
. My environment has a sitecustomize.py that adds additional paths tosys.path
based on some in-house env vars (not really my choice, I inherited this setup). Could we add a mypy flag to indicate that it should use the full sys.path? I don't really see a harm in including PYTHONPATH too.On a related note, shouldnt user site packages have precedence over system site packages?
The text was updated successfully, but these errors were encountered: