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.
This commit is contained in:
Tzu-ping Chung 2020-02-11 14:38:19 +08:00
parent 723b84517d
commit 6104060580
2 changed files with 6 additions and 3 deletions

2
news/7718.bugfix Normal file
View File

@ -0,0 +1,2 @@
Correctly detect global site-packages availability of virtual environments
created by PyPAs virtualenv>=20.0.

View File

@ -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