Skip to content

Commit 5a0e691

Browse files
authored
Refactor build system (#596)
* Refactor build logic * update (simplify) cd.yml * fix typo * Fix ci (I think) * deps * typo * not sure why but need preinstalled here * black * twine too * no input * try * remove dev reqs * Fix ci/cd * do korijns earlier trick * tweak in error msg * Fix sdist * Update references to download script * black * fix cd * Move coverage config to pyproject.toml * apply review suggestions
1 parent 379599c commit 5a0e691

File tree

15 files changed

+402
-293
lines changed

15 files changed

+402
-293
lines changed

.github/ISSUE_TEMPLATE/update-wgpu.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ For context, see the [codegen readme](https://github.com/pygfx/wgpu-py/blob/main
4747

4848
*The lines below can be copied in the PR's top post.*
4949

50-
* [ ] Run `python download-wgpu-native.py --version xx` to download the latest webgpu.h and DLL.
50+
* [ ] Run `python tools/download_wgpu_native.py --version xx` to download the latest webgpu.h and DLL.
5151
* [ ] Run `python codegen` to apply the automatic patches to the code.
5252
* [ ] It may be necessary to tweak the `hparser.py` to adjust to new formatting.
5353
* [ ] Diff the report for new differences to take into account.

.github/workflows/cd.yml

Lines changed: 53 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
# Github Actions script to produce binary wheels.
22
#
3-
# Note that a lot of the cibuildwheel config is in pyproject.toml.
4-
#
5-
# We perform one build for each wheel that we generate, i.e. one per architecture.
6-
# In download_wgpu_native.py, we detect CIBW_PLATFORM and CIBW_ARCHS to determine
7-
# the required binary from wgpu-native.
8-
#
9-
# If https://github.com/pypa/cibuildwheel/issues/944 gets implemented, we can build more wheels per build.
10-
#
11-
# Also includes the sdist build that does not include a binary.
12-
3+
# * One build to create all wheels (cross-platform).
4+
# * One build (with matrix) test the wheels on a selection of platforms.
5+
# * One build to publish the wheels on GitHub and Pypi.
136

147
name: CD
158

@@ -24,118 +17,88 @@ on:
2417

2518
jobs:
2619

27-
release-builds:
28-
name: Build wheel for ${{ matrix.platform }} ${{ matrix.arch }}
29-
timeout-minutes: 10
20+
build-wheels:
21+
name: Build all wheels
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: '3.12'
29+
- name: Install dev dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install -U -e .[build]
33+
- name: Build wheels (and sdist)
34+
run: python tools/build_all_wheels.py
35+
- name: Twine check
36+
run: |
37+
twine check dist/*
38+
- name: Upload distributions
39+
uses: actions/upload-artifact@v4
40+
with:
41+
path: dist
42+
name: all_wheels
43+
44+
test-wheels:
45+
name: Test wheel for ${{ matrix.name }}
46+
needs: [build-wheels]
3047
runs-on: ${{ matrix.os }}
3148
strategy:
3249
fail-fast: false
3350
matrix:
3451
include:
35-
- platform: windows
36-
arch: AMD64
37-
os: windows-latest
38-
testable: true
39-
- platform: windows
40-
arch: ARM64
52+
- name: windows amd64
4153
os: windows-latest
42-
- platform: windows
43-
arch: x86
44-
os: windows-latest
45-
- platform: macos
46-
arch: arm64
54+
- name: macos arm64
4755
os: macos-latest
48-
testable: true
49-
- platform: macos
50-
arch: x86_64
56+
- name: macos x86_64
5157
os: macos-13 # last Intel MacOS
52-
cibw_version: '==2.16' # delocation does not work for later versions
53-
- platform: linux
54-
arch: x86_64
55-
os: ubuntu-latest
56-
testable: true
57-
- platform: linux
58-
arch: aarch64
58+
- name: linux amd64
5959
os: ubuntu-latest
6060
steps:
6161
- uses: actions/checkout@v4
62-
- name: Set up QEMU
63-
if: matrix.platform == 'linux' && matrix.arch == 'aarch64'
64-
uses: docker/setup-qemu-action@v3
62+
- name: Set up Python
63+
uses: actions/setup-python@v5
6564
with:
66-
platforms: arm64
67-
- name: Install dev dependencies
68-
run: |
69-
python -m pip install --upgrade pip wheel setuptools twine cibuildwheel${{ matrix.cibw_version}}
70-
- name: Build wheels
71-
run: python -m cibuildwheel --output-dir dist
72-
env:
73-
CIBW_PLATFORM: ${{ matrix.platform }}
74-
CIBW_ARCHS: ${{ matrix.arch }}
75-
- name: Twine check
65+
python-version: '3.12'
66+
- name: Download assets
67+
uses: actions/download-artifact@v4
68+
with:
69+
path: dist
70+
- name: Flatten dist dir
71+
shell: bash
7672
run: |
77-
twine check dist/*
78-
- name: Test wheel
79-
if: matrix.testable
73+
find dist -mindepth 2 -type f -exec mv -f '{}' dist/ ';'
74+
rm -rf dist/*/
75+
- name: Install and test wheel
8076
shell: bash
8177
run: |
8278
rm -rf ./wgpu
83-
filename=$(ls dist/*.whl)
84-
pip install $filename
79+
# Install 'normally' to install deps, then force the install from dist-folder and nothing else
80+
pip install --find-links dist wgpu
81+
pip install --force-reinstall --no-deps --no-index --find-links dist wgpu
8582
pushd $HOME
8683
python -c 'import wgpu.backends.wgpu_native; print(wgpu.backends.wgpu_native._ffi.lib_path)'
8784
popd
8885
pip uninstall -y wgpu
8986
git reset --hard HEAD
90-
- name: Upload distributions
91-
uses: actions/upload-artifact@v4
92-
with:
93-
path: dist
94-
name: ${{ matrix.platform }}-${{ matrix.arch }}-build
95-
96-
97-
sdist-build:
98-
name: Build sdist
99-
timeout-minutes: 5
100-
runs-on: ubuntu-latest
101-
strategy:
102-
fail-fast: false
103-
steps:
104-
- uses: actions/checkout@v4
105-
- name: Set up Python
106-
uses: actions/setup-python@v5
107-
with:
108-
python-version: '3.12'
109-
- name: Install dev dependencies
110-
run: |
111-
python -m pip install --upgrade pip
112-
pip install -U -r dev-requirements.txt
113-
- name: Create source distribution
114-
run: |
115-
python setup.py sdist
116-
- name: Test sdist
87+
- name: Install from sdist
11788
shell: bash
11889
run: |
11990
rm -rf ./wgpu
91+
rm -rf ./dist/*.whl
92+
# Install sdist, but no test, because there is no wgpu-native lib now.
12093
filename=$(ls dist/*.tar.gz)
12194
pip install $filename
122-
# don't run tests, we just want to know if the sdist can be installed
12395
pip uninstall -y wgpu
12496
git reset --hard HEAD
125-
- name: Twine check
126-
run: |
127-
twine check dist/*
128-
- name: Upload distributions
129-
uses: actions/upload-artifact@v4
130-
with:
131-
path: dist
132-
name: sdist-build
133-
13497
13598
publish:
13699
name: Publish to Github and Pypi
137100
runs-on: ubuntu-latest
138-
needs: [release-builds, sdist-build]
101+
needs: [build-wheels, test-wheels]
139102
if: success() && startsWith(github.ref, 'refs/tags/v')
140103
steps:
141104
- uses: actions/checkout@v4

.github/workflows/ci.yml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Install dev dependencies
2929
run: |
3030
python -m pip install --upgrade pip
31-
pip install -U black flake8 flake8-black pep8-naming
31+
pip install -U -e .[lint]
3232
- name: Flake8
3333
run: |
3434
flake8 .
@@ -48,7 +48,7 @@ jobs:
4848
- name: Install dependencies
4949
run: |
5050
python -m pip install --upgrade pip
51-
pip install -U pytest numpy black cffi
51+
pip install -U -e .[codegen]
5252
- name: Test codegen
5353
run: |
5454
pytest -v codegen
@@ -68,9 +68,6 @@ jobs:
6868
- name: Install dependencies
6969
run: |
7070
python -m pip install --upgrade pip
71-
pip install requests
72-
python download-wgpu-native.py
73-
pip uninstall -q -y requests
7471
pip install -e .
7572
- name: Test imports
7673
env:
@@ -96,7 +93,7 @@ jobs:
9693
- name: Install dev dependencies
9794
run: |
9895
python -m pip install --upgrade pip
99-
pip install -U -r dev-requirements.txt
96+
pip install -U -e .[docs]
10097
- name: Build docs
10198
run: |
10299
cd docs
@@ -121,9 +118,7 @@ jobs:
121118
- name: Install dev dependencies
122119
run: |
123120
python -m pip install --upgrade pip
124-
pip install -U -r dev-requirements.txt
125-
python download-wgpu-native.py
126-
pip install -e .
121+
pip install -U -e .[tests,examples]
127122
- name: Test examples
128123
env:
129124
EXPECT_LAVAPIPE: true
@@ -145,10 +140,7 @@ jobs:
145140
- name: Install dependencies
146141
run: |
147142
python -m pip install --upgrade pip
148-
pip install -U requests numpy pytest
149-
python download-wgpu-native.py
150-
pip install -e .
151-
pip install psutil glfw pyinstaller>=4.9
143+
pip install -U -e .[tests] glfw pyinstaller
152144
- name: Test PyInstaller
153145
run: |
154146
pyinstaller --version
@@ -194,9 +186,7 @@ jobs:
194186
- name: Install dev dependencies
195187
run: |
196188
python -m pip install --upgrade pip
197-
pip install -U -r dev-requirements.txt
198-
python download-wgpu-native.py
199-
pip install -e .
189+
pip install -U -e .[tests]
200190
- name: Unit tests
201191
run: |
202192
pytest -v tests

.github/workflows/screenshots.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
screenshots:
11-
name: Regenerate
11+
name: Regenerate screenshot
1212
timeout-minutes: 10
1313
runs-on: 'ubuntu-latest'
1414
steps:
@@ -26,9 +26,7 @@ jobs:
2626
- name: Install dev dependencies
2727
run: |
2828
python -m pip install --upgrade pip
29-
pip install -U -r dev-requirements.txt
30-
python download-wgpu-native.py
31-
pip install -e .
29+
pip install -U -e .[tests,examples]
3230
- name: Regenerate screenshots
3331
run: |
3432
pytest -v --regenerate-screenshots -k test_examples_screenshots examples

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,14 @@ This code is distributed under the 2-clause BSD license.
115115
## Developers
116116

117117
* Clone the repo.
118-
* Install devtools using `pip install -r dev-requirements.txt` (you can replace
119-
`pip` with `pipenv` to install to a virtualenv).
120-
* Install wgpu-py in editable mode by running `pip install -e .`, this will also
121-
install runtime dependencies as needed.
122-
* Run `python download-wgpu-native.py` to download the upstream wgpu-native
118+
* Install devtools using `pip install -e .[dev]`.
119+
* Using `pip install -e .` will also download the upstream wgpu-native
123120
binaries.
124-
* Or alternatively point the `WGPU_LIB_PATH` environment variable to a custom
125-
build.
121+
* You can use `python tools/download_wgpu_native.py` when needed.
122+
* Or point the `WGPU_LIB_PATH` environment variable to a custom build of `wgpu-native`.
126123
* Use `black .` to apply autoformatting.
127124
* Use `flake8 .` to check for flake errors.
128125
* Use `pytest .` to run the tests.
129-
* Use `pip wheel --no-deps .` to build a wheel.
130126

131127

132128
### Updating to a later version of WebGPU or wgpu-native

codegen/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ The majority of work in the wgpu-native backend is the conversion of Python dic
136136

137137
### The update process
138138

139-
* Download the latest `webgpu.h` and DLL using `python download-wgpu-native.py --version xx`
139+
* Download the latest `webgpu.h` and DLL using `python tools/download_wgpu_native.py --version xx`
140140
* Run `python codegen` to apply the automatic patches to the code.
141141
* It may be necessary to tweak the `hparser.py` to adjust to new formatting.
142142
* Diff the report for new differences to take into account.

dev-requirements.txt

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)