EG/packaging/eg_editor.spec
2026-03-26 14:04:33 +08:00

181 lines
4.7 KiB
Python

# -*- mode: python ; coding: utf-8 -*-
import importlib.machinery
import importlib.util
import sys
from pathlib import Path
from PyInstaller.utils.hooks import collect_dynamic_libs, collect_submodules
def _has_module(module_name):
try:
return importlib.util.find_spec(module_name) is not None
except Exception:
return False
def _safe_collect_submodules(package_name):
try:
return collect_submodules(package_name)
except Exception:
return []
def _safe_collect_dynamic_libs(package_name):
try:
return collect_dynamic_libs(package_name)
except Exception:
return []
def _append_data_dir(datas, project_root, relative_path, bundle_target=None):
source = project_root / relative_path
if source.exists():
datas.append((str(source), bundle_target or relative_path.replace("\\", "/")))
def _append_package_data_dir(datas, package_name, relative_path, bundle_target):
spec = importlib.util.find_spec(package_name)
if not spec or not spec.origin:
return
package_root = Path(spec.origin).resolve().parent
source = package_root / relative_path
if source.exists():
datas.append((str(source), bundle_target))
SPEC_DIR = Path(SPEC).resolve().parent
PROJECT_ROOT = SPEC_DIR.parent
THIRD_PARTY_DIR = PROJECT_ROOT / "third_party"
RENDER_PIPELINE_DIR = PROJECT_ROOT / "RenderPipelineFile"
ENTRY_SCRIPT = PROJECT_ROOT / "Start_Run.py"
for candidate in (PROJECT_ROOT, THIRD_PARTY_DIR, RENDER_PIPELINE_DIR):
candidate_str = str(candidate)
if candidate.exists() and candidate_str not in sys.path:
sys.path.insert(0, candidate_str)
pathex = [
str(PROJECT_ROOT),
str(THIRD_PARTY_DIR),
str(RENDER_PIPELINE_DIR),
]
datas = []
for relative_path, bundle_target in (
("Resources", "Resources"),
("RenderPipelineFile", "RenderPipelineFile"),
("config", "config"),
("vr_actions", "vr_actions"),
("icons", "icons"),
("scripts", "scripts"),
("templates", "templates"),
("ui/Skins", "ui/Skins"),
("ssbo_component/shaders", "ssbo_component/shaders"),
("ssbo_component/effects", "ssbo_component/effects"),
):
_append_data_dir(datas, PROJECT_ROOT, relative_path, bundle_target)
imgui_ini = PROJECT_ROOT / "imgui.ini"
if imgui_ini.exists():
datas.append((str(imgui_ini), "."))
demo_dir = PROJECT_ROOT / "demo"
if demo_dir.exists():
datas.append((str(demo_dir), "demo"))
_append_package_data_dir(datas, "panda3d", "etc", "panda3d/etc")
binaries = []
for extension_suffix in importlib.machinery.EXTENSION_SUFFIXES:
local_lui_binary = PROJECT_ROOT / "ui" / f"lui{extension_suffix}"
if local_lui_binary.exists():
binaries.append((str(local_lui_binary), "ui"))
break
for package_name in ("panda3d", "imgui_bundle"):
binaries += _safe_collect_dynamic_libs(package_name)
if _has_module("openvr"):
binaries += _safe_collect_dynamic_libs("openvr")
hiddenimports = sorted(
set(
[
"pyassimp",
"p3dimgui",
"p3dimgui.backend",
"p3dimgui.shaders",
"rpcore",
"rpplugins",
"rplibs",
"RenderPipelineFile.rpcore",
"RenderPipelineFile.rpplugins",
"RenderPipelineFile.rplibs",
]
+ _safe_collect_submodules("core")
+ _safe_collect_submodules("scene")
+ _safe_collect_submodules("project")
+ _safe_collect_submodules("ui")
+ _safe_collect_submodules("ssbo_component")
+ _safe_collect_submodules("TransformGizmo")
+ _safe_collect_submodules("p3dimgui")
+ _safe_collect_submodules("rpcore")
+ _safe_collect_submodules("rpplugins")
+ _safe_collect_submodules("rplibs")
+ _safe_collect_submodules("RenderPipelineFile.rpcore")
+ _safe_collect_submodules("RenderPipelineFile.rpplugins")
+ _safe_collect_submodules("RenderPipelineFile.rplibs")
+ (["openvr"] if _has_module("openvr") else [])
+ (["pyassimp"] if _has_module("pyassimp") else [])
)
)
excludes = [
"PyQt5",
"PyQt6",
"PySide2",
"PySide6",
"tkinter",
]
a = Analysis(
[str(ENTRY_SCRIPT)],
pathex=pathex,
binaries=binaries,
datas=datas,
hiddenimports=hiddenimports,
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=excludes,
win_no_prefer_redirects=False,
win_private_assemblies=False,
noarchive=False,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name="EGEditor",
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False,
console=False,
)
coll = COLLECT(
exe,
a.binaries,
a.datas,
strip=False,
upx=False,
upx_exclude=[],
name="EGEditor",
)