Skip to content

Commit 79b17b5

Browse files
committed
chore: rust lint
1 parent 51d6e86 commit 79b17b5

9 files changed

Lines changed: 106 additions & 66 deletions

File tree

.github/workflows/cargo-test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Cargo Test
2+
3+
on: [push, workflow_dispatch]
4+
5+
jobs:
6+
test:
7+
strategy:
8+
matrix:
9+
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
10+
runs-on: ${{ matrix.os }}
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: dtolnay/rust-toolchain@stable
14+
- uses: astral-sh/setup-uv@v5
15+
with:
16+
python-version: "3.12"
17+
- name: Run Rust unit tests
18+
run: uv run cargo test --lib

.github/workflows/clippy.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Clippy
2+
3+
on: [push, workflow_dispatch]
4+
5+
jobs:
6+
clippy:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- uses: dtolnay/rust-toolchain@stable
11+
with:
12+
components: clippy
13+
- uses: astral-sh/setup-uv@v5
14+
with:
15+
python-version: "3.12"
16+
- name: Run Clippy
17+
run: uv run cargo clippy --lib -- -D warnings

.github/workflows/pylint.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ jobs:
1010
python-version: ["3.11", "3.12"]
1111
steps:
1212
- uses: actions/checkout@v4
13-
- name: Set up Python ${{ matrix.python-version }}
14-
uses: actions/setup-python@v5
13+
- uses: dtolnay/rust-toolchain@stable
14+
- uses: astral-sh/setup-uv@v5
1515
with:
1616
python-version: ${{ matrix.python-version }}
1717
- name: Install dependencies
18-
run: |
19-
python -m pip install --upgrade pip poetry
20-
poetry config virtualenvs.create false
21-
poetry install
18+
run: uv sync --dev
19+
- name: Build Rust extension
20+
run: uv run maturin develop
2221
- name: Analysing the code with pylint
23-
run: |
24-
python -m pylint $(git ls-files '*.py')
22+
run: uv run pylint $(git ls-files '*.py')

.github/workflows/pytest.yml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,22 @@ jobs:
1010
runs-on: ${{ matrix.os }}
1111
steps:
1212
- uses: actions/checkout@v4
13-
- name: Set up Python 3.12
14-
uses: actions/setup-python@v5
13+
- uses: dtolnay/rust-toolchain@stable
14+
- uses: astral-sh/setup-uv@v5
1515
with:
16-
python-version: 3.12
16+
python-version: "3.12"
1717
- name: Install dependencies
18-
run: |
19-
python -m pip install --upgrade pip poetry
20-
poetry config virtualenvs.create false
21-
poetry install
22-
- name: Test
23-
run: |
24-
coverage run --branch -m pytest tests/
25-
- name: Generate Report
26-
run: |
27-
coverage html
28-
- name: Upload report
18+
run: uv sync --dev
19+
- name: Build Rust extension
20+
run: uv run maturin develop
21+
- name: Rust unit tests
22+
run: uv run cargo test --lib
23+
- name: Python tests with coverage
24+
run: uv run coverage run --branch -m pytest tests/
25+
- name: Generate coverage report
26+
run: uv run coverage html
27+
- name: Upload coverage report
2928
uses: actions/upload-artifact@v4
3029
with:
3130
name: coverage-report-${{ matrix.os }}
32-
path: |
33-
htmlcov/*
31+
path: htmlcov/*

.github/workflows/release.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,46 @@ jobs:
1919
fetch-depth: 0
2020
token: ${{ secrets.RELEASER }}
2121

22+
- uses: dtolnay/rust-toolchain@stable
23+
24+
- uses: astral-sh/setup-uv@v5
25+
with:
26+
python-version: "3.12"
27+
28+
- name: Install dependencies
29+
run: uv sync --dev
2230

2331
- name: Python Semantic Release
32+
id: psr
2433
uses: python-semantic-release/python-semantic-release@v9.8.6
2534
with:
2635
github_token: ${{ secrets.RELEASER }}
2736
root_options: "-vv"
37+
38+
build-wheels:
39+
name: Build wheels (${{ matrix.os }})
40+
needs: release
41+
if: needs.release.outputs.released == 'true'
42+
strategy:
43+
matrix:
44+
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
45+
runs-on: ${{ matrix.os }}
46+
permissions:
47+
contents: write
48+
49+
steps:
50+
- uses: actions/checkout@v4
51+
with:
52+
ref: ${{ needs.release.outputs.tag }}
53+
token: ${{ secrets.RELEASER }}
54+
55+
- uses: PyO3/maturin-action@v1
56+
with:
57+
command: build
58+
args: --release --out dist
59+
manylinux: auto
60+
61+
- name: Upload wheels to release
62+
env:
63+
GH_TOKEN: ${{ secrets.RELEASER }}
64+
run: gh release upload ${{ needs.release.outputs.tag }} dist/*.whl

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,11 @@ thiserror = "2"
2020

2121
[dev-dependencies]
2222
tempfile = "3"
23+
24+
[lints.rust]
25+
# create_exception! internally uses #[cfg(feature = "gil-refs")] in pyo3 0.22
26+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(feature, values("gil-refs"))'] }
27+
28+
[lints.clippy]
29+
# PyO3 #[pymethods] PyResult<T> return types trigger a false positive
30+
useless_conversion = "allow"

src/db.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -202,30 +202,6 @@ impl DatasetDb {
202202
Ok(missions)
203203
}
204204

205-
pub fn get_mission(&self, name: &str) -> Result<MissionRecord> {
206-
let row = self.conn.query_row(
207-
"SELECT name, path, timestamp, device, country, region, site, mission_name, properties, notes \
208-
FROM missions WHERE name=?1",
209-
params![name],
210-
|row| {
211-
Ok(MissionRecord {
212-
name: row.get(0)?,
213-
path: row.get(1)?,
214-
metadata: MetadataRecord {
215-
timestamp: row.get(2)?,
216-
device: row.get(3)?,
217-
country: row.get(4)?,
218-
region: row.get(5)?,
219-
site: row.get(6)?,
220-
mission_name: row.get(7)?,
221-
properties: row.get(8)?,
222-
notes: row.get(9)?,
223-
},
224-
})
225-
},
226-
)?;
227-
Ok(row)
228-
}
229205

230206
// ── mission staged files ───────────────────────────────────
231207

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ impl PyDataManager {
436436
Ok(())
437437
}
438438

439+
#[allow(clippy::too_many_arguments)]
439440
fn initialize_mission(
440441
&mut self,
441442
timestamp: &str,
@@ -587,6 +588,7 @@ impl PyDataManager {
587588
Ok(output)
588589
}
589590

591+
#[pyo3(signature = (dataset, day=None, mission=None, root_dir=None))]
590592
fn activate(
591593
&mut self,
592594
dataset: &str,
@@ -597,8 +599,7 @@ impl PyDataManager {
597599
// Find or load the dataset
598600
let ds_state = if self.inner.find_dataset(dataset).is_some() {
599601
let info = self.inner.find_dataset(dataset).cloned().unwrap();
600-
let state = dataset::load_dataset_state(&PathBuf::from(&info.root_path))?;
601-
state
602+
dataset::load_dataset_state(&PathBuf::from(&info.root_path))?
602603
} else if let Some(ref rdir) = root_dir {
603604
let dataset_path = PathBuf::from(rdir).join(dataset);
604605
if !dataset_path.is_dir() {
@@ -658,6 +659,7 @@ impl PyDataManager {
658659
Ok(())
659660
}
660661

662+
#[pyo3(signature = (paths, readme, destination=None))]
661663
fn add(
662664
&mut self,
663665
paths: Vec<String>,

src/manager.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::{Path, PathBuf};
22

33
use crate::db::{DatasetInfo, ManagerDb};
4-
use crate::errors::{E4EError, Result};
4+
use crate::errors::Result;
55

66
/// Current manager schema version.
77
const VERSION: i32 = 2;
@@ -110,21 +110,7 @@ impl DataManagerState {
110110
Ok(())
111111
}
112112

113-
/// Return the root path for an active dataset name.
114-
pub fn active_dataset_root(&self) -> Result<Option<PathBuf>> {
115-
match &self.active_dataset_name {
116-
None => Ok(None),
117-
Some(name) => {
118-
match self.find_dataset(name) {
119-
Some(info) => Ok(Some(PathBuf::from(&info.root_path))),
120-
None => Err(E4EError::Runtime(format!(
121-
"Active dataset '{}' not found in registry",
122-
name
123-
))),
124-
}
125-
}
126-
}
127-
}
113+
128114
}
129115

130116

0 commit comments

Comments
 (0)