Skip to content

Commit 512e093

Browse files
committed
chore: update demo to the latest cookiecutter-robust-python
1 parent 6c62d2d commit 512e093

File tree

6 files changed

+136
-28
lines changed

6 files changed

+136
-28
lines changed

.cookiecutter.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"_commit": "5d756a871ab41b11e3501fbd7b59297c92371b66",
2+
"_commit": "183e0478a9ef41b408c7e0349c228ab5a837fb9f",
33
"_template": "C:\\Users\\56kyl\\source\\repos\\cookiecutter-robust-python",
44
"add_rust_extension": true,
55
"author": "Kyle Oliver",

.cruft.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"template": "C:\\Users\\56kyl\\source\\repos\\cookiecutter-robust-python",
3-
"commit": "5d756a871ab41b11e3501fbd7b59297c92371b66",
3+
"commit": "183e0478a9ef41b408c7e0349c228ab5a837fb9f",
44
"checkout": null,
55
"context": {
66
"cookiecutter": {
@@ -20,7 +20,7 @@
2020
"license": "MIT",
2121
"development_status": "Development Status :: 1 - Planning",
2222
"_template": "C:\\Users\\56kyl\\source\\repos\\cookiecutter-robust-python",
23-
"_commit": "5d756a871ab41b11e3501fbd7b59297c92371b66"
23+
"_commit": "183e0478a9ef41b408c7e0349c228ab5a837fb9f"
2424
}
2525
},
2626
"directory": null

.github/workflows/build-rust.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Build Rust Crates
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "rust/**/*.rs"
7+
- "rust/Cargo.toml"
8+
- "rust/Cargo.lock"
9+
- "noxfile.py"
10+
- ".github/workflows/build-rust.yml"
11+
push:
12+
branches:
13+
- main
14+
- master
15+
paths:
16+
- "rust/**/*.rs"
17+
- "rust/Cargo.toml"
18+
- "rust/Cargo.lock"
19+
- "noxfile.py"
20+
- ".github/workflows/build-rust.yml"
21+
22+
workflow_dispatch:
23+
24+
jobs:
25+
build-rust:
26+
name: Build Rust Crates
27+
runs-on: ${{ matrix.platform.runner }}
28+
strategy:
29+
matrix:
30+
platform:
31+
- runner: ubuntu-latest
32+
target: x86_64-unknown-linux-gnu
33+
- runner: ubuntu-latest
34+
target: x86_64-unknown-linux-musl
35+
- runner: ubuntu-latest
36+
target: aarch64-unknown-linux-gnu
37+
- runner: ubuntu-latest
38+
target: aarch64-unknown-linux-musl
39+
- runner: macos-latest
40+
target: x86_64-apple-darwin
41+
- runner: macos-latest
42+
target: aarch64-apple-darwin
43+
- runner: windows-latest
44+
target: x86_64-pc-windows-msvc
45+
- runner: windows-latest
46+
target: i686-pc-windows-msvc
47+
48+
steps:
49+
- name: Checkout code
50+
uses: actions/checkout@v4
51+
52+
- name: Set up Rust
53+
uses: dtolnay/rust-toolchain@stable
54+
with:
55+
targets: ${{ matrix.platform.target }}
56+
57+
- name: Cache Rust dependencies
58+
uses: Swatinem/rust-cache@v2
59+
with:
60+
workdir: rust/
61+
key: ${{ matrix.platform.target }}
62+
63+
- name: Set up cross-compilation toolchain (Linux)
64+
if: contains(matrix.platform.target, 'linux')
65+
run: |
66+
sudo apt-get update
67+
sudo apt-get install -y gcc-multilib
68+
if [[ "${{ matrix.platform.target }}" == *"aarch64"* ]]; then
69+
sudo apt-get install -y gcc-aarch64-linux-gnu
70+
fi
71+
if [[ "${{ matrix.platform.target }}" == *"musl"* ]]; then
72+
sudo apt-get install -y musl-tools
73+
fi
74+
75+
- name: Set up uv
76+
uses: astral-sh/setup-uv@v6
77+
78+
- name: Set up Python
79+
uses: actions/setup-python@v5
80+
with:
81+
python-version-file: ".github/workflows/.python-version"
82+
83+
- name: Build Rust crates for target
84+
run: |
85+
cd rust
86+
cargo build --release --target ${{ matrix.platform.target }}
87+
88+
- name: Upload Rust build artifacts
89+
uses: actions/upload-artifact@v4
90+
with:
91+
name: rust-artifacts-${{ matrix.platform.target }}
92+
path: rust/target/${{ matrix.platform.target }}/release/
93+
retention-days: 7

.github/workflows/lint-rust.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ jobs:
2929
uses: actions/checkout@v4
3030

3131
- name: Set up Rust
32-
run: |
33-
rustup component add rustfmt clippy
32+
uses: dtolnay/rust-toolchain@stable
33+
with:
34+
components: "rustfmt,clippy"
35+
36+
- name: Cache Rust dependencies
37+
uses: Swatinem/rust-cache@v2
38+
with:
39+
workdir: rust/
3440

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

.github/workflows/test-rust.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ jobs:
3737
- name: Set up Rust
3838
run: rustup show
3939

40+
- name: Cache Rust dependencies
41+
uses: Swatinem/rust-cache@v2
42+
with:
43+
workdir: rust/
44+
4045
- name: Set up uv
4146
uses: astral-sh/setup-uv@v6
4247

noxfile.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,10 @@
3939
TEST: str = "test"
4040
COVERAGE: str = "coverage"
4141
SECURITY: str = "security"
42-
PERF: str = "perf"
4342
DOCS: str = "docs"
4443
BUILD: str = "build"
4544
RELEASE: str = "release"
4645
QUALITY: str = "quality"
47-
PYTHON: str = "python"
48-
RUST: str = "rust"
4946

5047

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

9087

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

9794

98-
@nox.session(python=False, name="format-rust", tags=[FORMAT, RUST])
95+
@nox.session(python=False, name="format-rust", tags=[FORMAT])
9996
def format_rust(session: Session) -> None:
10097
"""Run Rust code formatter (cargo fmt)."""
101-
session.log("Installing formatting dependencies...")
102-
session.run("cargo", "install", "cargo-fmt", external=True)
103-
session.run("cargo", "fmt", "--all", "--", "--check", external=True)
104-
session.run("cargo", "fmt", "--all", "--", "--write", external=True)
98+
session.log("Ensuring rustfmt component is available...")
99+
session.run("rustup", "component", "add", "rustfmt", external=True)
100+
session.log("Formatting Rust code...")
101+
session.run("cargo", "fmt", "--all", external=True)
105102

106103

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

113110

114-
@nox.session(python=False, name="lint-rust", tags=[LINT, RUST])
111+
@nox.session(python=False, name="lint-rust", tags=[LINT, QUALITY])
115112
def lint_rust(session: Session) -> None:
116113
"""Run Rust code linters (cargo clippy)."""
117-
session.log("Installing linting dependencies...")
118-
session.run("cargo", "install", "cargo-clippy", external=True)
119-
session.run("cargo", "clippy", "--all-features", "--", "--check", external=True)
120-
session.run("cargo", "clippy", "--all-features", "--", "--write", external=True)
114+
session.log("Ensuring clippy component is available...")
115+
session.run("rustup", "component", "add", "clippy", external=True)
116+
session.log("Running clippy lints...")
117+
session.run("cargo", "clippy", "--all-features", "--", "-D", "warnings", external=True)
121118

122119

123-
@nox.session(python=PYTHON_VERSIONS, name="typecheck", tags=[TYPE, PYTHON])
120+
@nox.session(python=PYTHON_VERSIONS, name="typecheck")
124121
def typecheck(session: Session) -> None:
125122
"""Run static type checking (Pyright) on Python code."""
126123
session.log("Installing type checking dependencies...")
@@ -130,7 +127,7 @@ def typecheck(session: Session) -> None:
130127
session.run("pyright", "--pythonversion", session.python)
131128

132129

133-
@nox.session(python=False, name="security-python", tags=[SECURITY, PYTHON])
130+
@nox.session(python=False, name="security-python", tags=[SECURITY])
134131
def security_python(session: Session) -> None:
135132
"""Run code security checks (Bandit) on Python code."""
136133
session.log(f"Running Bandit static security analysis with py{session.python}.")
@@ -140,15 +137,15 @@ def security_python(session: Session) -> None:
140137
session.run("uvx", "pip-audit")
141138

142139

143-
@nox.session(python=False, name="security-rust", tags=[SECURITY, RUST])
140+
@nox.session(python=False, name="security-rust", tags=[SECURITY])
144141
def security_rust(session: Session) -> None:
145142
"""Run code security checks (cargo audit)."""
146-
session.log("Installing security dependencies...")
147-
session.run("cargo", "install", "cargo-audit", external=True)
143+
session.log("Ensuring cargo-audit is available...")
144+
session.run("cargo", "install", "cargo-audit", "--locked", external=True)
148145
session.run("cargo", "audit", "--all", external=True)
149146

150147

151-
@nox.session(python=PYTHON_VERSIONS, name="tests-python", tags=[TEST, PYTHON])
148+
@nox.session(python=PYTHON_VERSIONS, name="tests-python", tags=[TEST])
152149
def tests_python(session: Session) -> None:
153150
"""Run the Python test suite (pytest with coverage)."""
154151
session.log("Installing test dependencies...")
@@ -170,7 +167,7 @@ def tests_python(session: Session) -> None:
170167
)
171168

172169

173-
@nox.session(python=False, name="tests-rust", tags=[TEST, RUST, CI])
170+
@nox.session(python=False, name="tests-rust", tags=[TEST])
174171
def tests_rust(session: Session) -> None:
175172
"""Test the project's rust crates."""
176173
crates: list[Path] = [cargo_toml.parent for cargo_toml in CRATES_FOLDER.glob("*/Cargo.toml")]
@@ -195,7 +192,7 @@ def docs_build(session: Session) -> None:
195192
session.run("sphinx-build", "-b", "html", "docs", str(docs_build_dir), "-W")
196193

197194

198-
@nox.session(python=False, name="build-python", tags=[BUILD, PYTHON])
195+
@nox.session(python=False, name="build-python", tags=[BUILD])
199196
def build_python(session: Session) -> None:
200197
"""Build sdist and wheel packages (uv build)."""
201198
session.log(f"Building sdist and wheel packages with py{session.python}.")
@@ -205,6 +202,13 @@ def build_python(session: Session) -> None:
205202
session.log(f"- {path.name}")
206203

207204

205+
@nox.session(python=False, name="build-rust", tags=[BUILD])
206+
def build_rust(session: Session) -> None:
207+
"""Build standalone Rust crates for potential independent publishing."""
208+
session.log("Building Rust crates...")
209+
session.run("cargo", "build", "--release", "--manifest-path", "rust/Cargo.toml", external=True)
210+
211+
208212
@nox.session(python=False, name="build-container", tags=[BUILD])
209213
def build_container(session: Session) -> None:
210214
"""Build the Docker container image.

0 commit comments

Comments
 (0)