Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup wheel publishing #9

Merged
merged 2 commits into from
Oct 11, 2024
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
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ email: [email protected]
github: python-project-templates
project_description: A Rust-Python project template
project_name: rust template
python_version_primary: '3.11'
python_version_primary: '3.9'
team: Python Project Template Authors
42 changes: 37 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: Build Status

on:
Expand Down Expand Up @@ -31,7 +30,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.11"]
python-version: ["3.9"]

steps:
- uses: actions/checkout@v4
Expand All @@ -49,12 +48,32 @@ jobs:
toolchain: stable
components: clippy, rustfmt

- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.os }}

- name: Setup rust targets (MacOS)
run: |
rustup toolchain install stable-x86_64-apple-darwin
rustup target add x86_64-apple-darwin
rustup toolchain install stable-aarch64-apple-darwin
rustup target add aarch64-apple-darwin
if: matrix.os == 'macos-latest'

- name: Setup rust targets (Windows)
run: |
rustup toolchain install stable-x86_64-pc-windows-msvc
rustup target add x86_64-pc-windows-msvc
rustup toolchain install stable-i686-pc-windows-msvc
rustup target add i686-pc-windows-msvc
if: matrix.os == 'windows-latest'

- name: Install dependencies
run: make develop

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

- name: Checks
run: make checks
Expand All @@ -65,7 +84,6 @@ jobs:

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

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

- name: Make dist
run: make dist
run: |
make dist-rust
make dist-py-sdist
make dist-py-wheel
make dist-check
if: ${{ matrix.os == 'ubuntu-latest' }}

- name: Make dist
run: |
make dist-py-wheel
make dist-check
if: ${{ matrix.os != 'ubuntu-latest' }}

- uses: actions/upload-artifact@v4
with:
name: dist-${{matrix.os}}
path: dist
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ crate-type = ["cdylib"]

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

[profile.release]
Expand Down
27 changes: 18 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ develop-rust:

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

.PHONY: build-py build-rust build
.PHONY: build-py build-rust build dev
build-py:
maturin build

Expand Down Expand Up @@ -41,10 +41,11 @@ lint-py: ## run python linter with ruff
python -m ruff check rust_template
python -m ruff format --check rust_template

lint-rust: ## run the rust linter
lint-rust: ## run rust linter
make -C rust lint

lint: lint-rust lint-py ## run project linters

# alias
lints: lint

Expand All @@ -57,6 +58,7 @@ fix-rust: ## fix rust formatting
make -C rust fix

fix: fix-rust fix-py ## run project autoformatters

# alias
format: fix

Expand All @@ -79,26 +81,30 @@ annotate: ## run python type annotation checks with mypy
#########
# TESTS #
#########
.PHONY: test test-py coverage-py tests

.PHONY: test-py tests-py coverage-py
test-py: ## run python tests
python -m pytest -v rust_template/tests --junitxml=junit.xml

# alias
tests-py: test-py

coverage-py: ## run python tests and collect test coverage
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

.PHONY: test-rust tests-rust coverage-rust
test-rust: ## run rust tests
make -C rust test

# alias
tests-rust: test-rust

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

.PHONY: test coverage tests
test: test-py test-rust ## run all tests
coverage: coverage-py coverage-rust ## run all tests and collect test coverage

# alias
tests: test

Expand All @@ -122,18 +128,21 @@ major: ## bump a major version
########
# DIST #
########
.PHONY: dist dist-build dist-sdist dist-local-wheel publish
.PHONY: dist-py-wheel dist-py-sdist dist-rust dist-check dist publish

dist-py-wheel: # build python wheel
python -m cibuildwheel --output-dir dist

dist-build-py: # build python dists
python -m build -w -s
dist-py-sdist: # build python sdist
python -m build --sdist -o dist

dist-build-rust: # build rust dists
dist-rust: # build rust dists
make -C rust dist

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

dist: clean build dist-build-rust dist-build-py dist-check ## build all dists
dist: clean build dist-rust dist-py-wheel dist-py-sdist dist-check ## build all dists

publish: dist # publish python assets

Expand Down
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ develop = [
"build",
"bump-my-version",
"check-manifest",
"cibuildwheel",
"maturin>=1,<2",
"pytest",
"pytest-cov",
Expand Down Expand Up @@ -80,6 +81,25 @@ ignore = [
"rust/README.md",
]

[tool.cibuildwheel]
before-build = "rustup show"
build = "cp39-*"
skip = "*musllinux*"
test-command = "pytest -vvv {project}/rust_template/tests"
test-requires = ["pytest", "pytest-cov", "pytest-sugar", "pytest-xdist"]

[tool.cibuildwheel.linux]
before-build = "curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=stable --profile=minimal -y && rustup show"
environment = {PATH="$HOME/.cargo/bin:$PATH", CARGO_TERM_COLOR="always"}
archs = "x86_64"

[tool.cibuildwheel.macos]
archs = "x86_64 arm64"

[tool.cibuildwheel.windows]
environment = {PATH="$UserProfile\\.cargo\bin;$PATH"}
archs = "AMD64 x86"

[tool.pytest.ini_options]
asyncio_mode = "strict"
testpaths = "rust_template/tests"
Expand Down
Loading