Skip to content

Commit

Permalink
📦 Move packaging to PEP 517 in-tree backend
Browse files Browse the repository at this point in the history
This essentially allows the cythonization opt-out be controlled by the
`pure-python` PEP 517 config setting that can be passed to
the corresponding build frontends via their respective CLIs.
  • Loading branch information
webknjaz committed Dec 8, 2023
1 parent cd4c589 commit d9f3405
Show file tree
Hide file tree
Showing 14 changed files with 1,054 additions and 144 deletions.
316 changes: 200 additions & 116 deletions .github/workflows/ci-cd.yml

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions .github/workflows/reusable-build-wheel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---

name: Build wheel

on:
workflow_call:
inputs:
dists-artifact-name:
description: Workflow artifact name containing dists
required: true
type: string
cython-tracing:
description: Whether to build Cython modules with line tracing
default: '0'
required: false
type: string
os:
description: VM OS to use, without version suffix
default: ubuntu
required: false
type: string
qemu:
description: Emulated QEMU architecture
default: ''
required: false
type: string
source-tarball-name:
description: Sdist filename wildcard
required: true
type: string

env:
FORCE_COLOR: "1" # Make tools pretty.
PIP_DISABLE_PIP_VERSION_CHECK: "1"
PIP_NO_PYTHON_VERSION_WARNING: "1"

jobs:

build-wheel:
name: Build wheels on ${{ inputs.os }} ${{ inputs.qemu }}
runs-on: ${{ inputs.os }}-latest
# Ref: https://github.com/python-jsonschema/check-jsonschema/issues/354
timeout-minutes: 60 # FIXME: ${{ inputs.qemu && '60' || '20' }}
steps:
- name: Retrieve the project source from an sdist inside the GHA artifact
uses: re-actors/checkout-python-sdist@release/v1
with:
source-tarball-name: ${{ inputs.source-tarball-name }}
workflow-artifact-name: ${{ inputs.dists-artifact-name }}

- name: Set up QEMU
if: inputs.qemu
uses: docker/setup-qemu-action@v3
with:
platforms: all
id: qemu
- name: Prepare emulation
if: inputs.qemu
run: |
# Build emulated architectures only if QEMU is set,
# use default "auto" otherwise
echo "CIBW_ARCHS_LINUX=${{ inputs.qemu }}" >> "${GITHUB_ENV}"
shell: bash

- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_ARCHS_MACOS: x86_64 arm64 universal2
CIBW_CONFIG_SETTINGS: >- # Cython line tracing for coverage collection
pure-python=false
with-cython-tracing=${{ inputs.cython-tracing }}
- name: Upload built artifacts for testing and publishing
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.dists-artifact-name }}
path: ./wheelhouse/*.whl

...
7 changes: 6 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
include pyproject.toml
include pytest.ini
include pytest.ci.ini
include LICENSE
include CHANGES.rst
include README.rst
include CONTRIBUTORS.txt
graft frozenlist
graft packaging
graft docs
graft requirements
graft tests
include frozenlist/*.c
global-exclude *.pyc
global-exclude *.pyd
global-exclude *.so
global-exclude *.lib
global-exclude *.dll
global-exclude *.a
global-exclude *.obj
exclude frozenlist/*.c
exclude frozenlist/*.html
prune docs/_build
11 changes: 11 additions & 0 deletions packaging/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# `pep517_backend` in-tree build backend

The `pep517_backend.hooks` importable exposes callables declared by PEP 517
and PEP 660 and is integrated into `pyproject.toml`'s
`[build-system].build-backend` through `[build-system].backend-path`.

# Design considerations

`__init__.py` is to remain empty, leaving `hooks.py` the only entrypoint
exposing the callables. The logic is contained in private modules. This is
to prevent import-time side effects.
1 change: 1 addition & 0 deletions packaging/pep517_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""PEP 517 build backend for optionally pre-building Cython."""
6 changes: 6 additions & 0 deletions packaging/pep517_backend/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys

from . import cli

if __name__ == "__main__":
sys.exit(cli.run_main_program(argv=sys.argv))
Loading

0 comments on commit d9f3405

Please sign in to comment.