3
Rez @ s d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlm Z e r\d dl
mZmZ ej
eZejdZdd Zdd Zd
d Zdd
Zdd Zdd Zdd ZdS ) )absolute_importN)MYPY_CHECK_RUNNING)ListOptionalz8include-system-site-packages\s*=\s*(?Ptrue|false)c 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
/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el9.x86_64/opt/alt/python36/lib/python3.6/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.
real_prefix)hasattrr r
r
r
r !_running_under_regular_virtualenv s r c C s t p
t S )zGReturn True if we're running inside a virtualenv, False otherwise.
)r r r
r
r
r running_under_virtualenv( s r c C sP t jjtjd} y&tj| dd}|j j S Q R X W n t k
rJ dS X 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 ioopenread
splitlinesIOError)pyvenv_cfg_filefr
r
r _get_pyvenv_cfg_lines/ s r c C sR t } | dkrtjd dS x0| D ](}tj|}|dk r"|jddkr"dS q"W 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.TvaluefalseF)r loggerwarning#_INCLUDE_SYSTEM_SITE_PACKAGES_REGEXmatchgroup) cfg_linesliner" r
r
r _no_global_under_venv? s
r&