Repository navigation
340 lines (305 loc) · 12.5 KB
/
Copy pathpython-package.yml
File metadata and controls
340 lines (305 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
name: Python Package
# Builds the naja-schematic wheels/sdist (Python backend + the WASM viewer
# bundle, and in the platform wheels the headless SVG renderer), tests them
# against published najaeda, and on a `v<version>` tag publishes them to
# PyPI.
#
# Wheels: one per platform carrying bin/naja-schematic-render (Linux
# x86_64 and aarch64 manylinux, macOS universal2, Windows x64), plus a pure
# py3-none-any one for every other platform (everything but export_svg()).
# See python/hatch_build.py. Each platform wheel is built on its own runner,
# in parallel, and tested on that platform by the `test` job.
#
# Publishing uses PyPI trusted publishing (no token): the PyPI project must
# list this repository, this workflow file and the `pypi` environment as a
# trusted publisher.
#
# The `colab` job guards the README's Open-in-Colab badge (see below); the
# weekly run catches it breaking without a push here (a new najaeda or
# anywidget, naja's tutorial benchmarks moving).
on:
push:
branches: [ main ]
tags: [ "v*" ]
pull_request:
branches: [ main ]
schedule:
- cron: "0 6 * * 1"
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
# imgui for the build, naja only for its version header
# (CMakeLists.txt reads NajaVersion.h.in); not recursive.
submodules: true
- name: Set up Emscripten
uses: emscripten-core/setup-emsdk@v16
with:
version: latest
- name: Build the viewer bundle
run: |
emcmake cmake -S . -B build-wasm-module \
-DCMAKE_BUILD_TYPE=Release \
-DNAJA_SCHEMATIC_WASM_MODULE=ON
cmake --build build-wasm-module -j
cp build-wasm-module/naja-schematic.js python/naja_schematic/static/
cp LICENSE python/LICENSE
- name: Check the tag matches the package version
if: startsWith(github.ref, 'refs/tags/v')
run: |
version=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' python/naja_schematic/__init__.py)
test "v$version" = "${GITHUB_REF_NAME}" || {
echo "Tag ${GITHUB_REF_NAME} does not match __version__ $version"; exit 1; }
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Build wheel and sdist
run: |
python -m pip install build
python -m build python --outdir dist
- name: Check the bundle is in both archives, and no renderer
run: |
python -m zipfile -l dist/*.whl | grep -q 'naja_schematic/static/naja-schematic.js'
tar tzf dist/*.tar.gz | grep -q 'naja_schematic/static/naja-schematic.js'
ls dist/*-py3-none-any.whl
! unzip -l dist/*.whl | grep -q 'naja_schematic/bin/'
- uses: actions/upload-artifact@v6
with:
name: dist-pure
path: dist/
- uses: actions/upload-artifact@v6
with:
name: bundle
path: python/naja_schematic/static/naja-schematic.js
platform-wheels:
# The headless SVG renderer (no naja, SDL or GL: imgui and a C++
# compiler only) in a wheel per platform.
needs: build
runs-on: ${{ matrix.os }}
container: ${{ matrix.container }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
container: quay.io/pypa/manylinux_2_28_x86_64
platform: manylinux_2_28_x86_64
- os: ubuntu-24.04-arm
container: quay.io/pypa/manylinux_2_28_aarch64
platform: manylinux_2_28_aarch64
- os: macos-latest
container: ""
platform: macosx_11_0_universal2
- os: windows-latest
container: ""
platform: win_amd64
env:
MACOSX_DEPLOYMENT_TARGET: "11.0"
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Fetch the submodules the renderer needs
shell: bash
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git submodule update --init --depth 1 thirdparty/imgui thirdparty/ImGuiColorTextEdit
- name: Set up the build tools (manylinux)
if: matrix.container != ''
run: |
/opt/python/cp312-cp312/bin/python -m pip install cmake ninja build
echo "/opt/python/cp312-cp312/bin" >> "$GITHUB_PATH"
- uses: actions/setup-python@v6
if: matrix.container == ''
with:
python-version: "3.12"
- name: Set up the build tools (macOS, Windows)
if: matrix.container == ''
run: python -m pip install cmake ninja build
- name: Set up MSVC (Windows)
# What vcvarsall.bat x64 sets (cl, link, dumpbin, INCLUDE, LIB...),
# kept for the next steps. Inline: no action doing it runs on
# Node.js 24 yet.
if: runner.os == 'Windows'
shell: pwsh
run: |
$vs = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" `
-latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
-property installationPath
if (-not $vs) { throw "no Visual Studio with the C++ x64 tools" }
$vcvars = Join-Path $vs "VC\Auxiliary\Build\vcvarsall.bat"
# Only what it adds or changes.
cmd /c "`"$vcvars`" x64 >nul && set" | ForEach-Object {
if ($_ -match '^([^=]+)=(.*)$' -and
[Environment]::GetEnvironmentVariable($Matches[1]) -ne $Matches[2]) {
"$($Matches[1])=$($Matches[2])" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
}
}
- uses: actions/download-artifact@v7
with:
name: bundle
path: python/naja_schematic/static/
- name: Build naja-schematic-render
shell: bash
run: |
extra=()
if [ "$RUNNER_OS" = macOS ]; then
extra=(-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64")
fi
cmake -S . -B build-render -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DNAJA_SCHEMATIC_RENDER_ONLY=ON "${extra[@]}"
cmake --build build-render
exe=naja-schematic-render
if [ "$RUNNER_OS" = Windows ]; then exe=naja-schematic-render.exe; fi
mkdir -p python/naja_schematic/bin
cp "build-render/$exe" python/naja_schematic/bin/
python/naja_schematic/bin/$exe --version
case "$RUNNER_OS" in
macOS)
lipo -info python/naja_schematic/bin/$exe
otool -L python/naja_schematic/bin/$exe ;;
Windows)
# Static CRT: only system DLLs (KERNEL32 & co), no VCRUNTIME/MSVCP.
dumpbin //dependents python/naja_schematic/bin/$exe
! dumpbin //dependents python/naja_schematic/bin/$exe | grep -qiE 'vcruntime|msvcp' ;;
*)
ldd python/naja_schematic/bin/$exe ;;
esac
cp LICENSE python/LICENSE
- name: Build the platform wheel
shell: bash
env:
NAJA_SCHEMATIC_WHEEL_PLATFORM: ${{ matrix.platform }}
run: |
python -m build python --wheel --outdir dist
ls dist/*-py3-none-${{ matrix.platform }}.whl
python -m zipfile -l dist/*.whl | grep -q 'naja_schematic/bin/naja-schematic-render'
python -m zipfile -l dist/*.whl | grep -q 'naja_schematic/static/naja-schematic.js'
- uses: actions/upload-artifact@v6
with:
name: dist-${{ matrix.platform }}
path: dist/
test:
needs: [ build, platform-wheels ]
runs-on: ${{ matrix.os }}
# A request that errors leaves some tests waiting for a reply: fail, don't hang.
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
# One runner per platform wheel: each tests the wheel built for it.
os: [ ubuntu-24.04, ubuntu-24.04-arm, macos-latest, windows-latest ]
python-version: [ "3.10", "3.13" ]
# Oldest najaeda the package declares support for, and the newest.
najaeda: [ "==0.7.35", "" ]
steps:
- name: Checkout code
uses: actions/checkout@v5
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- uses: actions/download-artifact@v7
with:
pattern: dist-*
merge-multiple: true
path: dist/
- name: Install the built wheel
# The wheel pip picks for this platform, from the built ones only
# (PyPI may hold the same version): the one with the renderer.
shell: bash
run: |
python -m pip install --no-index --find-links dist --no-deps naja-schematic
python -m pip install "naja-schematic[test]" "najaeda${{ matrix.najaeda }}"
python -c "from naja_schematic import render; print(render.renderer_path())"
- name: Run tests against the installed package
# From outside python/, so the tests import the installed wheel
# rather than the source tree. No display: the SVG export must not
# need one (and fails here rather than skipping without a renderer).
working-directory: ${{ runner.temp }}
env:
NAJA_SCHEMATIC_REQUIRE_RENDER: "1"
DISPLAY: ""
run: python -m pytest -v ${{ github.workspace }}/python/tests
- name: Smoke-test the CLI
shell: bash
run: |
echo '{"request":"load_root"}' \
| naja-schematic --xilinx --verilog python/tests/data/design.v --stdio \
| grep -q '"root_response"'
- name: Smoke-test SVG export, with primitives defined in Python
shell: bash
env:
DISPLAY: ""
working-directory: python/tests/data
run: |
naja-schematic render --verilog py_design.v --py-primitives py_prims.py \
--trace u_ff:D --instance u_ff --svg "$RUNNER_TEMP/cone.svg"
grep -q '<svg' "$RUNNER_TEMP/cone.svg"
grep -q '>u_and2<' "$RUNNER_TEMP/cone.svg"
# Any unresolved target: non-zero, nothing written.
! naja-schematic render --verilog py_design.v --py-primitives py_prims.py \
--trace u_ff:D --net nope:A --svg "$RUNNER_TEMP/bad.svg"
test ! -e "$RUNNER_TEMP/bad.svg"
publish:
needs: [ build, platform-wheels, test ]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-24.04
environment: pypi
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v7
with:
pattern: dist-*
merge-multiple: true
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
colab:
# What the Open-in-Colab badge gives a user: the notebook on this branch,
# run as Colab runs it -- nothing preinstalled, its own
# `%pip install -U naja-schematic` fetching the release from PyPI. On a
# tag it runs after publishing and must get the version just released;
# otherwise it uses the current release, so a notebook edit that needs
# an unreleased API fails here rather than in Colab.
needs: publish
if: >-
!cancelled() && (needs.publish.result == 'success' ||
(needs.publish.result == 'skipped' && !startsWith(github.ref, 'refs/tags/v')))
runs-on: ubuntu-24.04
env:
PIP_NO_CACHE_DIR: "1"
steps:
- name: Checkout code
uses: actions/checkout@v5
- uses: actions/setup-python@v6
with:
# Colab's runtime Python.
python-version: "3.12"
- name: Install the notebook runner only
run: python -m pip install pytest nbformat nbclient ipykernel
- name: Pick the release to expect
shell: bash
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
version=${GITHUB_REF_NAME#v}
# A fresh upload takes a moment to show up on the index.
for i in $(seq 30); do
pip download -q --no-deps -d "$RUNNER_TEMP/dl" \
"naja-schematic==$version" && break
[ "$i" = 30 ] && { echo "naja-schematic $version not on PyPI"; exit 1; }
sleep 20
done
else
version=latest
fi
echo "NAJA_SCHEMATIC_COLAB_CHECK=$version" >> "$GITHUB_ENV"
- name: Run the Colab notebook against PyPI
# From outside python/ and without conftest.py (which imports
# najaeda): the notebook installs everything itself.
working-directory: ${{ runner.temp }}
run: >-
python -m pytest -v --noconftest
${{ github.workspace }}/python/tests/test_notebook.py