Repository navigation
Expand file tree
/
Copy pathbuild_package.py
More file actions
67 lines (52 loc) · 1.78 KB
/
Copy pathbuild_package.py
File metadata and controls
67 lines (52 loc) · 1.78 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
import argparse
import os
import datetime
TAG_ENV_NAME = "GITHUB_ACTION_TAG_NAME"
VERSION_TEXT = "0.0.0"
PROJECT_DIR = os.path.dirname(__file__)
VERSION_FILE_PATH = os.path.join("openexr_python", "__init__.py")
def parse_args():
paser = argparse.ArgumentParser()
paser.add_argument("--debug", type=bool, action=argparse.BooleanOptionalAction)
return paser.parse_args()
def get_version() -> str:
if TAG_ENV_NAME in os.environ:
return os.environ[TAG_ENV_NAME]
else:
return f"{datetime.datetime.now(datetime.timezone(datetime.timedelta(hours=9))).strftime('%Y.%m.%d.%H.%M.%S')}"
def swap_version_with_tag(
file_path: str,
version_text: str,
is_debug: bool,
):
assert os.path.exists(file_path)
assert os.path.isfile(file_path)
version = get_version()
if is_debug is True:
print(
f"The generated version is [{version}]. But swapping to [{version_text}] because this is debug mode."
)
version = version_text
with open(file=file_path, mode="r") as f:
file_text = str(f.read())
assert file_text.find(version_text) > -1
print(f"Build Version : {version}")
file_text = file_text.replace(version_text, version)
if is_debug is not True:
assert file_text.find(version_text) == -1
with open(file=file_path, mode="w") as f:
result = f.write(file_text)
print(result)
def build_package():
res = os.system("python -m build")
assert res == 0, f"The building process failed. code = {res}"
def main(args: argparse.Namespace):
is_debug: bool = args.debug
swap_version_with_tag(
file_path=VERSION_FILE_PATH,
version_text=VERSION_TEXT,
is_debug=is_debug,
)
build_package()
if __name__ == "__main__":
main(args=parse_args())