a
lj
@ s d dl Z d dlZd dlZd dlZd dlZd dlmZmZ e e Z
edZe
dddZe
dddZe
dd d
Zeee dddZe
dd
dZe
dddZe
dddZdS ) N)ListOptionalz8include-system-site-packages\s*=\s*(?Ptrue|false))returnc C s t jtt dt jkS )znChecks if sys.base_prefix and sys.prefix match.
This handles PEP 405 compliant virtual environments.
base_prefix)sysprefixgetattr r r B/usr/lib/python3.9/site-packages/pip/_internal/utils/virtualenv.py_running_under_venv s r c C s
t tdS )zmChecks if sys.real_prefix is set.
This handles virtual environments created with pypa's virtualenv.
Zreal_prefix)hasattrr r r r r
!_running_under_regular_virtualenv s r
c C s t p
t S )zBReturn True if we're running inside a virtualenv, False otherwise.)r r
r r r r
running_under_virtualenv s r c C sh t jtjd} z>t| dd}| W d W S 1 sB0 Y W n tyb Y dS 0 dS )zReads {sys.prefix}/pyvenv.cfg and returns its contents as list of lines
Returns None, if it could not read/access the file.
z
pyvenv.cfgzutf-8)encodingN) ospathjoinr r openread
splitlinesOSError)Zpyvenv_cfg_filefr r r
_get_pyvenv_cfg_lines$ s 0r c C sP t } | du rtd dS | D ]*}t|}|dur |ddkr dS q dS )aZ Check `{sys.prefix}/pyvenv.cfg` for system site-packages inclusion
PEP 405 specifies that when system site-packages are not supposed to be
visible from a virtual environment, `pyvenv.cfg` must contain the following
line:
include-system-site-packages = false
Additionally, log a warning if accessing the file fails.
NzCould not access 'pyvenv.cfg' despite a virtual environment being active. Assuming global site-packages is not accessible in this environment.TvalueZfalseF)r loggerZwarning#_INCLUDE_SYSTEM_SITE_PACKAGES_REGEXmatchgroup)Z cfg_linesliner r r r
_no_global_under_venv3 s
r c C s0 t jt jtj} t j| d}t j|S )zCheck if "no-global-site-packages.txt" exists beside site.py
This mirrors logic in pypa/virtualenv for determining whether system
site-packages are visible in the virtual environment.
zno-global-site-packages.txt)r r dirnameabspathsite__file__r exists)Zsite_mod_dirZno_global_site_packages_filer r r
#_no_global_under_regular_virtualenvP s r% c C s t rt S t rt S dS )zHReturns a boolean, whether running in venv with no system site-packages.F)r r r
r% r r r r
virtualenv_no_global^ s
r&