From 61040605803c8b181364549298747f7d719313f2 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Tue, 11 Feb 2020 14:38:19 +0800 Subject: [PATCH] Swap venv and virtualenv checks Environments created by pypa/virtualenv >=20 can pass both real_prefix and base_prefix checks, but are only able to use the pyvenv.cfg values, not the legacy `no-global-site-packages.txt`. So we need to check for venv (PEP 405) first. --- news/7718.bugfix | 2 ++ src/pip/_internal/utils/virtualenv.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 news/7718.bugfix diff --git a/news/7718.bugfix b/news/7718.bugfix new file mode 100644 index 00000000000..5abcce69a83 --- /dev/null +++ b/news/7718.bugfix @@ -0,0 +1,2 @@ +Correctly detect global site-packages availability of virtual environments +created by PyPA’s virtualenv>=20.0. diff --git a/src/pip/_internal/utils/virtualenv.py b/src/pip/_internal/utils/virtualenv.py index d81e6ac54bb..596a69a7dad 100644 --- a/src/pip/_internal/utils/virtualenv.py +++ b/src/pip/_internal/utils/virtualenv.py @@ -105,11 +105,12 @@ def virtualenv_no_global(): # type: () -> bool """Returns a boolean, whether running in venv with no system site-packages. """ + # PEP 405 compliance needs to be checked first since virtualenv >=20 would + # return True for both checks, but is only able to use the PEP 405 config. + if _running_under_venv(): + return _no_global_under_venv() if _running_under_regular_virtualenv(): return _no_global_under_regular_virtualenv() - if _running_under_venv(): - return _no_global_under_venv() - return False