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

pyinfo: Use sys.path instead of the site.getsitepackages procedure. #12530

Closed
wants to merge 1 commit into from

Conversation

Apteryks
Copy link

@Apteryks Apteryks commented Apr 6, 2022

Fixes #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.

I've applied this patch to the python-mypy in GNU Guix; which continued passing its test suite. This in turned enabled the python-pytest-enabler test suite to pass for the first time; previously it would fail due to mypy being unable to locate the stubs files, even they were installed.

I believe this is because mypy would only look (by default) at the Python installation site-packages directory, which in non-file hierarchy standard distributions is bound to fail.

Using sys.path instead of site.getsitepackages is more robust generally (it benefits from Python's site.py treatment) and avoids reinventing the wheel in mypy (such as parsing .pth files).

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.
@Apteryks Apteryks changed the title painfo: Use sys.path instead of the site.getsitepackages procedure. pyinfo: Use sys.path instead of the site.getsitepackages procedure. Apr 7, 2022
@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

aiohttp (https://github.com/aio-libs/aiohttp)
+ /tmp/mypy_primer/projects/aiohttp is in the PYTHONPATH. Please change directory so it is not.

@hauntsaninja
Copy link
Collaborator

Thanks, closing as a duplicate of #11143 which handles more cases, passes tests, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sitecustomize/full sys.path support
2 participants