blob: 6c918ced530b7cf198ae3ac91cdc08f80428b660 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# SPDX-License-Identifier: MIT
import os
import pathlib
import sys
import tempfile
import pep517
import build
import build.env
if sys.version_info >= (3, 8):
import importlib.metadata as importlib_metadata
else:
import importlib_metadata
def _project_wheel_metadata(builder: build.ProjectBuilder) -> 'importlib_metadata.PackageMetadata':
with tempfile.TemporaryDirectory() as tmpdir:
path = pathlib.Path(builder.metadata_path(tmpdir))
# https://github.com/python/importlib_metadata/pull/343
return importlib_metadata.PathDistribution(path).metadata # type: ignore[arg-type]
def project_wheel_metadata(
srcdir: build.PathType,
isolated: bool = True,
) -> 'importlib_metadata.PackageMetadata':
"""
Return the wheel metadata for a project.
Uses the ``prepare_metadata_for_build_wheel`` hook if available,
otherwise ``build_wheel``.
:param srcdir: Project source directory
:param isolated: Whether or not to run invoke the backend in the current
environment or to create an isolated one and invoke it
there.
"""
builder = build.ProjectBuilder(
os.fspath(srcdir),
runner=pep517.quiet_subprocess_runner,
)
if not isolated:
return _project_wheel_metadata(builder)
with build.env.IsolatedEnvBuilder() as env:
builder.python_executable = env.executable
builder.scripts_dir = env.scripts_dir
env.install(builder.build_system_requires)
env.install(builder.get_requires_for_build('wheel'))
return _project_wheel_metadata(builder)
__all__ = [
'project_wheel_metadata',
]
|