-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathbuild.py
55 lines (41 loc) · 1.72 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
import os
import shutil
from pathlib import Path
from src import __version__
BENCHMARK_EXE_NAME = "d4lf_benchmark.exe"
EXE_NAME = "d4lf.exe"
def build(release_dir: Path):
installer_cmd = f"pyinstaller --clean --onefile --distpath {release_dir} --paths src src\\main.py"
os.system(installer_cmd)
(release_dir / "main.exe").rename(release_dir / EXE_NAME)
def build_benchmark(release_dir: Path):
installer_cmd = f'pyinstaller --clean --onefile --distpath {release_dir} --paths src --add-data "benchmarks\\assets;benchmarks\\assets" benchmarks\\imageproc.py'
os.system(installer_cmd)
(release_dir / "imageproc.exe").rename(release_dir / BENCHMARK_EXE_NAME)
def clean_up():
if (build_dir := Path("build")).exists():
shutil.rmtree(build_dir)
for p in Path.cwd().glob("*.spec"):
p.unlink()
def copy_additional_resources(release_dir: Path):
shutil.copy("README.md", release_dir)
shutil.copytree("assets", release_dir / "assets")
def create_batch_for_gui(release_dir: Path, exe_name: str):
batch_file_path = release_dir / "gui.bat"
with open(batch_file_path, "w") as f:
f.write("@echo off\n")
f.write('cd /d "%~dp0"\n')
f.write(f'start "" {exe_name} --gui')
if __name__ == "__main__":
os.chdir(Path(__file__).parent)
print(f"Building version: {__version__}")
RELEASE_DIR = Path(f"d4lf_v{__version__}")
if RELEASE_DIR.exists():
shutil.rmtree(RELEASE_DIR.absolute())
RELEASE_DIR.mkdir(exist_ok=True, parents=True)
clean_up()
build(release_dir=RELEASE_DIR)
# build_benchmark(release_dir=RELEASE_DIR)
copy_additional_resources(RELEASE_DIR)
create_batch_for_gui(release_dir=RELEASE_DIR, exe_name=EXE_NAME)
clean_up()