KEMBAR78
Don't look in user site packages when using a virtual env by dmerejkowsky · Pull Request #11444 · python/mypy · GitHub
Skip to content

Conversation

dmerejkowsky
Copy link
Contributor

Description

Fixes #11274

As suggested in the above issue, we need to add user site packages to the list of directories only if site.ENABLE_USER_SITE is True.

Test Plan

Before the patch:

$ ./venv/bin/python mypy/pyinfo.py getsitepackages
['/mnt/data/dmerej/src/mypy/venv/lib/python3.9/site-packages', '/home/dmerej/.local/lib/python3.9/site-packages']

After the patch:

$ ./venv/bin/python mypy/pyinfo.py getsitepackages
['/mnt/data/dmerej/src/mypy/venv/lib/python3.9/site-packages']

where venv is the virtualenv for mypy development, as indicated in CONTRIBUTING.txt

Finally, we can check that pinfo still works outside a virtualenv:

$ python mypy/pyinfo.py getsitepackages
['/mnt/data/dmerej/src/mypy/venv/lib/python3.9/site-packages', '/home/dmerej/.local/lib/python3.9/site-packages']

mypy/pyinfo.py Outdated
if (
hasattr(site, 'getusersitepackages')
and hasattr(site, 'getsitepackages')
and site.ENABLE_USER_SITE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should still look in the directories returned by site.getsitepackages even if site.ENABLE_USER_SITE is false unless I'm mistaken.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes. Good catch.

@dmerejkowsky
Copy link
Contributor Author

yay CI is green \o/

@emmatyping emmatyping merged commit 7640664 into python:master Nov 5, 2021
emmatyping added a commit that referenced this pull request Nov 5, 2021
This is a follow up from #11444
JukkaL pushed a commit that referenced this pull request Nov 5, 2021
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this pull request Jan 20, 2022
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.

mypy looks for modules outside of virtualenv

3 participants