Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Don't look in user site packages when using a virtual env - #11444

Merged
emmatyping merged 3 commits into
python:masterfrom
dmerejkowsky:no-user-site-in-virtualenvs
Nov 5, 2021
Merged

Don't look in user site packages when using a virtual env#11444
emmatyping merged 3 commits into
python:masterfrom
dmerejkowsky:no-user-site-in-virtualenvs

Conversation

@dmerejkowsky

Copy link
Copy Markdown
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']

Comment thread mypy/pyinfo.py Outdated
if (
hasattr(site, 'getusersitepackages')
and hasattr(site, 'getsitepackages')
and site.ENABLE_USER_SITE

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread mypy/pyinfo.py Outdated
@dmerejkowsky

Copy link
Copy Markdown
Contributor Author

yay CI is green \o/

@emmatyping
emmatyping merged commit 7640664 into python:master Nov 5, 2021
Comment thread mypy/pyinfo.py
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