/
from_sdist.py
103 lines (85 loc) 路 2.95 KB
/
from_sdist.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import argparse
import subprocess
import sys
import tarfile
import tempfile
import textwrap
from pathlib import Path
from cibuildwheel.util import format_safe
def main() -> None:
parser = argparse.ArgumentParser(
prog="cibuildwheel-from-sdist",
description=textwrap.dedent(
"""
Build wheels from an sdist archive.
Extracts the sdist to a temp dir and calls cibuildwheel on the
resulting package directory. Note that cibuildwheel will be
invoked with its working directory as the package directory, so
options aside from --output-dir and --config-file are relative to
the package directory.
""",
),
epilog="Any further arguments will be passed on to cibuildwheel.",
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"--output-dir",
default="wheelhouse",
help="""
Destination folder for the wheels. Default: wheelhouse.
""",
)
parser.add_argument(
"--config-file",
default="",
help="""
TOML config file. To refer to a file inside the sdist, use the
`{project}` or `{package}` placeholder. e.g. `--config-file
{project}/config/cibuildwheel.toml` Default: "", meaning the
pyproject.toml inside the sdist, if it exists.
""",
)
parser.add_argument(
"package",
help="""
Path to the sdist archive that you want wheels for. Must be a
tar.gz archive file.
""",
)
args, passthrough_args = parser.parse_known_args()
output_dir = Path(args.output_dir).resolve()
with tempfile.TemporaryDirectory(prefix="cibw-sdist-") as temp_dir_str:
temp_dir = Path(temp_dir_str)
with tarfile.open(args.package) as tar:
tar.extractall(path=temp_dir)
temp_dir_contents = list(temp_dir.iterdir())
if len(temp_dir_contents) != 1 or not temp_dir_contents[0].is_dir():
exit("invalid sdist: didn't contain a single dir")
project_dir = temp_dir_contents[0]
if args.config_file:
# expand the placeholders if they're used
config_file_path = format_safe(
args.config_file,
project=project_dir,
package=project_dir,
)
config_file = Path(config_file_path).resolve()
else:
config_file = None
exit(
subprocess.call(
[
sys.executable,
"-m",
"cibuildwheel",
*(["--config-file", str(config_file)] if config_file else []),
"--output-dir",
output_dir,
*passthrough_args,
".",
],
cwd=project_dir,
)
)
if __name__ == "__main__":
main()