-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.py
More file actions
95 lines (73 loc) · 2.77 KB
/
Copy pathbuild.py
File metadata and controls
95 lines (73 loc) · 2.77 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
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
import pathlib
import subprocess
import tomllib
from PyInstaller.utils.win32.versioninfo import *
project_path = pathlib.Path(__file__).parent
def get_version_number() -> str:
proj_text = (project_path / "pyproject.toml").read_text(encoding="utf-8")
proj = tomllib.loads(proj_text)
return proj["project"]["version"]
def get_commit_id() -> str | None:
try:
return subprocess.check_output(["git", "rev-parse", "--short", "HEAD"], text=True).strip()
except FileNotFoundError, subprocess.CalledProcessError:
return None
def get_version_file_content(version_number: str, commit_id: str) -> str:
if not version_number:
version_number = "0.0.0"
if commit_id:
version_text = f"{version_number} (Build {commit_id})"
else:
version_text = version_number
version_parts_str = version_number.split(".")
version_parts = []
for i in range(4):
if i < len(version_parts_str):
v = int(version_parts_str[i])
else:
v = 0
version_parts.append(v & 0xffff)
version_info = VSVersionInfo(
ffi=FixedFileInfo(
filevers=version_parts,
prodvers=version_parts,
),
kids=[
StringFileInfo([StringTable("040904B0",[
StringStruct("CompanyName", "Lucretia"),
StringStruct("FileDescription", "Decomplicator"),
StringStruct("FileVersion", version_text),
StringStruct("InternalName", "Decomplicator"),
StringStruct("OriginalFilename", "decomplicator.exe"),
StringStruct("ProductName", "Decomplicator"),
StringStruct("ProductVersion", version_text),
])]),
VarFileInfo([VarStruct("Translation", [0x0409, 0x04B0])])
]
)
return str(version_info)
def build():
build_command = [
"pyinstaller",
"--name", "decomplicator",
"--contents-directory", "application",
"--add-data", "config:config",
"--add-data", "assets/icon.png:assets",
"--add-data", "version.txt:.",
"--icon", "assets/icon.png",
"--version-file", "version_win.txt",
"--noconsole",
"--noconfirm",
"src/main.py"
]
subprocess.run(build_command, cwd=project_path)
def main():
version = get_version_number()
commit = get_commit_id() or ""
version_file = project_path / "version.txt"
version_file.write_text(f"{version}\n{commit}", encoding="utf-8")
win_version_file = project_path / "version_win.txt"
win_version_file.write_text(get_version_file_content(version, commit), encoding="utf-8")
build()
if __name__ == '__main__':
main()