-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathcompile.py
More file actions
executable file
·122 lines (102 loc) · 4.3 KB
/
Copy pathcompile.py
File metadata and controls
executable file
·122 lines (102 loc) · 4.3 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
122
#!/usr/bin/env python3
import os
import platform
import shutil
import subprocess
import sys
from multiprocessing import cpu_count
from pathlib import Path
from typing import Optional
sys.path.append("./src")
from sticker_convert import __version__
CRYPTOGRAPHY_WIN_ARM_WHL = "cryptography @ https://github.com/khmyznikov/PyEnv-WoA-State/releases/download/cryptography-47.0.0-arm64/cryptography-47.0.0.dev1-cp311-abi3-win_arm64.whl"
def nuitka(python_bin: str, arch: Optional[str] = None) -> None:
cmd_list = [
python_bin,
"-m",
"nuitka",
"--standalone",
"--follow-imports",
"--assume-yes-for-downloads",
"--include-package=socksio",
"--include-data-files=src/sticker_convert/ios-message-stickers-template.zip=ios-message-stickers-template.zip",
"--include-data-dir=src/sticker_convert/resources=resources",
"--include-data-dir=src/sticker_convert/locales=locales",
"--enable-plugin=tk-inter",
"--include-package-data=signalstickers_client",
"--noinclude-data-file=tcl/opt0.4",
"--noinclude-data-file=tcl/http1.0",
"--product-name=sticker-convert",
"--company-name=laggykiller",
f"--product-version={__version__}",
f"--file-version={__version__}",
"--copyright=GPL-2.0",
f"--jobs={max(int(cpu_count() / 2), 1)}",
]
if platform.system() == "Windows":
cmd_list.append(
"--windows-icon-from-ico=src/sticker_convert/resources/appicon.ico"
)
elif platform.system() == "Darwin":
cmd_list.append("--disable-console")
cmd_list.append("--macos-create-app-bundle")
cmd_list.append("--macos-app-icon=src/sticker_convert/resources/appicon.icns")
if arch is not None:
cmd_list.append(f"--macos-target-arch={arch}")
cmd_list.append(f"--macos-app-version={__version__}")
else:
cmd_list.append("--linux-icon=src/sticker_convert/resources/appicon.png")
cmd_list.append("src/sticker-convert.py")
subprocess.run(cmd_list)
def win_patch() -> None:
for i in Path("sticker-convert.dist/av.libs").iterdir():
file_path = Path("sticker-convert.dist", i.name)
if file_path.is_file():
os.remove(file_path)
def osx_patch() -> None:
# https://github.com/pyinstaller/pyinstaller/issues/5154#issuecomment-1567603461
sticker_bin = Path("sticker-convert.app/Contents/MacOS/sticker-convert")
sticker_bin_cli = Path("sticker-convert.app/Contents/MacOS/sticker-convert-cli")
sticker_bin.rename(sticker_bin_cli)
with open(sticker_bin, "w+") as f:
f.write("#!/bin/bash\n")
f.write('cd "$(dirname "$0")"\n')
f.write("open ./sticker-convert-cli")
os.chmod(sticker_bin, 0o744)
subprocess.run(["codesign", "--force", "--deep", "-s", "-", "sticker-convert.app"])
def compile() -> None:
arch = os.getenv("SC_COMPILE_ARCH")
python_bin = str(Path(sys.executable).resolve())
ios_stickers_path = "src/sticker_convert/ios-message-stickers-template"
ios_stickers_zip = ios_stickers_path + ".zip"
if Path(ios_stickers_zip).exists():
os.remove(ios_stickers_zip)
shutil.make_archive(ios_stickers_path, "zip", ios_stickers_path)
shutil.rmtree("venv", ignore_errors=True)
subprocess.run([python_bin, "-m", "venv", "venv"])
if platform.system() == "Windows":
python_bin = os.path.abspath("venv/Scripts/python.exe")
else:
python_bin = os.path.abspath("venv/bin/python")
if platform.system() == "Windows" and platform.machine().lower() in (
"arm64",
"aarch64",
):
if shutil.which("cargo") is None:
raise RuntimeError("cargo required for building on Windows arm")
with open("requirements.txt") as f:
req = f.read()
with open("requirements.txt", "w+") as f:
for line in req.split("\n"):
if "cryptography" not in line:
f.write(line + "\n")
else:
f.write(CRYPTOGRAPHY_WIN_ARM_WHL + "\n")
subprocess.run([python_bin, "-m", "pip", "install", "--prefer-binary", ".[build]"])
nuitka(python_bin, arch)
if platform.system() == "Windows":
win_patch()
elif platform.system() == "Darwin":
osx_patch()
if __name__ == "__main__":
compile()