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

Functions

bool _contains_egg_info (str s)
 
bool _should_build (InstallRequirement req, bool need_wheel)
 
bool should_build_for_wheel_command (InstallRequirement req)
 
bool should_build_for_install_command (InstallRequirement req)
 
Optional[bool] _should_cache (InstallRequirement req)
 
str _get_cache_dir (InstallRequirement req, WheelCache wheel_cache)
 
None _verify_one (InstallRequirement req, str wheel_path)
 
Optional[str] _build_one (InstallRequirement req, str output_dir, bool verify, List[str] build_options, List[str] global_options, bool editable)
 
Optional[str] _build_one_inside_env (InstallRequirement req, str output_dir, List[str] build_options, List[str] global_options, bool editable)
 
bool _clean_one_legacy (InstallRequirement req, List[str] global_options)
 
BuildResult build (Iterable[InstallRequirement] requirements, WheelCache wheel_cache, bool verify, List[str] build_options, List[str] global_options)
 

Variables

 logger = logging.getLogger(__name__)
 
 _egg_info_re = re.compile(r"([a-z0-9_.]+)-([a-z0-9_.!+-]+)", re.IGNORECASE)
 
 BuildResult = Tuple[List[InstallRequirement], List[InstallRequirement]]
 

Detailed Description

Orchestrator for building wheels from InstallRequirements.

Function Documentation

◆ _build_one()

Optional[str] _build_one ( InstallRequirement  req,
str  output_dir,
bool  verify,
List[str]  build_options,
List[str]  global_options,
bool  editable 
)
protected
Build one wheel.

:return: The filename of the built wheel, or None if the build failed.

Definition at line 168 of file wheel_builder.py.

175) -> Optional[str]:
176 """Build one wheel.
177
178 :return: The filename of the built wheel, or None if the build failed.
179 """
180 artifact = "editable" if editable else "wheel"
181 try:
182 ensure_dir(output_dir)
183 except OSError as e:
185 "Building %s for %s failed: %s",
186 artifact,
187 req.name,
188 e,
189 )
190 return None
191
192 # Install build deps into temporary directory (PEP 518)
193 with req.build_env:
194 wheel_path = _build_one_inside_env(
195 req, output_dir, build_options, global_options, editable
196 )
197 if wheel_path and verify:
198 try:
199 _verify_one(req, wheel_path)
200 except (InvalidWheelFilename, UnsupportedWheel) as e:
201 logger.warning("Built %s for %s is invalid: %s", artifact, req.name, e)
202 return None
203 return wheel_path
204
205
for i

References pip._internal.wheel_builder._build_one_inside_env(), pip._internal.wheel_builder._verify_one(), and i.

Referenced by pip._internal.wheel_builder.build().

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

◆ _build_one_inside_env()

Optional[str] _build_one_inside_env ( InstallRequirement  req,
str  output_dir,
List[str]  build_options,
List[str]  global_options,
bool  editable 
)
protected

Definition at line 206 of file wheel_builder.py.

212) -> Optional[str]:
213 with TempDirectory(kind="wheel") as temp_dir:
214 assert req.name
217 assert req.pep517_backend
218 if global_options:
220 "Ignoring --global-option when building %s using PEP 517", req.name
221 )
222 if build_options:
224 "Ignoring --build-option when building %s using PEP 517", req.name
225 )
226 if editable:
227 wheel_path = build_wheel_editable(
228 name=req.name,
229 backend=req.pep517_backend,
230 metadata_directory=req.metadata_directory,
231 tempd=temp_dir.path,
232 )
233 else:
234 wheel_path = build_wheel_pep517(
235 name=req.name,
236 backend=req.pep517_backend,
237 metadata_directory=req.metadata_directory,
238 tempd=temp_dir.path,
239 )
240 else:
241 wheel_path = build_wheel_legacy(
242 name=req.name,
243 setup_py_path=req.setup_py_path,
245 global_options=global_options,
246 build_options=build_options,
247 tempd=temp_dir.path,
248 )
249
250 if wheel_path is not None:
251 wheel_name = os.path.basename(wheel_path)
252 dest_path = os.path.join(output_dir, wheel_name)
253 try:
254 wheel_hash, length = hash_file(wheel_path)
255 shutil.move(wheel_path, dest_path)
257 "Created wheel for %s: filename=%s size=%d sha256=%s",
258 req.name,
259 wheel_name,
260 length,
262 )
263 logger.info("Stored in directory: %s", output_dir)
264 return dest_path
265 except Exception as e:
267 "Building wheel for %s failed: %s",
268 req.name,
269 e,
270 )
271 # Ignore return, we can't do anything else useful.
272 if not req.use_pep517:
273 _clean_one_legacy(req, global_options)
274 return None
275
276

References pip._internal.wheel_builder._clean_one_legacy(), and i.

Referenced by pip._internal.wheel_builder._build_one().

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

◆ _clean_one_legacy()

bool _clean_one_legacy ( InstallRequirement  req,
List[str]  global_options 
)
protected

Definition at line 277 of file wheel_builder.py.

277def _clean_one_legacy(req: InstallRequirement, global_options: List[str]) -> bool:
278 clean_args = make_setuptools_clean_args(
280 global_options=global_options,
281 )
282
283 logger.info("Running setup.py clean for %s", req.name)
284 try:
285 call_subprocess(
286 clean_args, command_desc="python setup.py clean", cwd=req.source_dir
287 )
288 return True
289 except Exception:
290 logger.error("Failed cleaning build dir for %s", req.name)
291 return False
292
293

References i.

Referenced by pip._internal.wheel_builder._build_one_inside_env().

Here is the caller graph for this function:

◆ _contains_egg_info()

bool _contains_egg_info ( str  s)
protected
Determine whether the string looks like an egg_info.

:param s: The string to parse. E.g. foo-2.1

Definition at line 37 of file wheel_builder.py.

37def _contains_egg_info(s: str) -> bool:
38 """Determine whether the string looks like an egg_info.
39
40 :param s: The string to parse. E.g. foo-2.1
41 """
42 return bool(_egg_info_re.search(s))
43
44

References i.

Referenced by pip._internal.wheel_builder._should_cache().

Here is the caller graph for this function:

◆ _get_cache_dir()

str _get_cache_dir ( InstallRequirement  req,
WheelCache  wheel_cache 
)
protected
Return the persistent or temporary cache directory where the built
wheel need to be stored.

Definition at line 122 of file wheel_builder.py.

125) -> str:
126 """Return the persistent or temporary cache directory where the built
127 wheel need to be stored.
128 """
129 cache_available = bool(wheel_cache.cache_dir)
130 assert req.link
131 if cache_available and _should_cache(req):
133 else:
135 return cache_dir
136
137

References pip._internal.wheel_builder._should_cache(), and i.

Referenced by pip._internal.wheel_builder.build().

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

◆ _should_build()

bool _should_build ( InstallRequirement  req,
bool  need_wheel 
)
protected
Return whether an InstallRequirement should be built into a wheel.

Definition at line 45 of file wheel_builder.py.

48) -> bool:
49 """Return whether an InstallRequirement should be built into a wheel."""
51 # never build requirements that are merely constraints
52 return False
53 if req.is_wheel:
54 if need_wheel:
56 "Skipping %s, due to already being wheel.",
58 )
59 return False
60
61 if need_wheel:
62 # i.e. pip wheel, not pip install
63 return True
64
65 # From this point, this concerns the pip install command only
66 # (need_wheel=False).
67
68 if not req.source_dir:
69 return False
70
71 if req.editable:
72 # we only build PEP 660 editable requirements
74
75 return True
76
77

References i.

Referenced by pip._internal.wheel_builder.should_build_for_install_command(), and pip._internal.wheel_builder.should_build_for_wheel_command().

Here is the caller graph for this function:

◆ _should_cache()

Optional[bool] _should_cache ( InstallRequirement  req)
protected
Return whether a built InstallRequirement can be stored in the persistent
wheel cache, assuming the wheel cache is available, and _should_build()
has determined a wheel needs to be built.

Definition at line 90 of file wheel_builder.py.

92) -> Optional[bool]:
93 """
94 Return whether a built InstallRequirement can be stored in the persistent
95 wheel cache, assuming the wheel cache is available, and _should_build()
96 has determined a wheel needs to be built.
97 """
99 # never cache editable requirements
100 return False
101
103 # VCS checkout. Do not cache
104 # unless it points to an immutable commit hash.
105 assert not req.editable
106 assert req.source_dir
108 assert vcs_backend
110 return True
111 return False
112
113 assert req.link
114 base, ext = req.link.splitext()
115 if _contains_egg_info(base):
116 return True
117
118 # Otherwise, do not cache.
119 return False
120
121

References pip._internal.wheel_builder._contains_egg_info(), and i.

Referenced by pip._internal.wheel_builder._get_cache_dir().

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

◆ _verify_one()

None _verify_one ( InstallRequirement  req,
str  wheel_path 
)
protected

Definition at line 138 of file wheel_builder.py.

138def _verify_one(req: InstallRequirement, wheel_path: str) -> None:
139 canonical_name = canonicalize_name(req.name or "")
140 w = Wheel(os.path.basename(wheel_path))
141 if canonicalize_name(w.name) != canonical_name:
142 raise InvalidWheelFilename(
143 "Wheel has unexpected file name: expected {!r}, "
144 "got {!r}".format(canonical_name, w.name),
145 )
146 dist = get_wheel_distribution(FilesystemWheel(wheel_path), canonical_name)
147 dist_verstr = str(dist.version)
148 if canonicalize_version(dist_verstr) != canonicalize_version(w.version):
149 raise InvalidWheelFilename(
150 "Wheel has unexpected file name: expected {!r}, "
151 "got {!r}".format(dist_verstr, w.version),
152 )
153 metadata_version_value = dist.metadata_version
154 if metadata_version_value is None:
155 raise UnsupportedWheel("Missing Metadata-Version")
156 try:
157 metadata_version = Version(metadata_version_value)
158 except InvalidVersion:
159 msg = f"Invalid Metadata-Version: {metadata_version_value}"
160 raise UnsupportedWheel(msg)
161 if metadata_version >= Version("1.2") and not isinstance(dist.version, Version):
162 raise UnsupportedWheel(
163 "Metadata 1.2 mandates PEP 440 version, "
164 "but {!r} is not".format(dist_verstr)
165 )
166
167

References i.

Referenced by pip._internal.wheel_builder._build_one().

Here is the caller graph for this function:

◆ build()

BuildResult build ( Iterable[InstallRequirement requirements,
WheelCache  wheel_cache,
bool  verify,
List[str]  build_options,
List[str]  global_options 
)
Build wheels.

:return: The list of InstallRequirement that succeeded to build and
    the list of InstallRequirement that failed to build.

Definition at line 294 of file wheel_builder.py.

300) -> BuildResult:
301 """Build wheels.
302
303 :return: The list of InstallRequirement that succeeded to build and
304 the list of InstallRequirement that failed to build.
305 """
306 if not requirements:
307 return [], []
308
309 # Build the wheels.
311 "Building wheels for collected packages: %s",
312 ", ".join(req.name for req in requirements), # type: ignore
313 )
314
315 with indent_log():
316 build_successes, build_failures = [], []
317 for req in requirements:
318 assert req.name
319 cache_dir = _get_cache_dir(req, wheel_cache)
320 wheel_file = _build_one(
321 req,
322 cache_dir,
323 verify,
324 build_options,
325 global_options,
327 )
328 if wheel_file:
329 # Record the download origin in the cache
330 if req.download_info is not None:
331 # download_info is guaranteed to be set because when we build an
332 # InstallRequirement it has been through the preparer before, but
333 # let's be cautious.
335 # Update the link for this.
336 req.link = Link(path_to_url(wheel_file))
338 assert req.link.is_wheel
340 else:
342
343 # notify success/failure
344 if build_successes:
346 "Successfully built %s",
347 " ".join([req.name for req in build_successes]), # type: ignore
348 )
349 if build_failures:
351 "Failed to build %s",
352 " ".join([req.name for req in build_failures]), # type: ignore
353 )
354 # Return a list of requirements that failed to build
355 return build_successes, build_failures

References pip._internal.wheel_builder._build_one(), pip._internal.wheel_builder._get_cache_dir(), and i.

Here is the call graph for this function:

◆ should_build_for_install_command()

bool should_build_for_install_command ( InstallRequirement  req)

Definition at line 84 of file wheel_builder.py.

86) -> bool:
87 return _should_build(req, need_wheel=False)
88
89

References pip._internal.wheel_builder._should_build().

Here is the call graph for this function:

◆ should_build_for_wheel_command()

bool should_build_for_wheel_command ( InstallRequirement  req)

Definition at line 78 of file wheel_builder.py.

80) -> bool:
81 return _should_build(req, need_wheel=True)
82
83

References pip._internal.wheel_builder._should_build().

Here is the call graph for this function:

Variable Documentation

◆ _egg_info_re

_egg_info_re = re.compile(r"([a-z0-9_.]+)-([a-z0-9_.!+-]+)", re.IGNORECASE)
protected

Definition at line 32 of file wheel_builder.py.

◆ BuildResult

BuildResult = Tuple[List[InstallRequirement], List[InstallRequirement]]

Definition at line 34 of file wheel_builder.py.

◆ logger

logger = logging.getLogger(__name__)

Definition at line 30 of file wheel_builder.py.