Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions copier.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ add_vcpkg:
help: Add vcpkg dependency management
when: "{{ add_extension in ['cpp', 'cppjswasm'] }}"

add_pyodide:
type: bool
default: false
help: Build and test Pyodide wheels
when: "{{ add_extension in ['cpp', 'rust'] }}"

python_version_primary:
type: str
default: 3.11
Expand Down
1 change: 1 addition & 0 deletions examples/cpp.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
add_docs: true
add_pyodide: false
add_vcpkg: true
add_wiki: true
add_extension: cpp
Expand Down
1 change: 1 addition & 0 deletions examples/rust.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
add_docs: true
add_pyodide: false
add_wiki: true
add_extension: rust
email: 3105306+timkpaine@users.noreply.github.com
Expand Down
33 changes: 33 additions & 0 deletions python/cpp/.github/workflows/build.yaml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,36 @@ jobs:
with:
name: {% raw %}dist-${{ matrix.os }}-${{ matrix.python.version }}{% endraw %}
path: dist

{% if add_pyodide %}
pyodide:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Setup Python
uses: actions-ext/python/setup@6e1b91a408ea89f49bc8aff8724f83826f7b5446
with:
version: "3.14"

- name: Setup C++
uses: actions-ext/cpp/setup@c2b1e90366b3a1c628a1df0748135f5e345ab26f

{% if add_vcpkg -%}
- name: Setup vcpkg cache
uses: actions-ext/cpp/setup-vcpkg-cache@c2b1e90366b3a1c628a1df0748135f5e345ab26f

{% endif -%}
- name: Build and test Pyodide wheel
run: make test-pyodide

- name: Upload Pyodide distribution
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: dist-pyodide
path: dist/pyodide
{% endif %}
3 changes: 3 additions & 0 deletions python/cpp/.gitignore.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ Untitled*.ipynb

# Emscripten SDK (locally installed)
emsdk
{% if add_pyodide -%}
.pyodide_build/
{% endif %}

# Mac
.DS_Store
Expand Down
6 changes: 5 additions & 1 deletion python/cpp/Makefile.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ tests-py: test-py
coverage-py: ## run python tests and collect test coverage
python -m pytest -v {{ module }}/tests --cov={{ module }} --cov-report term-missing --cov-report xml

.PHONY: test coverage tests
.PHONY: test{% if add_pyodide %} test-pyodide{% endif %} coverage tests
test: test-py ## run all tests
{% if add_pyodide %}
test-pyodide: ## build and test the Python package in Pyodide
uvx --from cibuildwheel==4.2.0 cibuildwheel --only cp314-pyodide_wasm32 --output-dir dist/pyodide .
{% endif %}
coverage: coverage-py ## run all tests and collect test coverage

# alias
Expand Down
11 changes: 9 additions & 2 deletions python/cpp/pyproject.toml.jinja
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[build-system]
requires = [
"hatchling",
"hatch-cpp",
"hatch-cpp{% if add_pyodide %}>=0.5.0{% endif %}",
"pybind11",
]
build-backend = "hatchling.build"
Expand Down Expand Up @@ -46,7 +46,7 @@ develop = [
"check-dist",
"cibuildwheel",
"codespell",
"hatch-cpp",
"hatch-cpp{% if add_pyodide %}>=0.5.0{% endif %}",
"hatchling",
"mdformat",
"mdformat-tables>=1",
Expand Down Expand Up @@ -100,6 +100,13 @@ archs = "arm64"
archs = "AMD64"
skip = "*win32 *arm_64"

{% if add_pyodide -%}
[tool.cibuildwheel.pyodide]
test-command = "python -m pytest -vvv --pyargs {{ module }}.tests"
test-extras = []
test-requires = ["pytest"]
{% endif -%}

[tool.coverage.run]
branch = true
omit = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

28 changes: 28 additions & 0 deletions python/rust/.github/workflows/build.yaml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,31 @@ jobs:
with:
name: {% raw %}dist-${{ matrix.os }}{% endraw %}
path: dist

{% if add_pyodide %}
pyodide:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Setup Python
uses: actions-ext/python/setup@6e1b91a408ea89f49bc8aff8724f83826f7b5446
with:
version: "3.14"

- name: Setup Rust
uses: actions-ext/rust/setup@2db8e3e4c56beb7320c7d730bd2c2d6a6447bf6b

- name: Build and test Pyodide wheel
run: make test-pyodide

- name: Upload Pyodide distribution
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: dist-pyodide
path: dist/pyodide
{% endif %}
3 changes: 3 additions & 0 deletions python/rust/.gitignore.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ Untitled*.ipynb

# Emscripten SDK (locally installed)
emsdk
{% if add_pyodide -%}
.pyodide_build/
{% endif %}

# Mac
.DS_Store
Expand Down
7 changes: 6 additions & 1 deletion python/rust/Makefile.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,13 @@ tests-rs: test-rs
coverage-rs: ## run rust tests and collect test coverage
make -C rust coverage

.PHONY: test coverage tests
.PHONY: test{% if add_pyodide %} test-pyodide{% endif %} coverage tests
test: test-py test-rs ## run all tests
{% if add_pyodide %}
test-pyodide: ## build and test the Python package in Pyodide
rustup target add wasm32-unknown-emscripten
uvx --from cibuildwheel==4.2.0 cibuildwheel --only cp314-pyodide_wasm32 --output-dir dist/pyodide .
{% endif %}
coverage: coverage-py coverage-rs ## run all tests and collect test coverage

# alias
Expand Down
12 changes: 10 additions & 2 deletions python/rust/pyproject.toml.jinja
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[build-system]
requires = [
"hatchling",
"hatch-rs>=0.1.4",
"hatch-rs>={% if add_pyodide %}0.3.0{% else %}0.1.4{% endif %}",
]
build-backend = "hatchling.build"

Expand Down Expand Up @@ -46,7 +46,7 @@ develop = [
"check-dist",
"cibuildwheel",
"codespell",
"hatch-rs",
"hatch-rs{% if add_pyodide %}>=0.3.0{% endif %}",
"hatchling",
"mdformat",
"mdformat-tables>=1",
Expand Down Expand Up @@ -118,6 +118,14 @@ archs = "arm64"
environment = {PATH="$UserProfile\\.cargo\bin;$PATH", CARGO_TERM_COLOR="always"}
skip = "*win32 *arm_64"

{% if add_pyodide -%}
[tool.cibuildwheel.pyodide]
test-command = "python -m pytest -vvv --pyargs {{ module }}.tests"
test-extras = []
test-requires = ["pytest"]
xbuild-tools = ["cargo", "rustc", "rustup"]
{% endif -%}

[tool.coverage.run]
branch = true
omit = [
Expand Down
4 changes: 2 additions & 2 deletions python/rust/{{module}}/tests/test_all.py.jinja
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from {{ module }} import *
from {{ module }}{% if add_pyodide %}.{{ module }} import Example{% else %} import *{% endif %}


def test_all():
assert True
assert {% if add_pyodide %}str(Example("test")) == "test"{% else %}True{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading