Skip to content

Commit

Permalink
Refactor freezing process (pyzo#778)
Browse files Browse the repository at this point in the history
* 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
almarklein authored Dec 21, 2021
1 parent 7229621 commit f264513
Show file tree
Hide file tree
Showing 64 changed files with 1,177 additions and 1,019 deletions.
177 changes: 177 additions & 0 deletions .github/workflows/cd.yml
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 }}
42 changes: 27 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# GH Actions script to test Pyzo.

name: CI

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:

lint-build:
name: Linting
name: Test linting
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -51,6 +53,10 @@ jobs:
os: ubuntu-latest
pyversion: '3.9'
qtlib: pyside6
- name: Test Linux py310
os: ubuntu-latest
pyversion: '3.10'
qtlib: pyside6
# OS's
- name: Test Windows py310
os: windows-latest
Expand All @@ -61,28 +67,24 @@ jobs:
pyversion: '3.10'
qtlib: pyside6
# Qt libs
- name: Test Linux py310 PyQt5
- name: Test Linux py39 PyQt5
os: ubuntu-latest
pyversion: '3.10'
pyversion: '3.9'
qtlib: pyqt5
- name: Test Linux py310 PyQt6
- name: Test Linux py39 PyQt6
os: ubuntu-latest
pyversion: '3.10'
pyversion: '3.9'
qtlib: pyqt6
- name: Test Linux py310 PySide2
- name: Test Linux py39 PySide2
os: ubuntu-latest
pyversion: '3.10'
pyversion: '3.9'
qtlib: pyside2
- name: Test Linux py310 PySide6
os: ubuntu-latest
pyversion: '3.10'
qtlib: pyside6
steps:
- uses: actions/checkout@v2
- name: Setup os
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install libegl1-mesa
sudo apt install libegl1-mesa
- name: Set up Python ${{ matrix.pyversion }}
uses: actions/setup-python@v2
with:
Expand All @@ -98,4 +100,14 @@ jobs:
- name: Test on repo
run: |
pytest -v tests
# todo: add a dry-run or something so we actually boot Pyzo and close it
- name: Run Pyzo
if: matrix.os == 'ubuntu-latest'
run: |
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
xvfb-run --auto-servernum python pyzo --test
- name: Run Pyzo
if: matrix.os != 'ubuntu-latest'
run: |
python pyzo --test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ _feedstock/
build/
dist/
frozen/
freeze/build/
freeze/dist/
*.pyc
pyzo.egg-info/*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Pyzo - The Interactive editor for scientific Python

[![PyPI Version](https://img.shields.io/pypi/v/pyzo.svg)](https://pypi.python.org/pypi/pyzo/)
[![Build Status](https://dev.azure.com/pyzo/pyzo/_apis/build/status/pyzo.pyzo?branchName=master)](https://dev.azure.com/pyzo/pyzo/_build/latest?definitionId=1&branchName=master)
[![CI](https://github.com/pyzo/pyzo/actions/workflows/ci.yml/badge.svg)](https://github.com/pyzo/pyzo/actions/workflows/ci.yml)

Website: [pyzo.org](http://pyzo.org)

Expand Down
2 changes: 1 addition & 1 deletion TRANSLATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Simplified Chinese.

For the translations we make use of Qt's translation system. To update
a translation, run Qt linguist on any of the `.tr` files
[here](https://github.com/pyzo/pyzo/tree/master/pyzo/resources/translations).
[here](https://github.com/pyzo/pyzo/tree/main/pyzo/resources/translations).
Then submit the result, preferably via a Github pull request (but
emailing it to me is fine too).

Expand Down
File renamed without changes.
102 changes: 102 additions & 0 deletions freeze/boot.py
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")
Loading

0 comments on commit f264513

Please sign in to comment.