-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathbuild.py
More file actions
121 lines (96 loc) · 4.37 KB
/
Copy pathbuild.py
File metadata and controls
121 lines (96 loc) · 4.37 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import os
import platform
import PyInstaller.__main__
import subprocess
import sys
def run(cmd: list[str], cwd: str = "."):
"""Run a subprocess command."""
subprocess.run(cmd, check=True, cwd=cwd)
def docs():
"""Build the documentation and run a local server."""
run(["make", "html"], cwd="docs")
run(["python", "-m", "http.server", "-d", "build/html"], cwd="docs")
def update_translations():
"""Generate/update .ts files from the source code."""
run(["pyside6-lupdate", "-extensions", "py", "-recursive", "ode", "-ts", "ode/assets/translations/de.ts", "-target-language", "de_DE"])
run(["pyside6-lupdate", "-extensions", "py", "-recursive", "ode", "-ts", "ode/assets/translations/es.ts", "-target-language", "es_ES"])
run(["pyside6-lupdate", "-extensions", "py", "-recursive", "ode", "-ts", "ode/assets/translations/fr.ts", "-target-language", "fr_FR"])
run(["pyside6-lupdate", "-extensions", "py", "-recursive", "ode", "-ts", "ode/assets/translations/pt.ts", "-target-language", "pt_PT"])
run(["pyside6-lupdate", "-extensions", "py", "-recursive", "ode", "-ts", "ode/assets/translations/it.ts", "-target-language", "it_IT"])
def compile_translations():
"""Compile .ts to .qm files."""
run(["pyside6-lrelease", "ode/assets/translations/de.ts", "-qm", "ode/assets/translations/de.qm"])
run(["pyside6-lrelease", "ode/assets/translations/es.ts", "-qm", "ode/assets/translations/es.qm"])
run(["pyside6-lrelease", "ode/assets/translations/fr.ts", "-qm", "ode/assets/translations/fr.qm"])
run(["pyside6-lrelease", "ode/assets/translations/pt.ts", "-qm", "ode/assets/translations/pt.qm"])
run(["pyside6-lrelease", "ode/assets/translations/it.ts", "-qm", "ode/assets/translations/it.qm"])
def build_application():
"""Build an executable file for the Application."""
system = platform.system()
# Linux Defaults
icon_path = "packaging/linux/icon.svg"
app_name = "opendataeditor"
if system == "Darwin": # macOS
icon_path = "packaging/macos/icon.icns"
app_name = "OpenDataEditor"
elif system == "Windows":
icon_path = "packaging/windows/icon.ico"
app_name = "opendataeditor"
print("Creating executable file for Open Data Editor")
params = [
"src/ode/main.py",
"--windowed", # Required for Windows install to not open a console.
"--collect-all",
"frictionless", # Frictionless depends on data files
"--collect-all",
"ode", # Collect all assets from Open Data Editor
"--collect-all",
"llama_cpp", # Collect all assets from llama_cpp
"--collect-all",
"numpy", # Collect all assets from numpy (llama_cpp dependency)
"--log-level",
"WARN",
"--name",
app_name,
"--noconfirm",
"--icon",
icon_path,
]
if system == "Darwin":
params.extend(["--osx-bundle-identifier", "org.okfn.opendataeditor"])
if system == "Windows":
# llama_cpp depends on vcomp140.dll and it is not properly collected by PyInstaller as it
# is a dependency of shiboken6 as well. This library is only present in Windows if C++ Redistributable
# is installed which might not be the case for all of our users.
params.extend(["--add-binary", "C:\\Windows\\system32\\vcomp140.dll:."])
# Allow calling `python build.py build` with extra arguments
# e.g. when building AppImage `python build.py build --onefile --name "opendataeditor-X.Y.Z.AppImage"`
cli_args = sys.argv[2:]
if cli_args:
params.extend(cli_args)
PyInstaller.__main__.run(params)
# Clean the spec file generated by PyInstaller
if os.path.exists(f"{app_name}.spec"):
os.remove(f"{app_name}.spec")
def main():
if len(sys.argv) < 2:
print("Usage:")
print(" python build.py update-translations")
print(" python build.py compile-translations")
print(" python build.py build")
print(" python build.py docs")
sys.exit(1)
command = sys.argv[1].lower()
if command == "update-translations":
update_translations()
elif command == "compile-translations":
compile_translations()
elif command == "build":
build_application()
elif command == "docs":
docs()
else:
print(f"Unknown command: {command}")
sys.exit(1)
if __name__ == "__main__":
main()