From a0ee22406bdfe9a604ac74d0f6732e03f30437e2 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Mon, 4 Mar 2024 05:39:21 -0500 Subject: [PATCH] don't use spec file when building bin --- MANIFEST.in | 5 ----- relay.spec | 56 ----------------------------------------------- relay/__main__.py | 3 +++ relay/dev.py | 46 ++++++++++++++++++++++++-------------- setup.cfg | 5 +++-- 5 files changed, 35 insertions(+), 80 deletions(-) delete mode 100644 MANIFEST.in delete mode 100644 relay.spec diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index d58d6d6..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,5 +0,0 @@ -include frontend/base.haml -include frontend/style.css -include data/statements.sql -include data/swagger.yaml -include frontend/page/home.haml diff --git a/relay.spec b/relay.spec deleted file mode 100644 index 5965b51..0000000 --- a/relay.spec +++ /dev/null @@ -1,56 +0,0 @@ -# -*- mode: python ; coding: utf-8 -*- -import importlib -from pathlib import Path - - -block_cipher = None -aiohttp_swagger_path = Path(importlib.import_module('aiohttp_swagger').__file__).parent - - -a = Analysis( - ['relay/__main__.py'], - pathex=[], - binaries=[], - datas=[ - ('relay/data', 'relay/data'), - ('relay/frontend', 'relay/frontend'), - (aiohttp_swagger_path, 'aiohttp_swagger') - ], - hiddenimports=[ - 'pg8000', - 'sqlite3' - ], - hookspath=[], - hooksconfig={}, - 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) - -exe = EXE( - pyz, - a.scripts, - a.binaries, - a.zipfiles, - a.datas, - [], - name='activityrelay', - icon=None, - debug=False, - bootloader_ignore_signals=False, - strip=False, - upx=True, - upx_exclude=[], - runtime_tmpdir=None, - console=True, - disable_windowed_traceback=False, - argv_emulation=False, - target_arch=None, - codesign_identity=None, - entitlements_file=None, -) diff --git a/relay/__main__.py b/relay/__main__.py index 8ed335a..d3d7c18 100644 --- a/relay/__main__.py +++ b/relay/__main__.py @@ -1,5 +1,8 @@ +import multiprocessing + from relay.manage import main if __name__ == '__main__': + multiprocessing.freeze_support() main() diff --git a/relay/dev.py b/relay/dev.py index 5f06f3c..6407068 100644 --- a/relay/dev.py +++ b/relay/dev.py @@ -1,10 +1,14 @@ import click +import platform import subprocess import sys import time from datetime import datetime from pathlib import Path +from tempfile import TemporaryDirectory + +from . import __version__ try: from watchdog.observers import Observer @@ -46,25 +50,33 @@ def cli_lint(path): subprocess.run([sys.executable, '-m', 'pylint', path], check = False) -@cli.command('manifest-gen') -def cli_manifest_install(): - paths = [] - - for path in SCRIPT.rglob('*'): - if path.suffix.lower() in IGNORE_EXT or not path.is_file(): - continue - - paths.append(path) - - with REPO.joinpath('MANIFEST.in').open('w', encoding = 'utf-8') as fd: - for path in paths: - fd.write(f'include {str(path.relative_to(SCRIPT))}\n') - - @cli.command('build') def cli_build(): - cmd = [sys.executable, '-m', 'PyInstaller', 'relay.spec'] - subprocess.run(cmd, check = False) + with TemporaryDirectory() as tmp: + arch = 'amd64' if sys.maxsize >= 2**32 else 'i386' + cmd = [ + sys.executable, '-m', 'PyInstaller', + '--collect-data', 'relay', + '--collect-data', 'aiohttp_swagger', + '--hidden-import', 'pg8000', + '--hidden-import', 'sqlite3', + '--name', f'activityrelay-{__version__}-{platform.system().lower()}-{arch}', + '--workpath', tmp, + '--onefile', 'relay/__main__.py', + ] + + if platform.system() == 'Windows': + cmd.append('--console') + + # putting the spec path on a different drive than the source dir breaks + if str(SCRIPT)[0] == tmp[0]: + cmd.extend(['--specpath', tmp]) + + else: + cmd.append('--strip') + cmd.extend(['--specpath', tmp]) + + subprocess.run(cmd, check = False) @cli.command('run') diff --git a/setup.cfg b/setup.cfg index 685f357..41c2a30 100644 --- a/setup.cfg +++ b/setup.cfg @@ -34,8 +34,9 @@ dev = file: dev-requirements.txt [options.package_data] relay = - data/statements.sql - data/swagger.yaml + data/* + frontend/* + frontend/page/* [options.entry_points] console_scripts =