-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
68 lines (52 loc) · 1.52 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
64
65
66
67
68
"""Build this project for PyPI.
"""
from datetime import datetime
import subprocess as sp
import shutil
from typing import List
def _run_command(command: str) -> None:
"""
Run the specified command.
Parameters
----------
command : str
The command string.
Raises
------
Exception
If the command return code is not 0.
"""
print(datetime.now(), f'Command started: {command}')
popen = sp.Popen(
command, shell=True, stdout=sp.PIPE, stderr=sp.STDOUT)
stdout_bytes: bytes = popen.communicate()[0]
try:
stdout: str = stdout_bytes.decode('utf-8')
except Exception:
stdout = stdout_bytes.decode('sjis')
print(datetime.now(), stdout)
if popen.returncode == 0:
return
raise Exception(f'Command failed: {popen.returncode}')
_REMOVING_DIR_PATHS: List[str] = [
'./build',
'./dist',
'./stubdoc.egg-info',
]
def _remove_build_dirs() -> None:
"""
Remove directories related to build process.
"""
for removing_dir_path in _REMOVING_DIR_PATHS:
shutil.rmtree(removing_dir_path, ignore_errors=True)
def _main() -> None:
"""Script entry point.
"""
_remove_build_dirs()
command: str = 'poetry run python setup.py sdist'
_run_command(command=command)
command = 'poetry run python setup.py bdist_wheel'
_run_command(command=command)
print(datetime.now(), 'Build completed!')
if __name__ == "__main__":
_main()