Skip to content
Closed
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 .cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"_commit": "f46d0e9611ca496d3600e43343a01dcfb86caee6",
"_commit": "c6577daf23a9972a456f2331e679b07c049a264a",
"_template": "C:\\Users\\56kyl\\source\\repos\\cookiecutter-robust-python",
"add_rust_extension": true,
"author": "Kyle Oliver",
Expand Down
4 changes: 2 additions & 2 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "C:\\Users\\56kyl\\source\\repos\\cookiecutter-robust-python",
"commit": "f46d0e9611ca496d3600e43343a01dcfb86caee6",
"commit": "c6577daf23a9972a456f2331e679b07c049a264a",
"checkout": null,
"context": {
"cookiecutter": {
Expand All @@ -20,7 +20,7 @@
"license": "MIT",
"development_status": "Development Status :: 1 - Planning",
"_template": "C:\\Users\\56kyl\\source\\repos\\cookiecutter-robust-python",
"_commit": "f46d0e9611ca496d3600e43343a01dcfb86caee6"
"_commit": "c6577daf23a9972a456f2331e679b07c049a264a"
}
},
"directory": null
Expand Down
93 changes: 93 additions & 0 deletions .github/workflows/build-rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Build Rust Crates

on:
pull_request:
paths:
- "rust/**/*.rs"
- "rust/Cargo.toml"
- "rust/Cargo.lock"
- "noxfile.py"
- ".github/workflows/build-rust.yml"
push:
branches:
- main
- master
paths:
- "rust/**/*.rs"
- "rust/Cargo.toml"
- "rust/Cargo.lock"
- "noxfile.py"
- ".github/workflows/build-rust.yml"

workflow_dispatch:

jobs:
build-rust:
name: Build Rust Crates
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
- runner: ubuntu-latest
target: x86_64-unknown-linux-musl
- runner: ubuntu-latest
target: aarch64-unknown-linux-gnu
- runner: ubuntu-latest
target: aarch64-unknown-linux-musl
- runner: macos-latest
target: x86_64-apple-darwin
- runner: macos-latest
target: aarch64-apple-darwin
- runner: windows-latest
target: x86_64-pc-windows-msvc
- runner: windows-latest
target: i686-pc-windows-msvc

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform.target }}

- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: "rust/"
key: ${{ matrix.platform.target }}

- name: Set up cross-compilation toolchain (Linux)
if: contains(matrix.platform.target, 'linux')
run: |
sudo apt-get update
sudo apt-get install -y gcc-multilib
if [[ "${{ matrix.platform.target }}" == *"aarch64"* ]]; then
sudo apt-get install -y gcc-aarch64-linux-gnu
fi
if [[ "${{ matrix.platform.target }}" == *"musl"* ]]; then
sudo apt-get install -y musl-tools
fi

- name: Set up uv
uses: astral-sh/setup-uv@v6

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: ".github/workflows/.python-version"

- name: Build Rust crates for target
run: |
cd rust
cargo build --release --target ${{ matrix.platform.target }}

- name: Upload Rust build artifacts
uses: actions/upload-artifact@v4
with:
name: rust-artifacts-${{ matrix.platform.target }}
path: rust/target/${{ matrix.platform.target }}/release/
retention-days: 7
53 changes: 53 additions & 0 deletions .github/workflows/lint-rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Lint Rust Code

on:
pull_request:
paths:
- "rust/**/*.rs"
- "Cargo.toml"
- "noxfile.py"
- ".github/workflows/lint-rust.yml"
push:
branches:
- main
- master
paths:
- "rust/**/*.rs"
- "Cargo.toml"
- "noxfile.py"
- ".github/workflows/lint-rust.yml"

workflow_dispatch:

jobs:
lint-rust:
name: Run Rust Linting Checks
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
components: "rustfmt,clippy"

- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: "rust/"

- name: Set up uv
uses: astral-sh/setup-uv@v6

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: ".github/workflows/.python-version"

- name: Run Rust format check
run: uvx nox -s format-rust

- name: Run Rust lint check
run: uvx nox -s lint-rust
54 changes: 54 additions & 0 deletions .github/workflows/test-rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Test Rust Code

on:
pull_request:
paths:
- "rust/**/*.rs"
- "Cargo.toml"
- "noxfile.py"
- ".github/workflows/test-rust.yml"
push:
branches:
- main
- master
paths:
- "rust/**/*.rs"
- "Cargo.toml"
- "noxfile.py"
- ".github/workflows/test-rust.yml"

workflow_dispatch:

jobs:
test-rust:
name: Run Rust Tests on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- { os: "ubuntu-latest" }
- { os: "macos-latest" }
- { os: "windows-latest" }

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Rust
run: rustup show

- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: "rust/"

- name: Set up uv
uses: astral-sh/setup-uv@v6

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: ".github/workflows/.python-version"

- name: Run Rust tests
run: uvx nox -s test-rust
68 changes: 58 additions & 10 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,10 @@
TEST: str = "test"
COVERAGE: str = "coverage"
SECURITY: str = "security"
PERF: str = "perf"
DOCS: str = "docs"
BUILD: str = "build"
RELEASE: str = "release"
QUALITY: str = "quality"
PYTHON: str = "python"
RUST: str = "rust"


@nox.session(python=False, name="setup-git", tags=[ENV])
Expand Down Expand Up @@ -88,21 +85,39 @@ def precommit(session: Session) -> None:
activate_virtualenv_in_precommit_hooks(session)


@nox.session(python=False, name="format-python", tags=[FORMAT, PYTHON, QUALITY])
@nox.session(python=False, name="format-python", tags=[FORMAT, QUALITY])
def format_python(session: Session) -> None:
"""Run Python code formatter (Ruff format)."""
session.log(f"Running Ruff formatter check with py{session.python}.")
session.run("uvx", "ruff", "format", *session.posargs)


@nox.session(python=False, name="lint-python", tags=[LINT, PYTHON, QUALITY])
@nox.session(python=False, name="format-rust", tags=[FORMAT])
def format_rust(session: Session) -> None:
"""Run Rust code formatter (cargo fmt)."""
session.log("Ensuring rustfmt component is available...")
session.run("rustup", "component", "add", "rustfmt", external=True)
session.log("Formatting Rust code...")
session.run("cargo", "fmt", "--all", external=True)


@nox.session(python=False, name="lint-python", tags=[LINT, QUALITY])
def lint_python(session: Session) -> None:
"""Run Python code linters (Ruff check, Pydocstyle rules)."""
session.log(f"Running Ruff check with py{session.python}.")
session.run("uvx", "ruff", "check", "--fix", "--verbose")


@nox.session(python=PYTHON_VERSIONS, name="typecheck", tags=[TYPE, PYTHON])
@nox.session(python=False, name="lint-rust", tags=[LINT, QUALITY])
def lint_rust(session: Session) -> None:
"""Run Rust code linters (cargo clippy)."""
session.log("Ensuring clippy component is available...")
session.run("rustup", "component", "add", "clippy", external=True)
session.log("Running clippy lints...")
session.run("cargo", "clippy", "--all-features", "--", "-D", "warnings", external=True)


@nox.session(python=PYTHON_VERSIONS, name="typecheck")
def typecheck(session: Session) -> None:
"""Run static type checking (Pyright) on Python code."""
session.log("Installing type checking dependencies...")
Expand All @@ -112,7 +127,7 @@ def typecheck(session: Session) -> None:
session.run("pyright", "--pythonversion", session.python)


@nox.session(python=False, name="security-python", tags=[SECURITY, PYTHON])
@nox.session(python=False, name="security-python", tags=[SECURITY])
def security_python(session: Session) -> None:
"""Run code security checks (Bandit) on Python code."""
session.log(f"Running Bandit static security analysis with py{session.python}.")
Expand All @@ -122,7 +137,15 @@ def security_python(session: Session) -> None:
session.run("uvx", "pip-audit")


@nox.session(python=PYTHON_VERSIONS, name="tests-python", tags=[TEST, PYTHON])
@nox.session(python=False, name="security-rust", tags=[SECURITY])
def security_rust(session: Session) -> None:
"""Run code security checks (cargo audit)."""
session.log("Ensuring cargo-audit is available...")
session.run("cargo", "install", "cargo-audit", "--locked", external=True)
session.run("cargo", "audit", "--all", external=True)


@nox.session(python=PYTHON_VERSIONS, name="tests-python", tags=[TEST])
def tests_python(session: Session) -> None:
"""Run the Python test suite (pytest with coverage)."""
session.log("Installing test dependencies...")
Expand All @@ -144,6 +167,15 @@ def tests_python(session: Session) -> None:
)


@nox.session(python=False, name="tests-rust", tags=[TEST])
def tests_rust(session: Session) -> None:
"""Test the project's rust crates."""
crates: list[Path] = [cargo_toml.parent for cargo_toml in CRATES_FOLDER.glob("*/Cargo.toml")]
crate_kwargs: list[str] = [f"-p {crate.name}" for crate in crates]
session.run("cargo", "test", "--all-features", "--no-run", *crate_kwargs, external=True)
session.run("cargo", "test", "--all-features", *crate_kwargs, external=True)


@nox.session(python=DEFAULT_PYTHON_VERSION, name="build-docs", tags=[DOCS, BUILD])
def docs_build(session: Session) -> None:
"""Build the project documentation (Sphinx)."""
Expand All @@ -160,16 +192,23 @@ def docs_build(session: Session) -> None:
session.run("sphinx-build", "-b", "html", "docs", str(docs_build_dir), "-W")


@nox.session(python=False, name="build-python", tags=[BUILD, PYTHON])
@nox.session(python=False, name="build-python", tags=[BUILD])
def build_python(session: Session) -> None:
"""Build sdist and wheel packages (uv build)."""
session.log(f"Building sdist and wheel packages with py{session.python}.")
session.run("uv", "build", "--sdist", "--wheel", "--out-dir", "dist/", external=True)
session.run("maturin", "develop", "--uv")
session.log("Built packages in ./dist directory:")
for path in Path("dist/").glob("*"):
session.log(f"- {path.name}")


@nox.session(python=False, name="build-rust", tags=[BUILD])
def build_rust(session: Session) -> None:
"""Build standalone Rust crates for potential independent publishing."""
session.log("Building Rust crates...")
session.run("cargo", "build", "--release", "--manifest-path", "rust/Cargo.toml", external=True)


@nox.session(python=False, name="build-container", tags=[BUILD])
def build_container(session: Session) -> None:
"""Build the Docker container image.
Expand Down Expand Up @@ -241,6 +280,15 @@ def publish_python(session: Session) -> None:
session.run("uv", "publish", "dist/*", *session.posargs, external=True)


@nox.session(python=False, name="publish-rust", tags=[RELEASE])
def publish_rust(session: Session) -> None:
"""Publish built crates to crates.io."""
session.log("Publishing crates to crates.io")
for cargo_toml in CRATES_FOLDER.glob("*/Cargo.toml"):
crate_folder: Path = cargo_toml.parent
session.run("cargo", "publish", "-p", crate_folder.name)


@nox.session(python=False)
def tox(session: Session) -> None:
"""Run the 'tox' test matrix.
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,8 @@ publish-url = "https://test.pypi.org/legacy/"
explicit = true

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
requires = ["maturin>=1.9.0,<2.0"]
build-backend = "maturin"

[tool.maturin]
rust-src = "rust"
Loading
Loading