Skip to content

Commit

Permalink
Add GitHub Workflow to bundle application
Browse files Browse the repository at this point in the history
- refactored make.py for readability
- bump dependencies versions
  • Loading branch information
doizuc committed Nov 27, 2023
1 parent 5313970 commit 8723d60
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 63 deletions.
76 changes: 76 additions & 0 deletions .github/workflow/bundle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
on:
push:
branches:
- master
- dev

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']

steps:
- name: Get System Information
uses: kenchan0130/actions-system-info@master
id: system-info
- name: Echo Host Information
run: |
echo "OS: ${{ runner.os }}"
echo "CPU Core: ${{ steps.system-info.outputs.cpu-core }}"
echo "CPU Model: ${{ steps.system-info.outputs.cpu-model }}"
echo "Hostname: ${{ steps.system-info.outputs.hostname }}"
echo "Kernel release: ${{ steps.system-info.outputs.kernel-release }}"
echo "Kernel version: ${{ steps.system-info.outputs.kernel-version }}"
echo "Name: ${{ steps.system-info.outputs.name }}"
echo "Platform: ${{ steps.system-info.outputs.platform }}"
echo "Release: ${{ steps.system-info.outputs.release }}"
echo "Total memory bytes: ${{ steps.system-info.outputs.totalmem }}"
- name: Extract Branch Name
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ steps.extract_branch.outputs.branch }}

- name: Setup python
uses: actions/setup-python@v4
with:
python-version: '3.8'
cache: 'pip'
- name: Install python dependencies
run: |
pip install -r requirements.txt
pip install pyinstaller==6.0
pip list
- name: Download external resources
run: |
cd inlinino/resources
wget -r -np -R "index.html*" -nH --cut-dirs=4 https://misclab.umeoce.maine.edu/ftp/software/Inlinino/resources/
cd ../../
- name: Make Bundle
run: |
python make.py
echo "BUNDLE_NAME=$(ls bundle/dist | head -1 | xargs)" >> $GITHUB_ENV
- name: Zip Bundle
uses: thedoctor0/zip-release@0.7.1
with:
type: 'zip'
directory: 'bundle/dist/'
path: '${{ env.BUNDLE_NAME }}'
filename: '${{ env.BUNDLE_NAME }}.zip'

- name: Upload Bundle
uses: actions/upload-artifact@v3
with:
name: ${{ env.BUNDLE_NAME }}
path: bundle/dist/${{ env.BUNDLE_NAME }}.zip
# Known issue of double zip: https://github.com/actions/upload-artifact/issues/39
# However, need to zip before upload as too many files to send otherwise (very slow)
127 changes: 76 additions & 51 deletions make.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,87 @@
import PyInstaller.__main__
from inlinino import __version__
import os
import platform

import PyInstaller.__main__
import pyqtgraph
try:
import hypernav
except ImportError:
hypernav = None


root = os.path.join('.', 'bundle')
data_sep = ':'
icon_ext = 'ico'

# Set parameters specific to platform
if platform.system() not in ['Windows', 'Darwin', 'Linux']:
raise ValueError(f"Platform {platform.system()} not supported.")
os_specific_args = []
if platform.system() == 'Windows':
# Windows
OS_OPERATOR = ';'
ICON_EXT = 'ico'
DIST_PATH = 'dist_windows'
PATH_TO_SITE_PACKAGES = r'C:\Users\nils\AppData\Local\Programs\Python\Python38\Lib\site-packages' # Windows 10
OS_SPECIAL = tuple()
# PATH_TO_SITE_PACKAGES = r'C:\Program Files\Python38\Lib\site-packages' # Windows 7
# OS_SPECIAL = ('--add-data=%s%s%s' % (os.path.join(PATH_TO_SITE_PACKAGES, 'kaleido', 'executable', '*'), OS_OPERATOR, os.path.join('kaleido', 'executable')),)
PATH_TO_HYPERNAV_PACKAGE = r'Y:\PycharmProjects\hypernav'
data_sep = ';'
# Windows 7 specific
# os_specific_args = ('--add-data=%s%s%s' % (os.path.join(PATH_TO_SITE_PACKAGES, 'kaleido', 'executable', '*'),
# OS_OPERATOR, os.path.join('kaleido', 'executable')),)
elif platform.system() == 'Darwin':
# macOS
OS_OPERATOR = ':'
ICON_EXT = 'icns'
DIST_PATH = 'dist_darwin'
OS_SPECIAL = ('--target-architecture=x86_64',)
# OS_SPECIAL = ('--target-architecture=arm64', )
PATH_TO_SITE_PACKAGES = '/usr/local/Caskroom/miniconda/base/envs/Inlinino/lib/python3.8/site-packages'
PATH_TO_HYPERNAV_PACKAGE = '/Users/nils/PycharmProjects/hypernav'
# TODO add version number in plist of spec file (CFBundleVersion)
# https://pyinstaller.readthedocs.io/en/stable/spec-files.html?highlight=info_plist
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-102364
else:
# Linux
OS_OPERATOR = ':'
ICON_EXT = 'ico'
DIST_PATH = 'dist_linux'
PATH_TO_SITE_PACKAGES = '~/miniconda/base/envs/Inlinino/lib/python3.8/site-packages'
OS_SPECIAL = tuple()
HYPERNAV_IMPORT = PATH_TO_HYPERNAV_PACKAGE = '/Users/nils/PycharmProjects/hypernav'
icon_ext = 'icns'
os_specific_args = [
# '--target-arch=universal2', # Fails on GitHub but bundle works on both architecture
# Required for code signing
'--osx-bundle-identifier=com.umaine.sms.inlinino'
# f'--codesign-identity={os.getenv("CODESIGN_HASH")}',
# f'--osx-entitlements-file={os.path.join("Bundled", "entitlements.plist")}',
]

# Get version number (without importing file)
version = None
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'inlinino', '__init__.py'), 'r') as f:
for l in f:
if l.startswith('__version__'):
version = l.split('=')[1].strip(" \n'")
break

# Include all data files
add_data = []
ls = [
('README.md', '.'),
('LICENSE', '.'),
(os.path.join('inlinino', 'inlinino_cfg.json'), '.'),
(os.path.join('inlinino', 'resources'), 'resources'),
(os.path.join('inlinino', 'cfg', '*'), 'cfg'),
(os.path.join(os.path.dirname(pyqtgraph.__file__), 'icons', '*.png'), os.path.join('pyqtgraph', 'icons')),
(os.path.join(os.path.dirname(pyqtgraph.__file__), 'icons', '*.svg'), os.path.join('pyqtgraph', 'icons')),
]
if hypernav is not None:
ls.extend([
(os.path.join(os.path.dirname(hypernav.__file__), 'bin', '*.exe'), os.path.join('hypernav', 'bin')),
(os.path.join(os.path.dirname(hypernav.__file__), 'calibrate', 'templates', '*.txt'),
os.path.join('hypernav', 'calibrate', 'templates'))
])
for item, dest in ls:
add_data.append(f'--add-data={item}{data_sep}{dest}')

# Include hidden imports
hidden_imports = []
for i in [
'pyqtgraph.graphicsItems.ViewBox.axisCtrlTemplate_pyqt5',
'pyqtgraph.graphicsItems.PlotItem.plotConfigTemplate_pyqt5',
'pyqtgraph.imageview.ImageViewTemplate_pyqt5',
]:
hidden_imports.append(f'--hidden-import={i}')

# Bundle application
PyInstaller.__main__.run([
'--name=Inlinino-v%s' % __version__,
'--add-data=%s%s.' % (os.path.join('README.md'), OS_OPERATOR),
'--add-data=%s%s.' % (os.path.join('LICENSE'), OS_OPERATOR),
'--add-data=%s%s.' % (os.path.join('inlinino', 'inlinino_cfg.json'), OS_OPERATOR),
'--add-data=%s%sresources' % (os.path.join('inlinino', 'resources'), OS_OPERATOR),
'--add-data=%s%scfg' % (os.path.join('inlinino', 'cfg', '*'), OS_OPERATOR),
'--icon=%s' % os.path.join('inlinino', 'resources', 'inlinino.%s' % ICON_EXT),
'--osx-bundle-identifier=com.umaine.sms.inlinino',
'--distpath=%s' % DIST_PATH,
# pyqtgraph hidden imports
'--hidden-import=pyqtgraph.graphicsItems.ViewBox.axisCtrlTemplate_pyqt5',
'--hidden-import=pyqtgraph.graphicsItems.PlotItem.plotConfigTemplate_pyqt5',
'--hidden-import=pyqtgraph.imageview.ImageViewTemplate_pyqt5',
'--add-data=%s%s%s' % (os.path.join(PATH_TO_SITE_PACKAGES, 'pyqtgraph', 'icons', '*.png'), OS_OPERATOR, os.path.join('pyqtgraph', 'icons')),
'--add-data=%s%s%s' % (os.path.join(PATH_TO_SITE_PACKAGES, 'pyqtgraph', 'icons', '*.svg'), OS_OPERATOR, os.path.join('pyqtgraph', 'icons')),
# hidden hypernav import
'--add-data=%s%s%s' % (os.path.join(PATH_TO_HYPERNAV_PACKAGE, 'hypernav', 'bin', '*.exe'), OS_OPERATOR, os.path.join('hypernav', 'bin')),
'--add-data=%s%s%s' % (os.path.join(PATH_TO_HYPERNAV_PACKAGE, 'hypernav', 'calibrate', 'templates', '*.txt'), OS_OPERATOR, os.path.join('hypernav', 'calibrate', 'templates')),
*OS_SPECIAL,
'--clean',
f'--name=Inlinino-v{version}-{platform.system()}' % version,
'--icon=%s' % os.path.join('inlinino', 'resources', f'inlinino.{icon_ext}'),
f'--distpath={os.path.join(root, "dist")}',
f'--workpath={os.path.join(root, "build")}',
f'--specpath={root}',
'--windowed',
'--noconfirm',
# '--clean',
# '--debug=all',
'--windowed',
*add_data,
*hidden_imports,
*os_specific_args,
os.path.join('inlinino', '__main__.py')
])
23 changes: 11 additions & 12 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
pyserial>=3.4
pyqt5>=5.15
pyserial==3.5
pyqt5==5.15.4
pyqtgraph==0.12.1
colorama
numpy>=1.21
scipy
colorama==0.4.4
numpy==1.22
scipy==1.6
pyacs
pysatlantic
pynmea2>=1.18.0
pyusb>=1.2
hidapi>=0.11
setuptools
plotly
kaleido
wakepy
pynmea2==1.18.0
pyusb==1.2.1
hidapi==0.11.2
plotly==5.13.1
kaleido==0.2.1
wakepy==0.7.1

0 comments on commit 8723d60

Please sign in to comment.