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

Functions

bool _should_use_osx_framework_prefix ()
 
str _infer_prefix ()
 
str _infer_user ()
 
str _infer_home ()
 
Scheme get_scheme (str dist_name, bool user=False, typing.Optional[str] home=None, typing.Optional[str] root=None, bool isolated=False, typing.Optional[str] prefix=None)
 
str get_bin_prefix ()
 
str get_purelib ()
 
str get_platlib ()
 

Variables

 logger = logging.getLogger(__name__)
 
 _AVAILABLE_SCHEMES = set(sysconfig.get_scheme_names())
 
 _PREFERRED_SCHEME_API = getattr(sysconfig, "get_preferred_scheme", None)
 
list _HOME_KEYS
 

Function Documentation

◆ _infer_home()

str _infer_home ( )
protected
Try to find a home for the current platform.

Definition at line 101 of file _sysconfig.py.

101def _infer_home() -> str:
102 """Try to find a home for the current platform."""
103 if _PREFERRED_SCHEME_API:
104 return _PREFERRED_SCHEME_API("home")
105 suffixed = f"{os.name}_home"
106 if suffixed in _AVAILABLE_SCHEMES:
107 return suffixed
108 return "posix_home"
109
110
111# Update these keys if the user sets a custom home.

References pip._internal.locations._sysconfig._PREFERRED_SCHEME_API.

Referenced by pip._internal.locations._sysconfig.get_scheme().

Here is the caller graph for this function:

◆ _infer_prefix()

str _infer_prefix ( )
protected
Try to find a prefix scheme for the current platform.

This tries:

* A special ``osx_framework_library`` for Python distributed by Apple's
  Command Line Tools, when not running in a virtual environment.
* Implementation + OS, used by PyPy on Windows (``pypy_nt``).
* Implementation without OS, used by PyPy on POSIX (``pypy``).
* OS + "prefix", used by CPython on POSIX (``posix_prefix``).
* Just the OS name, used by CPython on Windows (``nt``).

If none of the above works, fall back to ``posix_prefix``.

Definition at line 55 of file _sysconfig.py.

55def _infer_prefix() -> str:
56 """Try to find a prefix scheme for the current platform.
57
58 This tries:
59
60 * A special ``osx_framework_library`` for Python distributed by Apple's
61 Command Line Tools, when not running in a virtual environment.
62 * Implementation + OS, used by PyPy on Windows (``pypy_nt``).
63 * Implementation without OS, used by PyPy on POSIX (``pypy``).
64 * OS + "prefix", used by CPython on POSIX (``posix_prefix``).
65 * Just the OS name, used by CPython on Windows (``nt``).
66
67 If none of the above works, fall back to ``posix_prefix``.
68 """
69 if _PREFERRED_SCHEME_API:
70 return _PREFERRED_SCHEME_API("prefix")
71 if _should_use_osx_framework_prefix():
72 return "osx_framework_library"
73 implementation_suffixed = f"{sys.implementation.name}_{os.name}"
74 if implementation_suffixed in _AVAILABLE_SCHEMES:
75 return implementation_suffixed
76 if sys.implementation.name in _AVAILABLE_SCHEMES:
78 suffixed = f"{os.name}_prefix"
79 if suffixed in _AVAILABLE_SCHEMES:
80 return suffixed
81 if os.name in _AVAILABLE_SCHEMES: # On Windows, prefx is just called "nt".
82 return os.name
83 return "posix_prefix"
84
85
for i

References pip._internal.locations._sysconfig._PREFERRED_SCHEME_API, pip._internal.locations._sysconfig._should_use_osx_framework_prefix(), and i.

Referenced by pip._internal.locations._sysconfig.get_scheme().

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

◆ _infer_user()

str _infer_user ( )
protected
Try to find a user scheme for the current platform.

Definition at line 86 of file _sysconfig.py.

86def _infer_user() -> str:
87 """Try to find a user scheme for the current platform."""
88 if _PREFERRED_SCHEME_API:
89 return _PREFERRED_SCHEME_API("user")
90 if is_osx_framework() and not running_under_virtualenv():
91 suffixed = "osx_framework_user"
92 else:
93 suffixed = f"{os.name}_user"
94 if suffixed in _AVAILABLE_SCHEMES:
95 return suffixed
96 if "posix_user" not in _AVAILABLE_SCHEMES: # User scheme unavailable.
97 raise UserInstallationInvalid()
98 return "posix_user"
99
100

References pip._internal.locations._sysconfig._PREFERRED_SCHEME_API.

Referenced by pip._internal.locations._sysconfig.get_scheme().

Here is the caller graph for this function:

◆ _should_use_osx_framework_prefix()

bool _should_use_osx_framework_prefix ( )
protected
Check for Apple's ``osx_framework_library`` scheme.

Python distributed by Apple's Command Line Tools has this special scheme
that's used when:

* This is a framework build.
* We are installing into the system prefix.

This does not account for ``pip install --prefix`` (also means we're not
installing to the system prefix), which should use ``posix_prefix``, but
logic here means ``_infer_prefix()`` outputs ``osx_framework_library``. But
since ``prefix`` is not available for ``sysconfig.get_default_scheme()``,
which is the stdlib replacement for ``_infer_prefix()``, presumably Apple
wouldn't be able to magically switch between ``osx_framework_library`` and
``posix_prefix``. ``_infer_prefix()`` returning ``osx_framework_library``
means its behavior is consistent whether we use the stdlib implementation
or our own, and we deal with this special case in ``get_scheme()`` instead.

Definition at line 29 of file _sysconfig.py.

29def _should_use_osx_framework_prefix() -> bool:
30 """Check for Apple's ``osx_framework_library`` scheme.
31
32 Python distributed by Apple's Command Line Tools has this special scheme
33 that's used when:
34
35 * This is a framework build.
36 * We are installing into the system prefix.
37
38 This does not account for ``pip install --prefix`` (also means we're not
39 installing to the system prefix), which should use ``posix_prefix``, but
40 logic here means ``_infer_prefix()`` outputs ``osx_framework_library``. But
41 since ``prefix`` is not available for ``sysconfig.get_default_scheme()``,
42 which is the stdlib replacement for ``_infer_prefix()``, presumably Apple
43 wouldn't be able to magically switch between ``osx_framework_library`` and
44 ``posix_prefix``. ``_infer_prefix()`` returning ``osx_framework_library``
45 means its behavior is consistent whether we use the stdlib implementation
46 or our own, and we deal with this special case in ``get_scheme()`` instead.
47 """
48 return (
49 "osx_framework_library" in _AVAILABLE_SCHEMES
50 and not running_under_virtualenv()
51 and is_osx_framework()
52 )
53
54

Referenced by pip._internal.locations._sysconfig._infer_prefix().

Here is the caller graph for this function:

◆ get_bin_prefix()

str get_bin_prefix ( )

Definition at line 201 of file _sysconfig.py.

201def get_bin_prefix() -> str:
202 # Forcing to use /usr/local/bin for standard macOS framework installs.
203 if sys.platform[:6] == "darwin" and sys.prefix[:16] == "/System/Library/":
204 return "/usr/local/bin"
205 return sysconfig.get_paths()["scripts"]
206
207

References i.

◆ get_platlib()

str get_platlib ( )

Definition at line 212 of file _sysconfig.py.

212def get_platlib() -> str:
213 return sysconfig.get_paths()["platlib"]

References i.

◆ get_purelib()

str get_purelib ( )

Definition at line 208 of file _sysconfig.py.

208def get_purelib() -> str:
209 return sysconfig.get_paths()["purelib"]
210
211

References i.

◆ get_scheme()

Scheme get_scheme ( str  dist_name,
bool   user = False,
typing.Optional[str]   home = None,
typing.Optional[str]   root = None,
bool   isolated = False,
typing.Optional[str]   prefix = None 
)
Get the "scheme" corresponding to the input parameters.

:param dist_name: the name of the package to retrieve the scheme for, used
    in the headers scheme path
:param user: indicates to use the "user" scheme
:param home: indicates to use the "home" scheme
:param root: root under which other directories are re-based
:param isolated: ignored, but kept for distutils compatibility (where
    this controls whether the user-site pydistutils.cfg is honored)
:param prefix: indicates to use the "prefix" scheme and provides the
    base directory for the same

Definition at line 124 of file _sysconfig.py.

131) -> Scheme:
132 """
133 Get the "scheme" corresponding to the input parameters.
134
135 :param dist_name: the name of the package to retrieve the scheme for, used
136 in the headers scheme path
137 :param user: indicates to use the "user" scheme
138 :param home: indicates to use the "home" scheme
139 :param root: root under which other directories are re-based
140 :param isolated: ignored, but kept for distutils compatibility (where
141 this controls whether the user-site pydistutils.cfg is honored)
142 :param prefix: indicates to use the "prefix" scheme and provides the
143 base directory for the same
144 """
145 if user and prefix:
146 raise InvalidSchemeCombination("--user", "--prefix")
147 if home and prefix:
148 raise InvalidSchemeCombination("--home", "--prefix")
149
150 if home is not None:
151 scheme_name = _infer_home()
152 elif user:
153 scheme_name = _infer_user()
154 else:
155 scheme_name = _infer_prefix()
156
157 # Special case: When installing into a custom prefix, use posix_prefix
158 # instead of osx_framework_library. See _should_use_osx_framework_prefix()
159 # docstring for details.
160 if prefix is not None and scheme_name == "osx_framework_library":
161 scheme_name = "posix_prefix"
162
163 if home is not None:
164 variables = {k: home for k in _HOME_KEYS}
165 elif prefix is not None:
166 variables = {k: prefix for k in _HOME_KEYS}
167 else:
168 variables = {}
169
170 paths = sysconfig.get_paths(scheme=scheme_name, vars=variables)
171
172 # Logic here is very arbitrary, we're doing it for compatibility, don't ask.
173 # 1. Pip historically uses a special header path in virtual environments.
174 # 2. If the distribution name is not known, distutils uses 'UNKNOWN'. We
175 # only do the same when not running in a virtual environment because
176 # pip's historical header path logic (see point 1) did not do this.
177 if running_under_virtualenv():
178 if user:
179 base = variables.get("userbase", sys.prefix)
180 else:
181 base = variables.get("base", sys.prefix)
182 python_xy = f"python{get_major_minor_version()}"
183 paths["include"] = os.path.join(base, "include", "site", python_xy)
184 elif not dist_name:
185 dist_name = "UNKNOWN"
186
187 scheme = Scheme(
188 platlib=paths["platlib"],
189 purelib=paths["purelib"],
190 headers=os.path.join(paths["include"], dist_name),
191 scripts=paths["scripts"],
192 data=paths["data"],
193 )
194 if root is not None:
195 for key in SCHEME_KEYS:
196 value = change_root(root, getattr(scheme, key))
197 setattr(scheme, key, value)
198 return scheme
199
200

References pip._internal.locations._sysconfig._infer_home(), pip._internal.locations._sysconfig._infer_prefix(), pip._internal.locations._sysconfig._infer_user(), and i.

Here is the call graph for this function:

Variable Documentation

◆ _AVAILABLE_SCHEMES

_AVAILABLE_SCHEMES = set(sysconfig.get_scheme_names())
protected

Definition at line 24 of file _sysconfig.py.

◆ _HOME_KEYS

list _HOME_KEYS
protected
Initial value:
1= [
2 "installed_base",
3 "base",
4 "installed_platbase",
5 "platbase",
6 "prefix",
7 "exec_prefix",
8]

Definition at line 112 of file _sysconfig.py.

◆ _PREFERRED_SCHEME_API

_PREFERRED_SCHEME_API = getattr(sysconfig, "get_preferred_scheme", None)
protected

◆ logger

logger = logging.getLogger(__name__)

Definition at line 13 of file _sysconfig.py.