-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.py
63 lines (50 loc) · 1.7 KB
/
build.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
# SPDX-License-Identifier: MIT
import argparse
import json
import logging
import pathlib
import shutil
import sys
from typing import Dict, Optional
from collections.abc import Sequence
import bootstrap
def main_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser()
parser.add_argument(
'--outdir',
'-o',
type=str,
default='dist',
help='output directory (defaults to `dist`)',
)
return parser
def main(cli_args: Sequence[str], prog: Optional[str] = None):
parser = main_parser()
if prog:
parser.prog = prog
args, unknown = parser.parse_known_args(cli_args)
logging.basicConfig(level=logging.INFO)
outdir = pathlib.Path(args.outdir).absolute()
if outdir.exists():
if not outdir.is_dir():
raise NotADirectoryError(f"{str(outdir)} exists and it's not a directory")
shutil.rmtree(outdir)
outdir.mkdir(parents=True)
# first we install the setuptools egg-info, then wheel,
# so that setuptools thinks they are installed
bootstrap.install_package_egginfo('setuptools')
bootstrap.install_package_egginfo('wheel')
# then we can build everything
artifacts = {
package: bootstrap.build_package(package, outdir)
for package in bootstrap.PACKAGES
}
# and finally, we generate the artifact metadata
outdir.joinpath('artifacts.json').write_text(json.dumps({
package: path.name for package, path in artifacts.items()
}))
print(f'Written wheels to `{str(args.outdir)}`:' + ''.join(sorted(
f'\n\t{artifact.name}' for artifact in artifacts.values()
)))
if __name__ == '__main__':
main(sys.argv[1:], 'python -m bootstra.build')