6from typing
import List, Optional
10 r"include-system-site-packages\s*=\s*(?P<value>true|false)"
15 """Checks if sys.base_prefix and sys.prefix match.
17 This handles PEP 405 compliant virtual environments.
23 """Checks if sys.real_prefix is set.
25 This handles virtual environments created with pypa's virtualenv.
28 return hasattr(sys,
"real_prefix")
32 """True if we're running inside a virtual environment, False otherwise."""
37 """Reads {sys.prefix}/pyvenv.cfg and returns its contents as list of lines
39 Returns None, if it could not read/access the file.
45 with open(pyvenv_cfg_file, encoding=
"utf-8")
as f:
52 """Check `{sys.prefix}/pyvenv.cfg` for system site-packages inclusion
54 PEP 405 specifies that when system site-packages are not supposed to be
55 visible from a virtual environment, `pyvenv.cfg` must contain the following
58 include-system-site-packages = false
60 Additionally, log a warning if accessing the file fails.
67 "Could not access 'pyvenv.cfg' despite a virtual environment "
68 "being active. Assuming global site-packages is not accessible "
69 "in this environment."
73 for line
in cfg_lines:
75 if match
is not None and match.group(
"value") ==
"false":
81 """Check if "no-global-site-packages.txt" exists beside site.py
83 This mirrors logic in pypa/virtualenv for determining whether system
84 site-packages are visible in the virtual environment.
89 "no-global-site-packages.txt",
95 """Returns a boolean, whether running in venv with no system site-packages."""
bool virtualenv_no_global()
bool _running_under_legacy_virtualenv()
bool _no_global_under_legacy_virtualenv()
Optional[List[str]] _get_pyvenv_cfg_lines()
bool _running_under_venv()
bool _no_global_under_venv()
bool running_under_virtualenv()