-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild_main.py
More file actions
115 lines (97 loc) · 3.12 KB
/
Copy pathbuild_main.py
File metadata and controls
115 lines (97 loc) · 3.12 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
import os
import sys
import shutil
from pathlib import Path
linux_hidden_modules = [
"espeak", # cspell:disable-line
"python_espeak-0.5.egg-info", # cspell:disable-line
"speechd_config", # cspell:disable-line
"speechd", # cspell:disable-line
]
if sys.base_prefix == sys.prefix and "GITHUB_RUN_ID" not in os.environ: # not in venv
venv = Path(".", "venv")
if sys.platform == "win32":
venv_python = venv.joinpath("Scripts", "python.exe")
else:
venv_python = venv.joinpath("bin", "python3")
if not venv.is_dir():
cmd = f'"{sys.executable}" -m venv {venv}'
os.system(cmd)
cmd = f"{venv_python} -m pip install -r requirements.txt pyinstaller"
os.system(cmd)
if sys.platform == "linux":
import site
system_packages = site.getsitepackages()
full_paths = []
for mod in linux_hidden_modules:
for base in system_packages:
test = Path(base).joinpath(mod)
if test.exists():
full_paths.append(str(test))
copy_cmd = (
"cp -r "
+ " ".join(full_paths)
+ " "
+ str(venv)
+ "/lib/python3.*/site-packages/"
)
print(copy_cmd)
if os.system(copy_cmd):
raise RuntimeError()
cmd = f"{venv_python} {__file__}"
os.system(cmd)
raise SystemExit()
from version_freeze import frozen, pyinstaller_version_txt
import PyInstaller.__main__
hidden_imports = [
"_cffi_backend", # Required by fa_launcher_audio's dependencies
]
if sys.platform == "linux":
hidden_imports += linux_hidden_modules
locale_copy_error = None
try:
raise Exception("skipping locale copy till more stable")
p = Path("./mods/FactorioAccess/locale")
if not p.exists():
p = Path("../")/p
base = Path("./r/locale")
if not base.is_dir():
raise Exception("missing resource locale folder")
for loc in p.iterdir():
file_to_copy = loc.joinpath("launcher.cfg")
if not file_to_copy.is_file():
continue
dest = base.joinpath(loc.name + ".cfg")
shutil.copyfile(file_to_copy, dest)
except Exception as e:
locale_copy_error = e
do_gui = "--gui" in sys.argv
name = "launcher"
if do_gui:
name += "_no_console"
spec = Path(name + ".spec")
if spec.is_file():
args = [str(spec)]
else:
args = [
"--onefile", # cspell:disable-line
"main.py",
"-n",
name,
"--add-data=./r:./r",
"--version-file",
str(pyinstaller_version_txt),
]
if do_gui:
args.append("--noconsole") # cspell:disable-line
for imp in hidden_imports:
args.append("--hidden-import=" + imp)
excludes = "FixTk tcl tk _tkinter tkinter Tkinter PIL".split(" ")
for m in excludes:
args.append("--exclude-module")
args.append(m)
with frozen():
PyInstaller.__main__.run(args)
if locale_copy_error:
print(locale_copy_error)
print("warn: no locale files. If you're not developing, this is fine to ignore.")