Skip to content

Commit

Permalink
Update to PyInstaller v6, move files to a binaries/ subfolder
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSpen210 committed Nov 1, 2023
1 parent d27c86f commit 8caff8b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
16 changes: 11 additions & 5 deletions postcompiler.spec
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Build the postcompiler script."""
import shutil
from pathlib import Path

from PyInstaller.utils.hooks import collect_submodules
Expand All @@ -24,14 +25,9 @@ with open(Path(SPECPATH, 'src', 'hammeraddons', '_version.py'), 'w') as f:
f.write(f'__version__ = {version!r}\n')

DATAS = [
(str(file), str(file.relative_to(root).parent))
for file in (root / 'transforms').rglob('*.py')
] + [
(str(root / 'crowbar_command/Crowbar.exe'), '.'),
(str(root / 'crowbar_command/FluentCommandLineParser.dll'), '.'),
]
for src, dest in DATAS:
print(src, '->', dest)

a = Analysis(
['src/hammeraddons/postcompiler.py'],
Expand Down Expand Up @@ -64,6 +60,8 @@ exe = EXE(
name='postcompiler',
debug=False,
bootloader_ignore_signals=False,
# Don't use bin/, in case someone puts this right in a game dir.
contents_directory='binaries',
strip=False,
upx=True,
console=True,
Expand All @@ -78,3 +76,11 @@ coll = COLLECT(
upx=True,
name='postcompiler'
)

# Copy transforms to the same place as the EXE, not into the binaries subfolder.
app_folder = Path(coll.name)
for file in (root / 'transforms').rglob('*.py'):
dest = app_folder / file.relative_to(root)
print(file, '->', dest)
dest.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(file, dest)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ typing_extensions >= 4.2.0
srctools >= 2.3.15
trio >= 0.20.0
trio-typing >= 0.7.0
pyinstaller >= 5.12.0
pyinstaller >= 6.1.0
versioningit >= 2.1.0
14 changes: 14 additions & 0 deletions src/hammeraddons/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""Postcompiler logic."""
from pathlib import Path
import sys


try:
from ._version import __version__
except ImportError:
Expand All @@ -8,3 +12,13 @@
import sys as _sys
del _sys.modules[_version.__name__] # type: ignore # noqa
del _version, _sys # type: ignore # noqa


try:
# PyInstaller sets this attribute.
BINS_PATH = Path(sys._MEIPASS) # noqa
FROZEN = True
except AttributeError:
# Root directory is up thrice from postcompiler.py.
BINS_PATH = Path(sys.argv[0], '..', '..', '..').resolve()
FROZEN = False
10 changes: 6 additions & 4 deletions src/hammeraddons/postcompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
from typing import Dict, List, Optional
from collections import defaultdict
from logging import FileHandler, StreamHandler
import math
import shutil
import argparse
import math
import os
import re
import shutil

from srctools import __version__ as version_lib, conv_bool
from srctools.bsp import BSP, BSP_LUMPS
from srctools.filesys import ZipFileSystem
from srctools.packlist import PackList

from hammeraddons import __version__ as version_haddons, config, propcombine, mdl_compiler
from hammeraddons import (
BINS_PATH, __version__ as version_haddons, config, mdl_compiler, propcombine,
)
from hammeraddons.bsp_transform import run_transformations
from hammeraddons.move_shim import install as install_depmodule_hook

Expand Down Expand Up @@ -246,7 +248,7 @@ async def main(argv: List[str]) -> None:
if 'CROWBAR_LOC' in os.environ:
crowbar_loc = Path(os.environ['CROWBAR_LOC']).resolve()
else:
crowbar_loc = Path(sys.argv[0], '../Crowbar.exe').resolve()
crowbar_loc = Path(BINS_PATH, 'Crowbar.exe').resolve()
else:
crowbar_loc = None

Expand Down

0 comments on commit 8caff8b

Please sign in to comment.