-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkdist.py
executable file
·78 lines (66 loc) · 1.93 KB
/
mkdist.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
#!/usr/bin/env python
import runpy
import shutil
import textwrap
from pathlib import Path
def delete_dir(path: Path):
if not path:
print(f"Error: '{path}' invalid.")
return False
if not path.is_dir():
print(f"Error: '{path}' not a dir.")
return False
stat = path.stat()
if not stat:
print(f"Error: can't read '{path}'.")
return False
# Try to remove the tree; if it fails, throw an error using try...except.
try:
shutil.rmtree(path)
return True
except OSError as e:
print(f"Error: {e.filename} - {e.strerror}.")
return False
def setup_dist_dir(dist_dir):
path = Path(dist_dir)
if not delete_dir(path):
print(f"deleting '{path}' failed, exiting.")
return
Path.mkdir(path)
def build():
runpy.run_module(mod_name="build", run_name="__main__", alter_sys=True)
def main():
"""
Run this script at the top level of the project.
It makes sure the "dist" directory is empty.
It builds the package in the "dist" directory.
It instructs how to proceed.
"""
dist_dir = "dist"
print(f"setting up {dist_dir} directory")
setup_dist_dir(dist_dir)
package = Path.cwd().name
print(
"Hopefully, you set the version number. If you didn't, call hatch version micro/minor/major"
)
print("see https://hatch.pypa.io/latest/version/")
print(f"building {package}")
build()
dist = Path(dist_dir)
wheel = str(next(dist.glob("*.whl")))
print(
textwrap.dedent(
f"""
now test by (creating) activating a virtual env
pip uninstall -y {package}
pip install -q {wheel}
test the package {package} interactively
pip uninstall -y {package}
deactivate
if you're happy:
python -m twine upload {dist_dir}/*
"""
)
)
if __name__ == "__main__":
main()