From ce3751912b8d463a5f430dc2dde142bfffaea7fd Mon Sep 17 00:00:00 2001 From: Rebecca Breu Date: Mon, 9 Aug 2021 18:45:50 +0200 Subject: [PATCH] Let Pyinstaller build the app as one executable (fixes #4) In addition, switch over to use a spec file to allow for more flexibility in the future. --- .github/workflows/build.yml | 6 ++-- .gitignore | 1 - BeeRef.spec | 64 +++++++++++++++++++++++++++++++++++++ CHANGELOG.rst | 1 + CONTRIBUTING.rst | 18 +++++++++++ build.py | 56 -------------------------------- requirements/dev.txt | 2 +- 7 files changed, 87 insertions(+), 61 deletions(-) create mode 100644 BeeRef.spec delete mode 100644 build.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3cb3186..d85c4a7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,12 +23,12 @@ jobs: python -m pip install --upgrade pip pip install pyinstaller pip install -e . - - name: Run build.py + - name: Run Pyinstaller run: | - python build.py + pyinstaller --onefile BeeRef.spec - name: Upload artifact uses: actions/upload-artifact@v2 with: name: build - path: dist/*.zip + path: dist/* retention-days: 5 diff --git a/.gitignore b/.gitignore index 4e17ede..6ff49a6 100644 --- a/.gitignore +++ b/.gitignore @@ -33,7 +33,6 @@ MANIFEST # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest -*.spec # Installer logs pip-log.txt diff --git a/BeeRef.spec b/BeeRef.spec new file mode 100644 index 0000000..fb485d8 --- /dev/null +++ b/BeeRef.spec @@ -0,0 +1,64 @@ +# -*- mode: python ; coding: utf-8 -*- + +import os +from os.path import join +import sys + +from beeref import constants + + +block_cipher = None +appname = f'{constants.APPNAME}-{constants.VERSION}' + +if sys.platform.startswith('win'): + icon = 'logo.ico' +else: + icon = 'logo.icns' # For OSX; param gets ignored on Linux + + +a = Analysis( + [join('beeref', '__main__.py')], + pathex=[os.getcwd()], + binaries=[], + datas=[ + (join('beeref', 'documentation'), join('beeref', 'documentation')), + (join('beeref', 'assets', '*.png'), join('beeref', 'assets'))], + hiddenimports=[], + 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=appname, + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + upx_exclude=[], + runtime_tmpdir=None, + console=False, + disable_windowed_traceback=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None , + icon=join('beeref', 'assets', icon)) + +if sys.platform == 'darwin': + app = BUNDLE( + exe, + name=f'{appname}.app', + icon=join('beeref', 'assets', icon), + bundle_identifier=None) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b5476f0..6863a99 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,6 +12,7 @@ Changed ------- * Make debug log file less verbose +* The program is now bundled as a single executable file (issue #4) Fixed ----- diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 4bc4853..7e19245 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -3,6 +3,10 @@ BeeRef — Notes For Developers BeeRef is written in Python and PyQt6. + +Delevoping +---------- + Clone the repository and install beeref and its dependencies:: git clone https://github.com/rbreu/beeref.git @@ -34,6 +38,20 @@ For debugging options, run:: beeref --help + +Building the app +---------------- + +To build the app, run:: + + pyinstaller --onefile BeeRef.spec + +You will find the generated executable in the folder ``dist``. + + +Website etc. +------------ + The Python version badge in the README is generated with pybadges:: python -m pybadges --left-text=Python --right-text="3.7 | 3.8 | 3.9" > images/python_version_badge.svg diff --git a/build.py b/build.py deleted file mode 100644 index eaaed16..0000000 --- a/build.py +++ /dev/null @@ -1,56 +0,0 @@ -"""Build release files.""" - - -from distutils.sysconfig import get_python_lib -import os.path -import shutil -import sys - - -import PyInstaller.__main__ - -from beeref import constants - - -def datapath(src, dest): - return os.path.join(*src) + os.pathsep + os.path.join(*dest) - - -appname = f'{constants.APPNAME}-{constants.VERSION}' -pyqt_dir = os.path.join(get_python_lib(), 'PyQt6', 'Qt6') - -if sys.platform.startswith('win'): - libdir = 'bin' - icon = 'logo.ico' -else: - libdir = 'lib' - icon = 'logo.icns' # For OSX; param gets ignored on Linux - -PyInstaller.__main__.run([ - '--noconfirm', - '--onedir', - '--windowed', - '--name', appname, - '--hidden-import', 'PyQt6.sip', - '--icon', os.path.join('beeref', 'assets', icon), - '--add-data', datapath( - [pyqt_dir, 'plugins', 'platforms'], ['platforms']), - '--add-data', datapath( - [pyqt_dir, 'plugins', 'imageformats'], ['imageformats']), - '--add-data', datapath([pyqt_dir, libdir], ['.']), - '--add-data', datapath( - ['beeref', 'documentation'], ['beeref', 'documentation']), - '--add-data', datapath( - ['beeref', 'assets', '*.png'], ['beeref', 'assets']), - 'beeref/__main__.py' -]) - -outfilename = os.path.join('dist', f'{appname}-{sys.platform}') -print(f'Zipping output to {outfilename}.zip') -shutil.make_archive( - outfilename, - 'zip', - root_dir='dist', - base_dir=appname) - -print('Done') diff --git a/requirements/dev.txt b/requirements/dev.txt index b2af2bc..98536ff 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -2,5 +2,5 @@ flake8 pybadges -pyinstaller +pyinstaller >= 4.5 yamllint