-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathcreate_executable.py
More file actions
77 lines (65 loc) · 2.11 KB
/
create_executable.py
File metadata and controls
77 lines (65 loc) · 2.11 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
import pathlib
import platform
import shutil
import subprocess
import sys
import tempfile
import zipfile
root_path = pathlib.Path(__file__).parent.parent
platform_names = {
"linux": "linux",
"darwin": "macos",
"win32": "windows",
}
machine_names = {
"AMD64": "x86_64",
"x86_64": "x86_64",
"aarch64": "ARM64",
"arm64": "ARM64",
}
with tempfile.TemporaryDirectory() as temp_dir:
temp_path = pathlib.Path(temp_dir)
# Copy rendercv to temp directory
shutil.copytree(root_path / "src" / "rendercv", temp_path / "rendercv")
# Create entry point script
rendercv_file = temp_path / "rendercv.py"
rendercv_file.write_text("import rendercv.cli.app as app; app.app()")
# Run PyInstaller
subprocess.run(
[
sys.executable,
"-m",
"PyInstaller",
"--onefile",
"--clean",
"--collect-all",
"rendercv",
"--collect-all",
"rendercv_fonts",
"--distpath",
"bin",
str(rendercv_file),
],
check=True,
)
# Determine executable name based on platform
platform_name = platform_names[sys.platform]
machine_name = machine_names[platform.machine()]
# Get original and new executable paths
match sys.platform:
case "win32":
original_name = "rendercv.exe"
new_name = f"rendercv-{platform_name}-{machine_name}.exe"
case _:
original_name = "rendercv"
new_name = f"rendercv-{platform_name}-{machine_name}"
original_path = root_path / "bin" / original_name
executable_path = root_path / "bin" / new_name
original_path.rename(executable_path)
# Create zip archive with preserved executable permissions
zip_path = executable_path.with_suffix(".zip")
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
zipinfo = zipfile.ZipInfo(executable_path.name)
# Set Unix executable permissions (rwxr-xr-x) - 0o755 shifted to external_attr position
zipinfo.external_attr = 0o755 << 16
zipf.writestr(zipinfo, executable_path.read_bytes())