Skip to content

Commit 9f6568a

Browse files
authored
Merge pull request #9 from python-project-templates/tkp/wheels
Setup wheel publishing
2 parents 13bb87e + 473d19d commit 9f6568a

File tree

6 files changed

+89
-28
lines changed

6 files changed

+89
-28
lines changed

.copier-answers.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ email: [email protected]
66
github: python-project-templates
77
project_description: A Rust-Python project template
88
project_name: rust template
9-
python_version_primary: '3.11'
9+
python_version_primary: '3.9'
1010
team: Python Project Template Authors

.github/workflows/build.yml

+37-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: Build Status
32

43
on:
@@ -31,7 +30,7 @@ jobs:
3130
strategy:
3231
matrix:
3332
os: [ubuntu-latest, macos-latest, windows-latest]
34-
python-version: ["3.11"]
33+
python-version: ["3.9"]
3534

3635
steps:
3736
- uses: actions/checkout@v4
@@ -49,12 +48,32 @@ jobs:
4948
toolchain: stable
5049
components: clippy, rustfmt
5150

51+
- name: Setup Rust cache
52+
uses: Swatinem/rust-cache@v2
53+
with:
54+
key: ${{ matrix.os }}
55+
56+
- name: Setup rust targets (MacOS)
57+
run: |
58+
rustup toolchain install stable-x86_64-apple-darwin
59+
rustup target add x86_64-apple-darwin
60+
rustup toolchain install stable-aarch64-apple-darwin
61+
rustup target add aarch64-apple-darwin
62+
if: matrix.os == 'macos-latest'
63+
64+
- name: Setup rust targets (Windows)
65+
run: |
66+
rustup toolchain install stable-x86_64-pc-windows-msvc
67+
rustup target add x86_64-pc-windows-msvc
68+
rustup toolchain install stable-i686-pc-windows-msvc
69+
rustup target add i686-pc-windows-msvc
70+
if: matrix.os == 'windows-latest'
71+
5272
- name: Install dependencies
5373
run: make develop
5474

5575
- name: Lint
5676
run: make lint
57-
if: ${{ matrix.os == 'ubuntu-latest' }}
5877

5978
- name: Checks
6079
run: make checks
@@ -65,7 +84,6 @@ jobs:
6584

6685
- name: Test
6786
run: make coverage
68-
if: ${{ matrix.os == 'ubuntu-latest' }}
6987

7088
- name: Upload test results (Python)
7189
uses: actions/upload-artifact@v4
@@ -85,6 +103,20 @@ jobs:
85103
uses: codecov/codecov-action@v4
86104

87105
- name: Make dist
88-
run: make dist
106+
run: |
107+
make dist-rust
108+
make dist-py-sdist
109+
make dist-py-wheel
110+
make dist-check
89111
if: ${{ matrix.os == 'ubuntu-latest' }}
90112

113+
- name: Make dist
114+
run: |
115+
make dist-py-wheel
116+
make dist-check
117+
if: ${{ matrix.os != 'ubuntu-latest' }}
118+
119+
- uses: actions/upload-artifact@v4
120+
with:
121+
name: dist-${{matrix.os}}
122+
path: dist

Cargo.lock

+12-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ crate-type = ["cdylib"]
1111

1212
[dependencies]
1313
rust_template = { path = "./rust", version = "*" }
14-
pyo3 = { version = "0.22", features = ["abi3-py37", "extension-module", "multiple-pymethods"] }
14+
pyo3 = { version = "0.22", features = ["abi3-py39", "extension-module", "multiple-pymethods"] }
1515
strum = "0.24.1"
1616

1717
[profile.release]

Makefile

+18-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ develop-rust:
1010

1111
develop: develop-rust develop-py ## setup project for development
1212

13-
.PHONY: build-py build-rust build
13+
.PHONY: build-py build-rust build dev
1414
build-py:
1515
maturin build
1616

@@ -41,10 +41,11 @@ lint-py: ## run python linter with ruff
4141
python -m ruff check rust_template
4242
python -m ruff format --check rust_template
4343

44-
lint-rust: ## run the rust linter
44+
lint-rust: ## run rust linter
4545
make -C rust lint
4646

4747
lint: lint-rust lint-py ## run project linters
48+
4849
# alias
4950
lints: lint
5051

@@ -57,6 +58,7 @@ fix-rust: ## fix rust formatting
5758
make -C rust fix
5859

5960
fix: fix-rust fix-py ## run project autoformatters
61+
6062
# alias
6163
format: fix
6264

@@ -79,26 +81,30 @@ annotate: ## run python type annotation checks with mypy
7981
#########
8082
# TESTS #
8183
#########
82-
.PHONY: test test-py coverage-py tests
83-
84+
.PHONY: test-py tests-py coverage-py
8485
test-py: ## run python tests
8586
python -m pytest -v rust_template/tests --junitxml=junit.xml
87+
8688
# alias
8789
tests-py: test-py
8890

8991
coverage-py: ## run python tests and collect test coverage
9092
python -m pytest -v rust_template/tests --junitxml=junit.xml --cov=rust_template --cov-branch --cov-fail-under=50 --cov-report term-missing --cov-report xml
9193

94+
.PHONY: test-rust tests-rust coverage-rust
9295
test-rust: ## run rust tests
9396
make -C rust test
97+
9498
# alias
9599
tests-rust: test-rust
96100

97101
coverage-rust: ## run rust tests and collect test coverage
98102
make -C rust coverage
99103

104+
.PHONY: test coverage tests
100105
test: test-py test-rust ## run all tests
101106
coverage: coverage-py coverage-rust ## run all tests and collect test coverage
107+
102108
# alias
103109
tests: test
104110

@@ -122,18 +128,21 @@ major: ## bump a major version
122128
########
123129
# DIST #
124130
########
125-
.PHONY: dist dist-build dist-sdist dist-local-wheel publish
131+
.PHONY: dist-py-wheel dist-py-sdist dist-rust dist-check dist publish
132+
133+
dist-py-wheel: # build python wheel
134+
python -m cibuildwheel --output-dir dist
126135

127-
dist-build-py: # build python dists
128-
python -m build -w -s
136+
dist-py-sdist: # build python sdist
137+
python -m build --sdist -o dist
129138

130-
dist-build-rust: # build rust dists
139+
dist-rust: # build rust dists
131140
make -C rust dist
132141

133142
dist-check: ## run python dist checker with twine
134143
python -m twine check dist/*
135144

136-
dist: clean build dist-build-rust dist-build-py dist-check ## build all dists
145+
dist: clean build dist-rust dist-py-wheel dist-py-sdist dist-check ## build all dists
137146

138147
publish: dist # publish python assets
139148

pyproject.toml

+20
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ develop = [
3636
"build",
3737
"bump-my-version",
3838
"check-manifest",
39+
"cibuildwheel",
3940
"maturin>=1,<2",
4041
"pytest",
4142
"pytest-cov",
@@ -80,6 +81,25 @@ ignore = [
8081
"rust/README.md",
8182
]
8283

84+
[tool.cibuildwheel]
85+
before-build = "rustup show"
86+
build = "cp39-*"
87+
skip = "*musllinux*"
88+
test-command = "pytest -vvv {project}/rust_template/tests"
89+
test-requires = ["pytest", "pytest-cov", "pytest-sugar", "pytest-xdist"]
90+
91+
[tool.cibuildwheel.linux]
92+
before-build = "curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=stable --profile=minimal -y && rustup show"
93+
environment = {PATH="$HOME/.cargo/bin:$PATH", CARGO_TERM_COLOR="always"}
94+
archs = "x86_64"
95+
96+
[tool.cibuildwheel.macos]
97+
archs = "x86_64 arm64"
98+
99+
[tool.cibuildwheel.windows]
100+
environment = {PATH="$UserProfile\\.cargo\bin;$PATH"}
101+
archs = "AMD64 x86"
102+
83103
[tool.pytest.ini_options]
84104
asyncio_mode = "strict"
85105
testpaths = "rust_template/tests"

0 commit comments

Comments
 (0)