o Ec @sddlZddlZddlZddlZddlZddlmZmZee Z e dZ de fddZde fddZde fd d Zdeeefd d Zde fd dZde fddZde fddZdS)N)ListOptionalz8include-system-site-packages\s*=\s*(?Ptrue|false)returncCstjttdtjkS)znChecks if sys.base_prefix and sys.prefix match. This handles PEP 405 compliant virtual environments. base_prefix)sysprefixgetattrr r Q/opt/alt/python310/lib/python3.10/site-packages/pip/_internal/utils/virtualenv.py_running_under_venvsr cCs ttdS)zmChecks if sys.real_prefix is set. This handles virtual environments created with pypa's virtualenv. Z real_prefix)hasattrrr r r r !_running_under_regular_virtualenvs r cCs tptS)zBReturn True if we're running inside a virtualenv, False otherwise.)r r r r r r running_under_virtualenvs rcCsftjtjd}z t|dd}|WdWS1s!wYWdSty2YdSw)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) ospathjoinrropenread splitlinesOSError)Zpyvenv_cfg_filefr r r _get_pyvenv_cfg_lines$s ( rcCsPt}|durtddS|D]}t|}|dur%|ddkr%dSqdS)aZCheck `{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)rloggerZwarning#_INCLUDE_SYSTEM_SITE_PACKAGES_REGEXmatchgroup)Z cfg_lineslinerr r r _no_global_under_venv3s  rcCs0tjtjtj}tj|d}tj|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)rrdirnameabspathsite__file__rexists)Z site_mod_dirZno_global_site_packages_filer r r #_no_global_under_regular_virtualenvPs  r%cCstrtStr tSdS)zHReturns a boolean, whether running in venv with no system site-packages.F)r rr r%r r r r virtualenv_no_global^s r&)Zloggingrrer"rtypingrrZ getLogger__name__rcompilerboolr r rstrrrr%r&r r r r s"