-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.py
110 lines (95 loc) · 3.35 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""
Description: build script, using nuitka
Author: Rainyl
LastEditTime: 2022-08-04 17:33:48
"""
import os
import re
from argparse import ArgumentParser
from pathlib import Path
import toml
from py7zr import FILTER_LZMA2, PRESET_DEFAULT, SevenZipFile
project = toml.load(Path(__file__).parent / "pyproject.toml")
__version__ = project["tool"]["poetry"]["version"]
CPUS: int = os.cpu_count() # type: ignore
def publish_to_7z(build_dir: str, version: str):
print("Compressing...")
working_dir = Path(f"{build_dir}/CeleryMathGui.dist/")
exclude_pattern = re.compile(r"qtwebengine_devtools_resources")
for file in working_dir.glob("**/*"):
if exclude_pattern.search(str(file)):
os.remove(file)
print(f"Pattern mached, remove {file}")
save_7z_name = f"{build_dir}/CeleryMath-v{version}-Windows_x64.7z"
filters = [{"id": FILTER_LZMA2, "preset": PRESET_DEFAULT}]
with SevenZipFile(save_7z_name, "w", filters=filters, mp=True) as archive:
archive.writeall(working_dir, arcname="CeleryMath")
print(f"Publish successfully, saved to {save_7z_name}")
def main(version: str, enable_debug: bool = False, jobs: int = CPUS):
# std_out = "--force-stdout-spec=celerymath_out.log "
# std_err = "--force-stderr-spec=celerymath_error.log "
std_out = ""
std_err = ""
console = "--disable-console "
build_dir = "build"
debug = ""
if enable_debug:
console = "--enable-console "
build_dir = "build_debug "
std_out = ""
std_err = ""
# debug = "--debug "
cmd = (
"nuitka "
# "--clang "
"--mingw64 "
# "--recompile-c-only "
"--standalone "
f"{debug} "
f"--output-dir={build_dir} "
# "--follow-imports "
f"{console} "
f"{std_out} "
f"{std_err} "
f"--jobs={jobs} "
"--file-description=CeleryMath "
f"--product-version={version} "
f"""--product-name="CeleryMath_v{version}" """
"""--copyright="Copyright © 2022-2023. MODCT All Rights Reserved." """
# "--show-progress "
# "--show-memory "
"--plugin-enable=pyside6 "
# "--plugin-enable=matplotlib "
# "--plugin-enable=multiprocessing "
# "--plugin-enable=upx "
"--user-package-configuration-file=cm.nuitka-package.config.yml "
"--windows-icon-from-ico=resources/icons/logo.ico "
"./CeleryMathGui.py "
# "test.py "
)
os.system(cmd)
# make directories and copy necessary files
mkdirs = [
Path(f"{build_dir}/CeleryMathGui.dist/conf"),
]
for path in mkdirs:
if not path.exists():
print(f"Making directory: {path}")
path.mkdir(parents=True)
# # compress using 7z
publish_to_7z(build_dir, version)
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("-v", dest="version", type=str)
parser.add_argument(
"--debug",
dest="debug",
action="store_true",
help="enable build for debug",
)
parser.add_argument("-j", dest="jobs", type=int, default=CPUS)
args = parser.parse_args()
# if provide version manully, use the provided version number
args.version = args.version or __version__
main(version=args.version, enable_debug=args.debug, jobs=args.jobs)