From acdd32a7af74fe52b5977a5957999d65d97aa7af Mon Sep 17 00:00:00 2001 From: Purnendu Chakraborty Date: Thu, 25 Apr 2024 11:38:34 -0400 Subject: [PATCH] Adding ability to create a mepo binary that can uploaded as an artifact of a Github actions workflow. Pyinstaller requires that the top level script not use relative imports --- mepo.spec | 51 ++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 5 ++++- src/mepo/__main__.py | 4 ++-- 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 mepo.spec diff --git a/mepo.spec b/mepo.spec new file mode 100644 index 00000000..ef59192d --- /dev/null +++ b/mepo.spec @@ -0,0 +1,51 @@ +# -*- mode: python ; coding: utf-8 -*- + +import os +import glob + +cmd_dir = os.path.join(SPECPATH, 'src/mepo/command') +cmd_list = [os.path.basename(x).split('.')[0] for x in glob.glob(os.path.join(cmd_dir, '*.py'))] +hidden_imports = [f'mepo.command.{x}' for x in cmd_list if '_' not in x] # exclude subcommands +print(f'hidden_imports: {hidden_imports}') + +a = Analysis( + ['src/mepo/__main__.py'], + pathex=[], + binaries=[], + datas=[], + hiddenimports=hidden_imports, + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + noarchive=False, + optimize=0, +) +pyz = PYZ(a.pure) + +exe = EXE( + pyz, + a.scripts, + [], + exclude_binaries=True, + name='mepo', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +) +coll = COLLECT( + exe, + a.binaries, + a.datas, + strip=False, + upx=True, + upx_exclude=[], + name='mepo', +) diff --git a/requirements.txt b/requirements.txt index 70035c47..c42d4a53 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,5 @@ PyYAML>=5.4 -pylint>=3.1.0 +pylint +build +twine +pyinstaller diff --git a/src/mepo/__main__.py b/src/mepo/__main__.py index 9e19e63c..3da15576 100644 --- a/src/mepo/__main__.py +++ b/src/mepo/__main__.py @@ -1,7 +1,7 @@ from importlib import import_module -from .cmdline.parser import MepoArgParser -from .utilities import mepoconfig +from mepo.cmdline.parser import MepoArgParser +from mepo.utilities import mepoconfig def main():