Skip to content

Instantly share code, notes, and snippets.

@pohmelie
Last active May 7, 2019 16:14
Show Gist options
  • Save pohmelie/9fbac47f2b88a6517e8a024282450135 to your computer and use it in GitHub Desktop.
Save pohmelie/9fbac47f2b88a6517e8a024282450135 to your computer and use it in GitHub Desktop.
pyinstaller extended spec with declarative hat
# -*- mode: python -*-
import configparser
import pathlib
import shutil
NAME = "app"
ONE_FILE = False
HIDDEN = [
"module_a",
"a.b.c.d",
]
# relative to pyinstaller call directory
FILES = [
"/path/to/file",
"/path/to/dir",
]
# relative to spec directory
MAIN = "anode-bin.py"
DATA = [
("/path/to/config", "config"),
("/path/to/icon.ico", "."),
]
pathlib.Path("dist").mkdir(parents=True, exist_ok=True)
for f in FILES:
for f_path in pathlib.Path().glob(f):
if f_path.is_file():
shutil.copy(f_path, "dist")
elif f_path.is_dir():
shutil.copytree(f_path, "dist/" + f_path.name)
else:
raise RuntimeError("{!r} is not file or dir".format(f))
block_cipher = None
a = Analysis(
[MAIN],
pathex=["."],
binaries=[],
datas=DATA,
hiddenimports=HIDDEN,
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
extras = []
if ONE_FILE:
extras = [
a.binaries,
a.zipfiles,
a.datas,
]
exe = EXE(
pyz,
a.scripts,
*extras,
[],
exclude_binaries=not ONE_FILE,
name=NAME,
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=False,
)
if not ONE_FILE:
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name=NAME,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment