Skip to content

Commit

Permalink
Remove fbs and update everything
Browse files Browse the repository at this point in the history
fbs was holding back the code from using modern versions of python, qt,
and everything else. Remove fsb and update everything.

 * Remove fbs from spec
 * update to python 3.12
 * update all dependencies to latest minor releases
 * update to latest version of pyinstaller
 * re-implement part of fbs context object to minimize refactoring
 * update Vial.spec to have all options necessary to run
  • Loading branch information
dwlocks committed Apr 14, 2024
1 parent cfdafb3 commit 5b083d0
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ target
__pycache__
*.pyc
.idea
build/
dist/
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.6.0
3.12
29 changes: 29 additions & 0 deletions misc/README.pyinstaller.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Command Line to generate a spec

These are the command-line options used to generate the .spec file for pyinstaller:

```
pyi-makespec \
--specpath=misc \
--name=Vial \
--add-data="../src/main/resources/base/qmk_settings.json:resources/base" \
--add-data="../src/build/settings/base.json:resources/settings" \
--add-data="../src/build/settings/linux.json:resources/settings" \
--add-data="../src/build/settings/mac.json:resources/settings" \
--windowed \
--noupx \
--icon="../src/main/icons/Icon.ico"
--argv-emulation \
./src/main/python/main.py
```


If you are upgrading pyinstaller and want to use new default options, you must
either delete the old spec or rename it to force pyi-makespec to use updated
default options.

## Building from the spec

```
pyinstaller misc/Vial.spec
```
73 changes: 40 additions & 33 deletions misc/Vial.spec
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None
a = Analysis(
['..\\src\\main\\python\\main.py'],
pathex=[],
binaries=[],
datas=[('../src/main/resources/base/qmk_settings.json', 'resources/base'), ('../src/build/settings/base.json', 'resources/settings'), ('../src/build/settings/linux.json', 'resources/settings'), ('../src/build/settings/mac.json', 'resources/settings')],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
)
pyz = PYZ(a.pure)


a = Analysis(['../src/main/python/main.py'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
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,
[],
exclude_binaries=True,
name='Vial',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False,
console=False )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=False,
upx_exclude=[],
name='Vial')
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='Vial',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False,
console=True,
disable_windowed_traceback=False,
argv_emulation=True,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=['..\\src\\main\\icons\\Icon.ico'],
)
coll = COLLECT(
exe,
a.binaries,
a.datas,
strip=False,
upx=False,
upx_exclude=[],
name='Vial',
)
13 changes: 13 additions & 0 deletions misc/build_spec.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
REM Only useful to regenerate or add options to Vial.spec
pyi-makespec ^
--specpath=misc ^
--name=Vial ^
--add-data="../src/main/resources/base/qmk_settings.json:resources/base" ^
--add-data="../src/build/settings/base.json:resources/settings" ^
--add-data="../src/build/settings/linux.json:resources/settings" ^
--add-data="../src/build/settings/mac.json:resources/settings" ^
--console ^
--noupx ^
--icon="../src/main/icons/Icon.ico" ^
--argv-emulation ^
./src/main/python/main.py
22 changes: 13 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
altgraph==0.17
future==0.18.2
altgraph==0.17.4
certifi==2024.2.2
future==1.0.0
hidapi==0.14.0
https://github.com/danthedeckie/simpleeval/archive/41c99b8e224a7a0ae0ac59c773598fe79a4470db.zip
keyboard==0.13.5
macholib==1.14
pefile==2019.4.18
pyinstaller-hooks-contrib==2021.2
pyinstaller==4.3
packaging==24.0
pefile==2023.2.7
pyinstaller==6.5.0
pyinstaller-hooks-contrib==2024.3
PyQt5==5.15.7
PyQt5-Qt5==5.15.2
PyQt5-sip==12.9.0
PyQt5==5.15.4
PyQt5-sip==12.13.0
pywin32==306; sys_platform == 'win32'
certifi
pywin32-ctypes==0.2.2
setuptools==69.2.0
simpleeval==0.9.13
sip==6.8.3
1 change: 1 addition & 0 deletions src/build/settings/base.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"app_name": "Vial",
"organization_name": "Vial-kb",
"author": "xyz",
"main_module": "src/main/python/main.py",
"version": "0.7.1"
Expand Down
3 changes: 2 additions & 1 deletion src/build/settings/mac.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"mac_bundle_identifier": ""
"mac_bundle_identifier": "",
"organization_domain": "vial.today"
}
71 changes: 55 additions & 16 deletions src/main/python/main.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
# SPDX-License-Identifier: GPL-2.0-or-later
import ssl
import certifi
from functools import cached_property
from glob import glob
import json
import os

if ssl.get_default_verify_paths().cafile is None:
os.environ['SSL_CERT_FILE'] = certifi.where()

from os import path
import ssl
import sys
import traceback

import certifi
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QApplication

import sys

from main_window import MainWindow


# http://timlehr.com/python-exception-hooks-with-qt-message-box/
from util import init_logger

if ssl.get_default_verify_paths().cafile is None:
os.environ['SSL_CERT_FILE'] = certifi.where()

def show_exception_box(log_msg):
if QtWidgets.QApplication.instance() is not None:
Expand Down Expand Up @@ -53,29 +52,69 @@ def exception_hook(self, exc_type, exc_value, exc_traceback):
self._exception_caught.emit(log_msg)
sys._excepthook(exc_type, exc_value, exc_traceback)

class VialApplicationContext(ApplicationContext):
class VialApplicationContext():

def __init__(self):
self.bundle_dir = self.get_bundle_dir()
self.vial_settings = self.load_vial_settings()

@cached_property
def app(self):
# Override the app definition in order to set WM_CLASS.
result = QtWidgets.QApplication(sys.argv)
result.setApplicationName(self.build_settings["app_name"])
result.setOrganizationDomain("vial.today")
result.setApplicationName(self.vial_settings["app_name"])
result.setOrganizationName(self.vial_settings["organization_name"])
# Only used on mac in place of organization Name
result.setOrganizationDomain(self.vial_settings["organization_domain"])

#TODO: Qt sets applicationVersion on non-Linux platforms if the exe/pkg metadata is correctly configured.
# TODO: Qt sets applicationVersion on non-Linux platforms if the exe/pkg
# metadata is correctly configured.
# https://doc.qt.io/qt-5/qcoreapplication.html#applicationVersion-prop
# Verify it is, and only set manually on Linux.
#if sys.platform.startswith("linux"):
result.setApplicationVersion(self.build_settings["version"])
result.setApplicationVersion(self.vial_settings["version"])
return result

def load_vial_settings(self):
"""Load and merge settings/*.json files"""
settings_file_names = self.get_settings_file_names()
vial_settings = {}
for file_name in settings_file_names:
with open(file_name, "r") as base:
settings = json.load(base)
vial_settings |= settings
return vial_settings

def get_bundle_dir(self):
"""Calculate the absolute base path of the bundled app"""
return path.abspath(path.dirname(__file__))

def get_settings_file_names(self):
"""Read all settings files from the bundled resources/settings dir"""
# resources/settings/ is the bundled path set in Vial.spec for source path
settings_files_pattern = self.real_path("resources", "settings", "*.json")
return glob(settings_files_pattern)

def real_path(self, *args):
"""Calculate the absolute path of a bundled file"""
return path.join(self.bundle_dir, *args)

def get_resource(self, file_name):
"""Implement fsb context's get_resource."""
# TODO: FSB Assumed all resources are in the following directory. Maybe
# files should be moved?
return self.real_path(os.path.join("resources", "base", file_name))


if __name__ == '__main__':
if len(sys.argv) == 2 and sys.argv[1] == "--linux-recorder":
from linux_keystroke_recorder import linux_keystroke_recorder

linux_keystroke_recorder()
else:
app = QApplication(sys.argv)
init_logger()
appctxt = VialApplicationContext()
app = appctxt.app
qt_exception_hook = UncaughtHook()
window = MainWindow(appctxt)
window.show()
Expand Down

0 comments on commit 5b083d0

Please sign in to comment.