Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._internal.utils.virtualenv Namespace Reference

Functions

bool _running_under_venv ()
 
bool _running_under_legacy_virtualenv ()
 
bool running_under_virtualenv ()
 
Optional[List[str]] _get_pyvenv_cfg_lines ()
 
bool _no_global_under_venv ()
 
bool _no_global_under_legacy_virtualenv ()
 
bool virtualenv_no_global ()
 

Variables

 logger = logging.getLogger(__name__)
 
 _INCLUDE_SYSTEM_SITE_PACKAGES_REGEX
 

Function Documentation

◆ _get_pyvenv_cfg_lines()

Optional[List[str]] _get_pyvenv_cfg_lines ( )
protected
Reads {sys.prefix}/pyvenv.cfg and returns its contents as list of lines

Returns None, if it could not read/access the file.

Definition at line 36 of file virtualenv.py.

36def _get_pyvenv_cfg_lines() -> Optional[List[str]]:
37 """Reads {sys.prefix}/pyvenv.cfg and returns its contents as list of lines
38
39 Returns None, if it could not read/access the file.
40 """
41 pyvenv_cfg_file = os.path.join(sys.prefix, "pyvenv.cfg")
42 try:
43 # Although PEP 405 does not specify, the built-in venv module always
44 # writes with UTF-8. (pypa/pip#8717)
45 with open(pyvenv_cfg_file, encoding="utf-8") as f:
46 return f.read().splitlines() # avoids trailing newlines
47 except OSError:
48 return None
49
50
for i

References i.

Referenced by pip._internal.utils.virtualenv._no_global_under_venv().

Here is the caller graph for this function:

◆ _no_global_under_legacy_virtualenv()

bool _no_global_under_legacy_virtualenv ( )
protected
Check 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.

Definition at line 80 of file virtualenv.py.

80def _no_global_under_legacy_virtualenv() -> bool:
81 """Check if "no-global-site-packages.txt" exists beside site.py
82
83 This mirrors logic in pypa/virtualenv for determining whether system
84 site-packages are visible in the virtual environment.
85 """
87 no_global_site_packages_file = os.path.join(
88 site_mod_dir,
89 "no-global-site-packages.txt",
90 )
91 return os.path.exists(no_global_site_packages_file)
92
93

References i.

Referenced by pip._internal.utils.virtualenv.virtualenv_no_global().

Here is the caller graph for this function:

◆ _no_global_under_venv()

bool _no_global_under_venv ( )
protected
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.

Definition at line 51 of file virtualenv.py.

51def _no_global_under_venv() -> bool:
52 """Check `{sys.prefix}/pyvenv.cfg` for system site-packages inclusion
53
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
56 line:
57
58 include-system-site-packages = false
59
60 Additionally, log a warning if accessing the file fails.
61 """
62 cfg_lines = _get_pyvenv_cfg_lines()
63 if cfg_lines is None:
64 # We're not in a "sane" venv, so assume there is no system
65 # site-packages access (since that's PEP 405's default state).
67 "Could not access 'pyvenv.cfg' despite a virtual environment "
68 "being active. Assuming global site-packages is not accessible "
69 "in this environment."
70 )
71 return True
72
73 for line in cfg_lines:
75 if match is not None and match.group("value") == "false":
76 return True
77 return False
78
79

References pip._internal.utils.virtualenv._get_pyvenv_cfg_lines(), and i.

Referenced by pip._internal.utils.virtualenv.virtualenv_no_global().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _running_under_legacy_virtualenv()

bool _running_under_legacy_virtualenv ( )
protected
Checks if sys.real_prefix is set.

This handles virtual environments created with pypa's virtualenv.

Definition at line 22 of file virtualenv.py.

22def _running_under_legacy_virtualenv() -> bool:
23 """Checks if sys.real_prefix is set.
24
25 This handles virtual environments created with pypa's virtualenv.
26 """
27 # pypa/virtualenv case
28 return hasattr(sys, "real_prefix")
29
30

References i.

Referenced by pip._internal.utils.virtualenv.running_under_virtualenv(), and pip._internal.utils.virtualenv.virtualenv_no_global().

Here is the caller graph for this function:

◆ _running_under_venv()

bool _running_under_venv ( )
protected
Checks if sys.base_prefix and sys.prefix match.

This handles PEP 405 compliant virtual environments.

Definition at line 14 of file virtualenv.py.

14def _running_under_venv() -> bool:
15 """Checks if sys.base_prefix and sys.prefix match.
16
17 This handles PEP 405 compliant virtual environments.
18 """
19 return sys.prefix != getattr(sys, "base_prefix", sys.prefix)
20
21

References i.

Referenced by pip._internal.utils.virtualenv.running_under_virtualenv(), and pip._internal.utils.virtualenv.virtualenv_no_global().

Here is the caller graph for this function:

◆ running_under_virtualenv()

bool running_under_virtualenv ( )
True if we're running inside a virtual environment, False otherwise.

Definition at line 31 of file virtualenv.py.

31def running_under_virtualenv() -> bool:
32 """True if we're running inside a virtual environment, False otherwise."""
33 return _running_under_venv() or _running_under_legacy_virtualenv()
34
35

References pip._internal.utils.virtualenv._running_under_legacy_virtualenv(), and pip._internal.utils.virtualenv._running_under_venv().

Here is the call graph for this function:

◆ virtualenv_no_global()

bool virtualenv_no_global ( )
Returns a boolean, whether running in venv with no system site-packages.

Definition at line 94 of file virtualenv.py.

94def virtualenv_no_global() -> bool:
95 """Returns a boolean, whether running in venv with no system site-packages."""
96 # PEP 405 compliance needs to be checked first since virtualenv >=20 would
97 # return True for both checks, but is only able to use the PEP 405 config.
98 if _running_under_venv():
99 return _no_global_under_venv()
100
101 if _running_under_legacy_virtualenv():
102 return _no_global_under_legacy_virtualenv()
103
104 return False

References pip._internal.utils.virtualenv._no_global_under_legacy_virtualenv(), pip._internal.utils.virtualenv._no_global_under_venv(), pip._internal.utils.virtualenv._running_under_legacy_virtualenv(), and pip._internal.utils.virtualenv._running_under_venv().

Here is the call graph for this function:

Variable Documentation

◆ _INCLUDE_SYSTEM_SITE_PACKAGES_REGEX

_INCLUDE_SYSTEM_SITE_PACKAGES_REGEX
protected
Initial value:
2 r"include-system-site-packages\s*=\s*(?P<value>true|false)"
3)

Definition at line 9 of file virtualenv.py.

◆ logger

logger = logging.getLogger(__name__)

Definition at line 8 of file virtualenv.py.