Skip to content

Commit

Permalink
Merge pull request #11 from DavidCEllis/env_zipapp
Browse files Browse the repository at this point in the history
Add a ducktools-env zipapp as a distribution format
  • Loading branch information
DavidCEllis authored Sep 27, 2024
2 parents c219d4f + 8e885fe commit 6a6d64e
Show file tree
Hide file tree
Showing 19 changed files with 1,420 additions and 31 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/auto-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: UnitTests

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

jobs:
test-splitguides:

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest]
python-version: ["3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .[testing]
- name: Test with pytest
run: |
pytest tests/
31 changes: 31 additions & 0 deletions .github/workflows/build-exe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build Exe Archive

#on:
# release:
# types: [published]

on: workflow_dispatch

jobs:
build:
name: Build executable
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install the module
run: |
python -m pip install --upgrade pip
python -m pip install .
- name: Build the application
run: |
python application/setup.py build
- name: Store the built application
uses: actions/upload-artifact@v4
with:
name: ducktools-exe
path: build/
68 changes: 68 additions & 0 deletions .github/workflows/build-wheel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Build and Publish wheel to Github

#on:
# release:
# types: [published]

on: workflow_dispatch

jobs:
build:
name: Build Wheel
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

# github-release:
# name: >-
# Sign the Python 🐍 distribution 📦 with Sigstore
# and upload them to GitHub Release
# needs:
# - publish-to-pypi
# runs-on: ubuntu-latest
#
# permissions:
# contents: write # IMPORTANT: mandatory for making GitHub Releases
# id-token: write # IMPORTANT: mandatory for sigstore
#
# steps:
# - name: Download all the dists
# uses: actions/download-artifact@v4
# with:
# name: python-package-distributions
# path: dist/
# - name: Sign the dists with Sigstore
# uses: sigstore/[email protected]
# with:
# release-signing-artifacts: false
# inputs: >-
# ./dist/*.tar.gz
# ./dist/*.whl
# - name: Upload artifact signatures to GitHub Release
# env:
# GITHUB_TOKEN: ${{ github.token }}
# # Upload to GitHub Release using the `gh` CLI.
# # `dist/` contains the built packages, and the
# # sigstore-produced signatures and certificates.
# run: >-
# gh release upload
# '${{ github.ref_name }}' dist/**
# --repo '${{ github.repository }}'
66 changes: 66 additions & 0 deletions .github/workflows/build-zipapp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Build zipapp

#on:
# release:
# types: [published]

on: workflow_dispatch

jobs:
build:
name: Build zipapp
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install the module
run: |
python -m pip install --upgrade pip
python -m pip install .
- name: Build the zipapp
run: |
python zipapp/build_zipapps.py
- name: Store the built zipapp
uses: actions/upload-artifact@v4
with:
name: ducktools-zipapp
path: zipapp/dist

# add-to-github-release:
# name: >-
# Sign the zipapp with Sigstore
# and upload it to GitHub Release
# needs:
# - build
# runs-on: windows-latest
#
# permissions:
# contents: write # IMPORTANT: mandatory for making GitHub Releases
# id-token: write # IMPORTANT: mandatory for sigstore
#
# steps:
# - name: Download the zipapp
# uses: actions/download-artifact@v4
# with:
# name: ducktools-zipapp
# path: zipapp/dist/
# - name: Sign the zipapp with Sigstore
# uses: sigstore/[email protected]
# with:
# release-signing-artifacts: false
# inputs: >-
# ./zipapp/dist/*.pyz
# - name: Upload artifact signature to GitHub Release
# env:
# GITHUB_TOKEN: ${{ github.token }}
# # Upload to GitHub Release using the `gh` CLI.
# # `dist/` contains the built packages, and the
# # sigstore-produced signatures and certificates.
# run: >-
# gh release upload
# '${{ github.ref_name }}' zipapp/dist/**
# --repo '${{ github.repository }}'
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ipython_config.py
# Environments
.env
.venv
env/
env*/
venv/
ENV/
env.bak/
Expand Down
9 changes: 9 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
graft src
graft tests
graft docs

prune */build
prune */dist
prune */.pytest_cache

global-exclude *~ *.py[cod] *.so
37 changes: 29 additions & 8 deletions application/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
`python setup.py build` in this folder to create the application.
"""

import itertools
import sys
import shutil
from pathlib import Path

from cx_Freeze import setup, Executable
Expand All @@ -20,6 +22,9 @@
static_folder = str(base_path / "src" / "splitguides" / "static")
icon_file = str(base_path / "resources" / "logo_alpha.ico")
icon_png = str(base_path / "resources" / "logo_alpha.png")
readme = str(base_path / "readme.md")
license_file = str(base_path / "COPYING")


base = None
if sys.platform == "win32":
Expand All @@ -37,7 +42,7 @@
"markdown.extensions.sane_lists",
"markdown.extensions.tables",
],
"include_files": [templates, static_folder, icon_png],
"include_files": [templates, static_folder, icon_png, readme, license_file],
}
}

Expand All @@ -46,10 +51,26 @@
Executable(script=server_app, target_name="splitguides_server", icon=icon_file),
]

setup(
name="splitguides",
version=splitguides.__version__,
description="Speedrun notes tool with HTML rendering",
options=options,
executables=executables,
)
if __name__ == "__main__":
build_path = Path.cwd() / "build"
if build_path.exists:
print("Cleaning up build path")
for f in itertools.chain(
build_path.glob("exe.*"),
build_path.glob("SplitGuides_v*"),
):
if f.is_dir():
print(f"Removing: {f}")
shutil.rmtree(f)

setup(
name="splitguides",
version=splitguides.__version__,
description="Speedrun notes tool with HTML rendering",
options=options,
executables=executables,
)

app_path = list(build_path.glob("exe.*"))[0]
output_folder = app_path.with_name(f"SplitGuides_v{splitguides.__version__}")
app_path.rename(output_folder)
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[build-system]
requires = [
"setuptools>=61.0",
"pyside6-essentials~=6.7",
]
build-backend = "setuptools.build_meta"

Expand All @@ -11,7 +12,7 @@ authors = [
{ name="David C Ellis" },
]
readme="README.md"
requires-python = ">=3.11" # 3.12 should function, but may not build
requires-python = ">=3.12" # 3.12 should function and build now
dependencies = [
"pyside6~=6.7",
"jinja2~=3.1",
Expand All @@ -20,13 +21,15 @@ dependencies = [
"markdown~=3.6",
"keyboard~=0.13.5",
"ducktools-classbuilder>=0.2.1", # renamed in_dict to serialize
"ducktools-env>=0.1.5", # Used for script runner implementation
"waitress~=3.0",
]
classifiers = [
"Development Status :: 3 - Alpha",
"Development Status :: 4 - Beta",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dynamic = ['version']
license = {file = "COPYING"}
Expand Down
13 changes: 13 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file exists to make sure the UI files are built
import sys
from pathlib import Path
from subprocess import run


from setuptools import setup

if __name__ == "__main__":
path_to_build = str(Path(__file__).parent / "src" / "splitguides" / "build_ui.py")
run([sys.executable, path_to_build])

setup()
2 changes: 1 addition & 1 deletion src/splitguides/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.9.0"
__version__ = "0.9.1"
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Build the .ui files into .py script files.
"""

# In v5.14 they removed pyside2uic so this invokes uic directly
from subprocess import run
from pathlib import Path
Expand All @@ -20,12 +24,14 @@ def uic(infile, outfile):
return run(cmd, capture_output=True)


def build_ui():
def build_ui(replace=True):
"""
Compile any .ui files in this folder to the build folder as .py files
:param replace: replace existing UI files
"""
# Scan this folder for .ui files
root = Path(__file__).parent
root = Path(__file__).parent / "ui" / "layouts"
ui_files = root.glob("*.ui")

# Make the build and __init__ files if they do not exist
Expand All @@ -36,13 +42,17 @@ def build_ui():

for infile in ui_files:
outfile = root / "build" / infile.with_suffix(".py").name
result = uic(infile, outfile)

if result.returncode == 0:
print(f"Read: {infile}\nBuilt: {outfile}\n")
if replace or not outfile.exists:
result = uic(infile, outfile)

if result.returncode == 0:
print(f"Read: {infile}\nBuilt: {outfile}\n")
else:
print(f"Failed to convert: code{result.returncode}\n{result.stderr}")
else:
print(f"Failed to convert: code{result.returncode}\n{result.stderr}")
print(f"Output file {outfile} already exists")


if __name__ == "__main__":
build_ui()
build_ui(replace=True)
Loading

0 comments on commit 6a6d64e

Please sign in to comment.