forked from Windows200000/TwitchDropsMiner-updated
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild.spec
More file actions
155 lines (137 loc) · 4.52 KB
/
Copy pathbuild.spec
File metadata and controls
155 lines (137 loc) · 4.52 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# -*- mode: python ; coding: utf-8 -*-
from __future__ import annotations
import sys
import platform
import fnmatch
from pathlib import Path
from collections import abc
from traceback import format_exc
from typing import Any, TypeAlias, TYPE_CHECKING
SELF_PATH = str(Path(".").resolve())
if SELF_PATH not in sys.path:
sys.path.insert(0, SELF_PATH)
from constants import WORKING_DIR, SITE_PACKAGES_PATH, DEFAULT_LANG
if TYPE_CHECKING:
from PyInstaller.building.splash import Splash
from PyInstaller.building.build_main import Analysis
from PyInstaller.building.datastruct import _TOCTuple
from PyInstaller.building.api import PYZ, EXE, COLLECT, BUNDLE
PYZTypeCOLLECT: TypeAlias = "abc.Iterable[_TOCTuple] | PYZ"
PYZTypeEXE: TypeAlias = "abc.Iterable[_TOCTuple] | PYZ | Splash"
# Simple configuration
upx: bool = False # Use UPX compression (reduces file size, may increase AV detections)
console: bool = False # True if you'd want to add a console window (useful for debugging)
one_dir: bool = False # True for one-dir, False for one-file
optimize: int | None = None # -1/None/0=none, 1=remove asserts, 2=also remove docstrings
app_name: str = "Twitch Drops Miner (by DevilXD)"
# (source_path, dest_path, required)
to_add: list[tuple[Path, str, bool]] = [
# icon files
(Path("icons/pickaxe.ico"), "./icons", True),
(Path("icons/active.ico"), "./icons", True),
(Path("icons/idle.ico"), "./icons", True),
(Path("icons/error.ico"), "./icons", True),
(Path("icons/maint.ico"), "./icons", True),
# SeleniumWire HTTPS/SSL cert file and key
(Path(SITE_PACKAGES_PATH, "seleniumwire/ca.crt"), "./seleniumwire", False),
(Path(SITE_PACKAGES_PATH, "seleniumwire/ca.key"), "./seleniumwire", False),
]
for lang_filepath in WORKING_DIR.joinpath("lang").glob("*.json"):
to_add.append((lang_filepath, "lang", True))
# Ensure the required to-be-added data exists
datas: list[tuple[Path, str]] = []
for source_path, dest_path, required in to_add:
if source_path.exists():
datas.append((source_path, dest_path))
elif required:
raise FileNotFoundError(str(source_path))
hooksconfig: dict[str, Any] = {}
binaries: list[tuple[Path, str]] = []
hiddenimports: list[str] = [
"PIL._tkinter_finder",
"setuptools._distutils.log",
"setuptools._distutils.dir_util",
"setuptools._distutils.file_util",
"setuptools._distutils.archive_util",
]
if sys.platform == "linux":
# Needed files for better system tray support on Linux via pystray (AppIndicator backend).
"""
arch: str = platform.machine()
libraries_path: Path = Path(f"/usr/lib/{arch}-linux-gnu")
if not libraries_path.exists():
libraries_path = Path("/usr/lib64")
datas.append(
(libraries_path / "girepository-1.0/AyatanaAppIndicator3-0.1.typelib", "gi_typelibs")
)
binaries.append((libraries_path / "libayatana-appindicator3.so.1", "."))
"""
hiddenimports.extend([
"gi.repository.Gtk",
"gi.repository.GObject",
])
hooksconfig = {
"gi": {
"icons": [],
"themes": [],
"languages": ["en_US"]
}
}
a = Analysis(
["main.py"],
datas=datas,
binaries=binaries,
hooksconfig=hooksconfig,
hiddenimports=hiddenimports,
)
# Exclude unneeded Linux libraries (supports globbing)
excluded_binaries = [
"libicudata.so.*",
"libicuuc.so.*",
"librsvg-*.so.*"
]
a.binaries = [
b for b in a.binaries
if not any(fnmatch.fnmatch(b[0], pattern) for pattern in excluded_binaries)
]
if one_dir:
exe_args: PYZTypeEXE = tuple()
collect_args: PYZTypeCOLLECT = (a.datas, a.binaries)
else:
exe_args = (a.datas, a.binaries)
collect_args = tuple()
pyz = PYZ(a.pure)
try:
exe = EXE(
pyz,
a.scripts,
*exe_args,
upx=upx,
debug=False,
name=app_name,
console=console,
optimize=optimize,
exclude_binaries=one_dir,
icon="icons/pickaxe.ico",
)
except PermissionError as exc:
exc_text: str = format_exc()
if any(t in exc_text for t in ("os.remove", "os.unlink")):
raise PermissionError("Ensure the executable isn't running when rebuilding.") from exc
raise
if one_dir:
coll = COLLECT(
exe,
*collect_args,
upx=upx,
name=app_name,
)
# macOS bundle support
if sys.platform == "darwin":
source = coll if one_dir else exe
app = BUNDLE(
source,
name=f'{app_name}.app',
icon="icons/pickaxe.ico",
bundle_identifier='com.twitchdrops.miner',
)