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.
This commit is contained in:
Rebecca Breu 2021-08-09 18:45:50 +02:00
parent 05bb02163d
commit ce3751912b
7 changed files with 87 additions and 61 deletions

View file

@ -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

1
.gitignore vendored
View file

@ -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

64
BeeRef.spec Normal file
View file

@ -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)

View file

@ -12,6 +12,7 @@ Changed
-------
* Make debug log file less verbose
* The program is now bundled as a single executable file (issue #4)
Fixed
-----

View file

@ -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

View file

@ -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')

View file

@ -2,5 +2,5 @@
flake8
pybadges
pyinstaller
pyinstaller >= 4.5
yamllint