Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
BuildEnvironment Class Reference
Inheritance diagram for BuildEnvironment:

Public Member Functions

None __init__ (self)
 
None __enter__ (self)
 
None __exit__ (self, Optional[Type[BaseException]] exc_type, Optional[BaseException] exc_val, Optional[TracebackType] exc_tb)
 
Tuple[Set[Tuple[str, str]], Set[str]] check_requirements (self, Iterable[str] reqs)
 
None install_requirements (self, "PackageFinder" finder, Iterable[str] requirements, str prefix_as_string, *str kind)
 

Static Protected Member Functions

None _install_requirements (str pip_runnable, "PackageFinder" finder, Iterable[str] requirements, _Prefix prefix, *str kind)
 

Protected Attributes

 _prefixes
 
 _site_dir
 
 _save_env
 
 _lib_dirs
 

Detailed Description

Creates and manages an isolated environment to install build deps

Definition at line 80 of file build_env.py.

Constructor & Destructor Documentation

◆ __init__()

None __init__ (   self)

Reimplemented in NoOpBuildEnvironment.

Definition at line 83 of file build_env.py.

83 def __init__(self) -> None:
84 temp_dir = TempDirectory(kind=tempdir_kinds.BUILD_ENV, globally_managed=True)
85
86 self._prefixes = OrderedDict(
87 (name, _Prefix(os.path.join(temp_dir.path, name)))
88 for name in ("normal", "overlay")
89 )
90
91 self._bin_dirs: List[str] = []
92 self._lib_dirs: List[str] = []
93 for prefix in reversed(list(self._prefixes.values())):
94 self._bin_dirs.append(prefix.bin_dir)
95 self._lib_dirs.extend(prefix.lib_dirs)
96
97 # Customize site to:
98 # - ensure .pth files are honored
99 # - prevent access to system site packages
100 system_sites = _get_system_sitepackages()
101
102 self._site_dir = os.path.join(temp_dir.path, "site")
103 if not os.path.exists(self._site_dir):
104 os.mkdir(self._site_dir)
105 with open(
106 os.path.join(self._site_dir, "sitecustomize.py"), "w", encoding="utf-8"
107 ) as fp:
108 fp.write(
110 """
111 import os, site, sys
112
113 # First, drop system-sites related paths.
114 original_sys_path = sys.path[:]
115 known_paths = set()
116 for path in {system_sites!r}:
117 site.addsitedir(path, known_paths=known_paths)
118 system_paths = set(
119 os.path.normcase(path)
120 for path in sys.path[len(original_sys_path):]
121 )
122 original_sys_path = [
123 path for path in original_sys_path
124 if os.path.normcase(path) not in system_paths
125 ]
126 sys.path = original_sys_path
127
128 # Second, add lib directories.
129 # ensuring .pth file are processed.
130 for path in {lib_dirs!r}:
131 assert not path in sys.path
132 site.addsitedir(path)
133 """
134 ).format(system_sites=system_sites, lib_dirs=self._lib_dirs)
135 )
136
for i

References i.

Referenced by Protocol.__init_subclass__().

Here is the caller graph for this function:

Member Function Documentation

◆ __enter__()

None __enter__ (   self)

Reimplemented in NoOpBuildEnvironment.

Definition at line 137 of file build_env.py.

137 def __enter__(self) -> None:
138 self._save_env = {
139 name: os.environ.get(name, None)
140 for name in ("PATH", "PYTHONNOUSERSITE", "PYTHONPATH")
141 }
142
143 path = self._bin_dirs[:]
144 old_path = self._save_env["PATH"]
145 if old_path:
147
148 pythonpath = [self._site_dir]
149
151 {
152 "PATH": os.pathsep.join(path),
153 "PYTHONNOUSERSITE": "1",
154 "PYTHONPATH": os.pathsep.join(pythonpath),
155 }
156 )
157

◆ __exit__()

None __exit__ (   self,
Optional[Type[BaseException]]  exc_type,
Optional[BaseException]  exc_val,
Optional[TracebackType]  exc_tb 
)

Reimplemented in NoOpBuildEnvironment.

Definition at line 158 of file build_env.py.

163 ) -> None:
164 for varname, old_value in self._save_env.items():
165 if old_value is None:
166 os.environ.pop(varname, None)
167 else:
168 os.environ[varname] = old_value
169

References BuildEnvironment._save_env, and i.

◆ _install_requirements()

None _install_requirements ( str  pip_runnable,
"PackageFinder"  finder,
Iterable[str]  requirements,
_Prefix  prefix,
*str  kind 
)
staticprotected

Definition at line 226 of file build_env.py.

233 ) -> None:
234 args: List[str] = [
236 pip_runnable,
237 "install",
238 "--ignore-installed",
239 "--no-user",
240 "--prefix",
242 "--no-warn-script-location",
243 ]
245 args.append("-v")
246 for format_control in ("no_binary", "only_binary"):
247 formats = getattr(finder.format_control, format_control)
249 (
250 "--" + format_control.replace("_", "-"),
251 ",".join(sorted(formats or {":none:"})),
252 )
253 )
254
255 index_urls = finder.index_urls
256 if index_urls:
257 args.extend(["-i", index_urls[0]])
258 for extra_index in index_urls[1:]:
259 args.extend(["--extra-index-url", extra_index])
260 else:
261 args.append("--no-index")
262 for link in finder.find_links:
263 args.extend(["--find-links", link])
264
265 for host in finder.trusted_hosts:
266 args.extend(["--trusted-host", host])
268 args.append("--pre")
270 args.append("--prefer-binary")
271 args.append("--")
272 args.extend(requirements)
273 extra_environ = {"_PIP_STANDALONE_CERT": where()}
274 with open_spinner(f"Installing {kind}") as spinner:
275 call_subprocess(
276 args,
277 command_desc=f"pip subprocess to install {kind}",
278 spinner=spinner,
279 extra_environ=extra_environ,
280 )
281
282

References i.

Referenced by BuildEnvironment.install_requirements(), and InstallationReport.to_dict().

Here is the caller graph for this function:

◆ check_requirements()

Tuple[Set[Tuple[str, str]], Set[str]] check_requirements (   self,
Iterable[str]   reqs 
)
Return 2 sets:
- conflicting requirements: set of (installed, wanted) reqs tuples
- missing requirements: set of reqs

Definition at line 170 of file build_env.py.

172 ) -> Tuple[Set[Tuple[str, str]], Set[str]]:
173 """Return 2 sets:
174 - conflicting requirements: set of (installed, wanted) reqs tuples
175 - missing requirements: set of reqs
176 """
177 missing = set()
178 conflicting = set()
179 if reqs:
180 env = (
181 get_environment(self._lib_dirs)
182 if hasattr(self, "_lib_dirs")
183 else get_default_environment()
184 )
185 for req_str in reqs:
186 req = Requirement(req_str)
187 # We're explicitly evaluating with an empty extra value, since build
188 # environments are not provided any mechanism to select specific extras.
189 if req.marker is not None and not req.marker.evaluate({"extra": ""}):
190 continue
192 if not dist:
193 missing.add(req_str)
194 continue
195 if isinstance(dist.version, Version):
196 installed_req_str = f"{req.name}=={dist.version}"
197 else:
198 installed_req_str = f"{req.name}==={dist.version}"
199 if not req.specifier.contains(dist.version, prereleases=True):
200 conflicting.add((installed_req_str, req_str))
201 # FIXME: Consider direct URL?
202 return conflicting, missing
203

◆ install_requirements()

None install_requirements (   self,
"PackageFinder"  finder,
Iterable[str]  requirements,
str  prefix_as_string,
*str  kind 
)

Reimplemented in NoOpBuildEnvironment.

Definition at line 204 of file build_env.py.

211 ) -> None:
212 prefix = self._prefixes[prefix_as_string]
213 assert not prefix.setup
214 prefix.setup = True
215 if not requirements:
216 return
217 self._install_requirements(
218 get_runnable_pip(),
219 finder,
220 requirements,
221 prefix,
222 kind=kind,
223 )
224

References BuildEnvironment._install_requirements(), InstallationReport._install_requirements, BuildEnvironment._prefixes, pip._internal.build_env.get_runnable_pip(), and i.

Here is the call graph for this function:

Field Documentation

◆ _lib_dirs

_lib_dirs
protected

Definition at line 181 of file build_env.py.

◆ _prefixes

_prefixes
protected

Definition at line 86 of file build_env.py.

Referenced by BuildEnvironment.install_requirements().

◆ _save_env

_save_env
protected

Definition at line 138 of file build_env.py.

Referenced by BuildEnvironment.__exit__().

◆ _site_dir

_site_dir
protected

Definition at line 102 of file build_env.py.


The documentation for this class was generated from the following file: