Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 702aff1

Browse files
committed
ci: Add a build for wasm
This adds a `pyproject.toml` config for it, so you can replicate locally with cibuildwheel.
1 parent 38257d9 commit 702aff1

4 files changed

Lines changed: 104 additions & 21 deletions

File tree

.github/labeler.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
---
22
"CI: Run cibuildwheel":
33
- changed-files:
4-
- any-glob-to-any-file: ['.github/workflows/cibuildwheel.yml']
4+
- any-glob-to-any-file:
5+
- '.github/workflows/cibuildwheel.yml'
6+
- '.github/workflows/wasm.yml'
57
"CI: Run cygwin":
68
- changed-files:
79
- any-glob-to-any-file: ['.github/workflows/cygwin.yml']

.github/workflows/nightlies.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,28 @@ jobs:
3232
run: |
3333
PROJECT_REPO="matplotlib/matplotlib"
3434
BRANCH="main"
35-
WORKFLOW_NAME="cibuildwheel.yml"
3635
ARTIFACT_PATTERN="cibw-wheels-*"
3736
38-
gh run --repo "${PROJECT_REPO}" \
39-
list --branch "${BRANCH}" \
40-
--workflow "${WORKFLOW_NAME}" \
41-
--json event,status,conclusion,databaseId > runs.json
42-
RUN_ID=$(
43-
jq --compact-output \
44-
'[
45-
.[] |
46-
# Filter on "push" events to main (merged PRs) ...
47-
select(.event == "push") |
48-
# that have completed successfully ...
49-
select(.status == "completed" and .conclusion == "success")
50-
] |
51-
# and get ID of latest build of wheels.
52-
sort_by(.databaseId) | reverse | .[0].databaseId' runs.json
53-
)
54-
gh run --repo "${PROJECT_REPO}" view "${RUN_ID}"
55-
gh run --repo "${PROJECT_REPO}" \
56-
download "${RUN_ID}" --pattern "${ARTIFACT_PATTERN}"
37+
for WORKFLOW_NAME in cibuildwheel.yml wasm.yml; do
38+
gh run --repo "${PROJECT_REPO}" \
39+
list --branch "${BRANCH}" \
40+
--workflow "${WORKFLOW_NAME}" \
41+
--json event,status,conclusion,databaseId > runs.json
42+
RUN_ID=$(
43+
jq --compact-output \
44+
'[
45+
.[] |
46+
# Filter on "push" events to main (merged PRs) ...
47+
select(.event == "push") |
48+
# that have completed successfully ...
49+
select(.status == "completed" and .conclusion == "success")
50+
] |
51+
# and get ID of latest build of wheels.
52+
sort_by(.databaseId) | reverse | .[0].databaseId' runs.json
53+
)
54+
gh run --repo "${PROJECT_REPO}" view "${RUN_ID}"
55+
gh run --repo "${PROJECT_REPO}" download "${RUN_ID}" --pattern "${ARTIFACT_PATTERN}"
56+
done
5757
5858
mkdir dist
5959
mv ${ARTIFACT_PATTERN}/*.whl dist/

.github/workflows/wasm.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
name: Build wasm wheels
3+
4+
on:
5+
# Save CI by only running this on release branches or tags.
6+
push:
7+
branches:
8+
- main
9+
- v[0-9]+.[0-9]+.x
10+
tags:
11+
- v*
12+
# Also allow running this action on PRs if requested by applying the
13+
# "Run cibuildwheel" label.
14+
pull_request:
15+
types:
16+
- opened
17+
- synchronize
18+
- reopened
19+
- labeled
20+
21+
permissions:
22+
contents: read
23+
24+
jobs:
25+
build_wasm:
26+
if: >-
27+
(
28+
github.event_name == 'push' ||
29+
github.event_name == 'pull_request' && (
30+
(
31+
github.event.action == 'labeled' &&
32+
github.event.label.name == 'CI: Run cibuildwheel'
33+
) ||
34+
contains(github.event.pull_request.labels.*.name,
35+
'CI: Run cibuildwheel')
36+
)
37+
)
38+
name: Build wasm
39+
runs-on: ubuntu-24.04
40+
41+
steps:
42+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
43+
with:
44+
fetch-depth: 0
45+
persist-credentials: false
46+
47+
- uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
48+
name: Install Python
49+
with:
50+
python-version: '3.13'
51+
52+
- name: Build wheels for wasm
53+
uses: pypa/cibuildwheel@ee02a1537ce3071a004a6b08c41e72f0fdc42d9a # v3.4.0
54+
env:
55+
CIBW_PLATFORM: "pyodide"
56+
57+
- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
58+
with:
59+
name: cibw-wheels-wasm
60+
path: ./wheelhouse/*.whl
61+
if-no-files-found: error

pyproject.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,23 @@ testpaths = ["lib"]
322322
addopts = [
323323
"--import-mode=importlib",
324324
]
325+
326+
[tool.cibuildwheel.pyodide]
327+
test-requires = "pytest"
328+
test-command = [
329+
# Wheels are built without test images, so copy them into the testing directory.
330+
"basedir=$(python -c 'import pathlib, matplotlib; print(pathlib.Path(matplotlib.__file__).parent.parent)')",
331+
"cp -a {package}/lib/matplotlib/tests/data $basedir/matplotlib/tests/",
332+
"""
333+
for subdir in matplotlib mpl_toolkits/axes_grid1 mpl_toolkits/axisartist mpl_toolkits/mplot3d; do
334+
cp -a {package}/lib/${subdir}/tests/baseline_images $basedir/${subdir}/tests/
335+
done""",
336+
# Test installed, not repository, copy as we aren't using an editable install.
337+
"pytest -p no:cacheprovider --pyargs matplotlib mpl_toolkits.axes_grid1 mpl_toolkits.axisartist mpl_toolkits.mplot3d",
338+
]
339+
[tool.cibuildwheel.pyodide.environment]
340+
# Exceptions are needed for pybind11:
341+
# https://github.com/pybind/pybind11/pull/5298
342+
CFLAGS = "-fexceptions"
343+
CXXFLAGS = "-fexceptions"
344+
LDFLAGS = "-fexceptions"

0 commit comments

Comments
 (0)