-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path__main__.py
More file actions
95 lines (81 loc) · 2.71 KB
/
__main__.py
File metadata and controls
95 lines (81 loc) · 2.71 KB
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
from __future__ import annotations # noqa: D100
import argparse
import os
import pathlib
import sys
from typing import TYPE_CHECKING
from ._via_fresh_subprocess import SubprocessFrontend
if TYPE_CHECKING:
from ._frontend import EditableResult, SdistResult, WheelResult
def main_parser() -> argparse.ArgumentParser: # noqa: D103
parser = argparse.ArgumentParser(
description=(
"A pyproject.toml-based build frontend. "
"This is mainly useful for debugging PEP-517 backends. "
"This frontend will not do things like install required build dependencies."
),
)
parser.add_argument(
"srcdir",
type=pathlib.Path,
nargs="?",
default=pathlib.Path.cwd(),
help="source directory (defaults to current directory)",
)
parser.add_argument(
"--sdist",
"-s",
dest="distributions",
action="append_const",
const="sdist",
default=[],
help="build a source distribution",
)
parser.add_argument(
"--wheel",
"-w",
dest="distributions",
action="append_const",
const="wheel",
help="build a wheel distribution",
)
parser.add_argument(
"--editable",
"-e",
dest="distributions",
action="append_const",
const="editable",
help="build an editable wheel distribution",
)
parser.add_argument(
"--outdir",
"-o",
type=pathlib.Path,
help=f"output directory (defaults to {{srcdir}}{os.sep}dist)",
)
return parser
def main(argv: list[str]) -> None: # noqa: D103
parser = main_parser()
args = parser.parse_args(argv)
outdir = args.outdir or args.srcdir / "dist"
# we intentionally do not build editable distributions by default
distributions = args.distributions or ["sdist", "wheel"]
frontend = SubprocessFrontend(*SubprocessFrontend.create_args_from_folder(args.srcdir)[:-1])
res: SdistResult | WheelResult | EditableResult
if "sdist" in distributions:
print("Building sdist...") # noqa: T201
res = frontend.build_sdist(outdir)
print(res.out) # noqa: T201
print(res.err, file=sys.stderr) # noqa: T201
if "wheel" in distributions:
print("Building wheel...") # noqa: T201
res = frontend.build_wheel(outdir)
print(res.out) # noqa: T201
print(res.err, file=sys.stderr) # noqa: T201
if "editable" in distributions:
print("Building editable wheel...") # noqa: T201
res = frontend.build_editable(outdir)
print(res.out) # noqa: T201
print(res.err, file=sys.stderr) # noqa: T201
if __name__ == "__main__":
main(sys.argv[1:])