Skip to content

Commit ca24236

Browse files
authored
Merge pull request #5 from cjermain/20250204_update
2025-02-04 Update
2 parents 9ec11bf + 314b60a commit ca24236

File tree

8 files changed

+264
-30
lines changed

8 files changed

+264
-30
lines changed

.github/workflows/CI.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ jobs:
1212
os: ["ubuntu"]
1313
runs-on: ${{ matrix.os }}-latest
1414
steps:
15-
- uses: actions/checkout@v2
16-
- uses: actions/setup-python@v2
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-python@v5
1717
with:
18-
python-version: "3.10"
19-
cache: "pip"
18+
python-version: "3.12"
19+
- name: Install uv
20+
uses: astral-sh/setup-uv@v5
21+
with:
22+
enable-cache: true
2023
- uses: actions-rs/toolchain@v1
2124
with:
2225
toolchain: stable
@@ -25,27 +28,24 @@ jobs:
2528
components: llvm-tools-preview
2629
- name: Install cargo-llvm-cov
2730
uses: taiki-e/install-action@cargo-llvm-cov
28-
- uses: Swatinem/rust-cache@v1
31+
- uses: Swatinem/rust-cache@v2
2932
with:
3033
key: coverage-cargo-${{ matrix.os }}
3134
continue-on-error: true
3235
- name: Setup virtual environment
3336
run: |
34-
python -m venv venv
35-
source venv/bin/activate
36-
pip install -r requirements.txt
37+
uv sync
3738
- name: Run coverage
3839
run: |
39-
source venv/bin/activate
4040
source <(cargo llvm-cov show-env --export-prefix)
4141
export CARGO_TARGET_DIR=$CARGO_LLVM_COV_TARGET_DIR
4242
export CARGO_INCREMENTAL=1
4343
cargo llvm-cov clean --workspace
4444
cargo test
45-
maturin develop
46-
pytest tests --cov=foobar --cov-report xml
47-
cargo llvm-cov --no-run --lcov --output-path coverage.lcov
48-
- uses: codecov/codecov-action@v3
45+
uv run -- maturin develop --uv
46+
uv run -- pytest tests --cov=foobar --cov-report xml
47+
cargo llvm-cov report --lcov --output-path coverage.lcov
48+
- uses: codecov/codecov-action@v5
4949
with:
5050
files: coverage.lcov,coverage.xml
5151
name: ${{ matrix.os }}

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name = "foobar"
99
crate-type = ["cdylib"]
1010

1111
[dependencies]
12-
pyo3 = { version = "0.16.1", features = ["extension-module"] }
12+
pyo3 = { version = "0.23.3", features = ["extension-module"] }
1313

1414
[package.metadata.maturin]
1515
python-source = "python"

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ system. This installs `pytest`, which is able to measure the coverage of the
4848
Python only sections and also exercise the PyO3 bound Rust code.
4949

5050
```
51-
python3 -m venv venv
52-
source venv/bin/activate
53-
pip install -r requirements.txt
51+
uv sync
5452
```
5553

5654
The Rust tests use `cargo test`. To measure the full Rust coverage from Python
@@ -86,9 +84,9 @@ measurements.
8684
```
8785
cargo llvm-cov clean --workspace
8886
cargo test
89-
maturin develop
90-
pytest tests --cov=foobar --cov-report xml
91-
cargo llvm-cov --no-run --lcov --output-path coverage.lcov
87+
uv run -- maturin develop --uv
88+
uv run -- pytest tests --cov=foobar --cov-report xml
89+
cargo llvm-cov report --lcov --output-path coverage.lcov
9290
```
9391

9492
First the `cargo llvm-cov clean` command removes any previous profiling

pyproject.toml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
[build-system]
2-
requires = ["maturin>=0.12,<0.13"]
3-
build-backend = "maturin"
4-
51
[project]
62
name = "foobar"
7-
requires-python = ">=3.6"
3+
version = "0.1.1"
4+
requires-python = ">=3.9"
85
classifiers = [
96
"Programming Language :: Rust",
107
"Programming Language :: Python :: Implementation :: CPython",
118
"Programming Language :: Python :: Implementation :: PyPy",
129
]
10+
dependencies = [
11+
"pytest>=8.3.4",
12+
"pytest-cov>=6.0.0",
13+
"maturin>=1.8.1",
14+
]
15+
16+
[build-system]
17+
requires = ["maturin>=1.0,<2.0"]
18+
build-backend = "maturin"
1319

20+
[tool.maturin]
21+
python-source = "python"
22+
module-name = "foobar._foobar"

python/foobar/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .foobar import pyo3_sum
1+
from ._foobar import pyo3_sum
22

33
def py_sum(a, b):
44
"""Returns the sum of two numbers (Python only)"""

requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn pyo3_sum(a: usize, b: usize) -> PyResult<usize> {
1414

1515
/// A Python module implemented in Rust.
1616
#[pymodule]
17-
fn foobar(_py: Python, m: &PyModule) -> PyResult<()> {
17+
fn _foobar(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
1818
m.add_function(wrap_pyfunction!(pyo3_sum, m)?)?;
1919
Ok(())
2020
}

uv.lock

Lines changed: 230 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)