-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathpackaging_utils.py
More file actions
140 lines (119 loc) · 3.59 KB
/
packaging_utils.py
File metadata and controls
140 lines (119 loc) · 3.59 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
"""Shared helpers for packaging scripts (PyInstaller and Nuitka)."""
from __future__ import annotations
import os
import pkgutil
from dataclasses import dataclass
from pathlib import Path
from typing import Iterable, List
PROJECT_ROOT = Path(__file__).parent
APP_DIR = PROJECT_ROOT / "app"
DATA_DIR = PROJECT_ROOT / "data"
LANGUAGE_MODULES_DIR = APP_DIR / "Language" / "modules"
VIEW_DIR = APP_DIR / "view"
LICENSE_FILE = PROJECT_ROOT / "LICENSE"
VERSION_FILE = PROJECT_ROOT / "version_info.txt"
ICON_FILE = PROJECT_ROOT / "data" / "assets" / "icon" / "secrandom-icon-paper.ico"
@dataclass(frozen=True)
class DataInclude:
"""Represents a file or directory that must be bundled with the app."""
source: Path
target: str
is_dir: bool = False
BASE_HIDDEN_IMPORTS: List[str] = [
"app.Language.obtain_language",
"app.tools.language_manager",
"app.tools.path_utils",
"app.tools.variable",
"app.tools.settings_access",
"app.tools.settings_default",
"app.tools.settings_default_storage",
"app.tools.personalised",
"app.common.data.list",
"app.common.history.history",
"app.common.display.result_display",
"app.common.extract.extract",
"app.tools.config",
"app.page_building.main_window_page",
"app.page_building.settings_window_page",
]
ADDITIONAL_HIDDEN_IMPORTS: List[str] = [
"qfluentwidgets",
"loguru",
"edge_tts",
"aiohttp",
"imageio",
"numpy",
"numpy.core",
"numpy.lib",
"numpy.fft",
"numpy.linalg",
"numpy.random",
"numpy.ma",
"numpy.polynomial",
"numpy.testing",
"numpy.distutils",
"numpy.compat",
"pandas",
"PySide6",
"app.view.another_window.contributor",
"app.view.settings.settings",
"app.view.tray.tray",
]
def collect_language_modules() -> List[str]:
modules: List[str] = []
if LANGUAGE_MODULES_DIR.exists():
for file in LANGUAGE_MODULES_DIR.glob("*.py"):
if file.name == "__init__.py":
continue
modules.append(f"app.Language.modules.{file.stem}")
return modules
def collect_view_modules() -> List[str]:
modules: List[str] = []
if VIEW_DIR.exists():
for _, name, ispkg in pkgutil.walk_packages(
[str(VIEW_DIR)], prefix="app.view."
):
if not ispkg:
modules.append(name)
return modules
def collect_data_includes() -> List[DataInclude]:
includes: List[DataInclude] = []
if DATA_DIR.exists():
includes.append(DataInclude(DATA_DIR, "data", is_dir=True))
if LANGUAGE_MODULES_DIR.exists():
includes.append(
DataInclude(LANGUAGE_MODULES_DIR, "app/Language/modules", is_dir=True)
)
if LICENSE_FILE.exists():
includes.append(DataInclude(LICENSE_FILE, ".", is_dir=False))
return includes
def normalize_hidden_imports(extra: Iterable[str] = ()) -> List[str]:
seen = set()
ordered: List[str] = []
for name in list(BASE_HIDDEN_IMPORTS) + list(extra):
if name in seen:
continue
seen.add(name)
ordered.append(name)
return ordered
def format_add_data(include: DataInclude) -> str:
sep = ";" if os.name == "nt" else ":"
return f"{include.source}{sep}{include.target}"
__all__ = [
"PROJECT_ROOT",
"APP_DIR",
"DATA_DIR",
"LANGUAGE_MODULES_DIR",
"VIEW_DIR",
"LICENSE_FILE",
"VERSION_FILE",
"ICON_FILE",
"DataInclude",
"BASE_HIDDEN_IMPORTS",
"ADDITIONAL_HIDDEN_IMPORTS",
"collect_language_modules",
"collect_view_modules",
"collect_data_includes",
"normalize_hidden_imports",
"format_add_data",
]