forked from pyzo/pyzo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor freezing process (pyzo#778)
* refactor vendored qtpy and more * do a test run on ci * fix and leftover renames * fix ci * first CD * fixes * fix~ * more fixes * mo fixes * improvements * fixes * fixes * woops * fixes * undo part of last fix
- Loading branch information
1 parent
7229621
commit f264513
Showing
64 changed files
with
1,177 additions
and
1,019 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
# GH Actions script to build the Pyzo binaries. | ||
|
||
name: CD | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
tags: [ 'v*' ] | ||
branches: [ cd ] | ||
|
||
jobs: | ||
|
||
# The default Windows build serving the majority of users. | ||
# Not needed because already installed: choco install innosetup --version=5.6.1 | ||
win64: | ||
name: Build Windows 64 | ||
runs-on: windows-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.10' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -U pyside6 pyinstaller | ||
pip install -r freeze/frozen_libs.txt | ||
- name: Freeze | ||
run: python freeze/pyzo_freeze.py | ||
- name: Package | ||
run: python freeze/pyzo_package.py | ||
- name: Test frozen | ||
run: python freeze/pyzo_test_frozen.py | ||
- name: Upload distributions | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
path: | | ||
freeze/dist/*.zip | ||
freeze/dist/*.exe | ||
name: dist | ||
|
||
# A 32bit windows build for people on old machines. | ||
# Win32 is on the brink of deprecation, so we tune down on Py and Qt versions. | ||
win32: | ||
name: Build Windows 32 | ||
runs-on: windows-latest | ||
env: | ||
PYZO_QT_API: PyQt5 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.9' | ||
architecture: x86 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -U ${{ env.PYZO_QT_API }} pyinstaller | ||
pip install -r freeze/frozen_libs.txt | ||
- name: Freeze | ||
run: python freeze/pyzo_freeze.py | ||
- name: Package | ||
run: python freeze/pyzo_package.py | ||
- name: Test frozen | ||
run: python freeze/pyzo_test_frozen.py | ||
- name: Upload distributions | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
path: | | ||
freeze/dist/*.zip | ||
name: dist | ||
|
||
# A MacOS build for x86_64. Via Rosetta this should work on all modern Macs, | ||
# but an arm64 (M1) build would be nice in the future. | ||
macos_amd64: | ||
name: Build MacOS amd64 | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.10' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -U pyside6 pyinstaller | ||
pip install -r freeze/frozen_libs.txt | ||
- name: Freeze | ||
run: python freeze/pyzo_freeze.py | ||
- name: Package | ||
run: python freeze/pyzo_package.py | ||
- name: Test frozen | ||
shell: bash | ||
run: python freeze/pyzo_test_frozen.py | ||
- name: Upload distributions | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
path: | | ||
freeze/dist/*.zip | ||
freeze/dist/*.dmg | ||
name: dist | ||
|
||
# For Linux we make a build on a somewhat older ubuntu. Most Linux users prefer (or are fine with) | ||
# running Pyzo from source anyway. | ||
linux_amd64: | ||
name: Build Linux amd64 | ||
runs-on: ubuntu-18.04 | ||
env: | ||
PYZO_QT_API: PyQt5 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.9' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -U ${{ env.PYZO_QT_API }} pyinstaller | ||
pip install -r freeze/frozen_libs.txt | ||
sudo apt install -y libdbus-1-3 libxkbcommon-x11-0 libxcb-icccm4 \ | ||
libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 \ | ||
libxcb-xinerama0 libxcb-xfixes0 libxcb-shape0 | ||
- name: Freeze | ||
run: python freeze/pyzo_freeze.py | ||
- name: Package | ||
run: python freeze/pyzo_package.py | ||
- name: Test frozen | ||
run: xvfb-run --auto-servernum python freeze/pyzo_test_frozen.py | ||
- name: Upload distributions | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
path: | | ||
freeze/dist/*.tar.gz | ||
name: dist | ||
|
||
|
||
publish: | ||
name: Publish binaries to Github | ||
runs-on: ubuntu-latest | ||
needs: [ win64, win32, macos_amd64, linux_amd64 ] | ||
if: success() && startsWith(github.ref, 'refs/tags/v') | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.10' | ||
- name: Download assets | ||
uses: actions/[email protected] | ||
with: | ||
name: dist | ||
- name: Get version from git ref | ||
id: get_version | ||
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} | ||
- name: Create GH release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ steps.get_version.outputs.VERSION }} | ||
release_name: Release ${{ steps.get_version.outputs.VERSION }} | ||
body: | | ||
Autogenerated binary wheels that include wgpu-native. | ||
See [the changelog](https://github.com/pygfx/wgpu-py/blob/main/CHANGELOG.md) for details. | ||
draft: false | ||
prerelease: false | ||
- name: Upload release assets | ||
# Move back to official action after fix https://github.com/actions/upload-release-asset/issues/4 | ||
uses: AButler/[email protected] | ||
with: | ||
release-tag: ${{ steps.get_version.outputs.VERSION }} | ||
files: 'dist/*.zip;dist/*.tar.gz;dist/*.dmg;dist/*.exe;dist/*.msi' | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,7 @@ _feedstock/ | |
build/ | ||
dist/ | ||
frozen/ | ||
freeze/build/ | ||
freeze/dist/ | ||
*.pyc | ||
pyzo.egg-info/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import os | ||
import sys | ||
import platform | ||
import traceback | ||
import importlib | ||
|
||
import dialite | ||
|
||
|
||
TEST = "--test" in sys.argv | ||
|
||
|
||
# %% Utils | ||
|
||
|
||
def write(*msg): | ||
print(*msg) | ||
if TEST and os.getenv("PYZO_LOG", ""): | ||
with open(os.getenv("PYZO_LOG"), "at") as f: | ||
f.write(" ".join(msg) + "\n") | ||
|
||
|
||
class SourceImporter: | ||
def __init__(self, dir): | ||
self.module_names = set() | ||
for name in os.listdir(dir): | ||
fullname = os.path.join(dir, name) | ||
if name.endswith(".py"): | ||
self.module_names.add(name) | ||
elif os.path.isdir(fullname): | ||
if os.path.isfile(os.path.join(fullname, "__init__.py")): | ||
self.module_names.add(name) | ||
|
||
def find_spec(self, fullname, path, target=None): | ||
if fullname.split(".")[0] in self.module_names: | ||
return sys.meta_path[1].find_spec(fullname, path, target) | ||
else: | ||
return None | ||
|
||
|
||
def error_handler(cls, err, tb, action=""): | ||
title = "Application aborted" | ||
if action: | ||
title += f" while {action}" | ||
msg = f"{cls.__name__}: {err}" | ||
# Try writing traceback to stderr | ||
try: | ||
tb_info = "".join(traceback.format_list(traceback.extract_tb(tb))) | ||
write(f"{title}\n{msg}\n{tb_info}") | ||
except Exception: | ||
pass | ||
# Use dialite to show error in modal window | ||
if not TEST: | ||
dialite.fail(title, msg) | ||
|
||
|
||
class BootAction: | ||
def __init__(self, action): | ||
self._action = action | ||
try: | ||
write(action) | ||
except Exception: | ||
pass | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, cls, err, tb): | ||
if err: | ||
error_handler(cls, err, tb, self._action) | ||
sys.exit(1) | ||
|
||
|
||
# %% Boot | ||
|
||
if TEST: | ||
write("Checking Pyzo container") | ||
write(platform.platform()) | ||
write(sys.version) | ||
|
||
|
||
with BootAction("Setting up source importer"): | ||
source_dir = os.path.join(sys._MEIPASS, "source") | ||
sys.path.insert(0, source_dir) | ||
sys.meta_path.insert(0, SourceImporter(source_dir)) | ||
|
||
|
||
with BootAction("Applying pre-import Qt tweaks"): | ||
importlib.import_module("pyzo.pre_qt_import") | ||
|
||
|
||
with BootAction("Importing Qt"): | ||
QtCore = importlib.import_module("pyzo.qt." + "QtCore") | ||
QtGui = importlib.import_module("pyzo.qt." + "QtGui") | ||
QtWidgets = importlib.import_module("pyzo.qt." + "QtWidgets") | ||
|
||
|
||
with BootAction("Running Pyzo"): | ||
pyzo = importlib.import_module("pyzo") | ||
write(f"Pyzo {pyzo.__version__}") | ||
pyzo.start() | ||
write("Stopped") |
Oops, something went wrong.