From 055ba7e34d353756c129005cf6175170b9fe96a9 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sat, 22 Nov 2025 10:34:03 +1300 Subject: [PATCH 1/7] CI: Add clippy and fmt lints Run cargo clippy, and cargo fmt with import sorting. --- .github/workflows/lint.yml | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..4a789a5 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,40 @@ +name: Lint + +on: + push: + branches: ["main"] + pull_request: + types: [opened, reopened, synchronize] + branches: ["main"] + +permissions: {} + +# Make sure CI fails on all warnings, including Clippy lints +env: + CARGO_TERM_COLOR: always + RUSTFLAGS: "-Dwarnings" + +jobs: + clippy_check: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + with: + persist-credentials: false + + - name: Run Clippy + run: cargo clippy --all-targets + + format_check: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + with: + persist-credentials: false + + - name: Run Rustfmt + run: cargo fmt --check -- --config imports_granularity=Module,group_imports=StdExternalCrate From 3885faa4797ce54f7b68802e99d6e6748d9f1cb0 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sat, 22 Nov 2025 10:39:19 +1300 Subject: [PATCH 2/7] Format imports --- src/cog.rs | 8 ++++---- src/error.rs | 1 + src/geo/geo_key_directory.rs | 3 +-- src/metadata/reader.rs | 11 ++++++----- src/predictor.rs | 11 ++++------- src/reader.rs | 1 + src/tiff/error.rs | 8 ++------ 7 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/cog.rs b/src/cog.rs index 99a0f14..1021b23 100644 --- a/src/cog.rs +++ b/src/cog.rs @@ -23,13 +23,13 @@ mod test { use std::io::BufReader; use std::sync::Arc; - use crate::metadata::{PrefetchBuffer, TiffMetadataReader}; - use crate::reader::{AsyncFileReader, ObjectReader}; - - use super::*; use object_store::local::LocalFileSystem; use tiff::decoder::{DecodingResult, Limits}; + use super::*; + use crate::metadata::{PrefetchBuffer, TiffMetadataReader}; + use crate::reader::{AsyncFileReader, ObjectReader}; + #[ignore = "local file"] #[tokio::test] async fn tmp() { diff --git a/src/error.rs b/src/error.rs index b1b2204..8c63711 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,7 @@ //! Error handling. use std::fmt::Debug; + use thiserror::Error; /// Enum with all errors in this crate. diff --git a/src/geo/geo_key_directory.rs b/src/geo/geo_key_directory.rs index acf9aa2..8f248ef 100644 --- a/src/geo/geo_key_directory.rs +++ b/src/geo/geo_key_directory.rs @@ -5,8 +5,7 @@ use std::collections::HashMap; use num_enum::{IntoPrimitive, TryFromPrimitive}; -use crate::tiff::Value; -use crate::tiff::{TiffError, TiffResult}; +use crate::tiff::{TiffError, TiffResult, Value}; /// Geospatial TIFF tag variants #[derive(Clone, Copy, Debug, PartialEq, TryFromPrimitive, IntoPrimitive, Eq, Hash)] diff --git a/src/metadata/reader.rs b/src/metadata/reader.rs index 6a72ff9..ae5de16 100644 --- a/src/metadata/reader.rs +++ b/src/metadata/reader.rs @@ -623,14 +623,15 @@ async fn read_tag_value( #[cfg(test)] mod test { - use crate::{ - metadata::{reader::read_tag, MetadataFetch}, - reader::Endianness, - tiff::{tags::Tag, Value}, - }; use bytes::Bytes; use futures::FutureExt; + use crate::metadata::reader::read_tag; + use crate::metadata::MetadataFetch; + use crate::reader::Endianness; + use crate::tiff::tags::Tag; + use crate::tiff::Value; + impl MetadataFetch for Bytes { fn fetch( &self, diff --git a/src/predictor.rs b/src/predictor.rs index 34d6fe5..1d2fc81 100644 --- a/src/predictor.rs +++ b/src/predictor.rs @@ -3,10 +3,10 @@ use std::fmt::Debug; use bytes::{Bytes, BytesMut}; -use crate::error::AsyncTiffError; +use crate::error::{AsyncTiffError, AsyncTiffResult}; +use crate::reader::Endianness; use crate::tiff::tags::PlanarConfiguration; use crate::ImageFileDirectory; -use crate::{error::AsyncTiffResult, reader::Endianness}; /// All info that may be used by a predictor /// @@ -397,12 +397,9 @@ mod test { use bytes::Bytes; - use crate::{ - predictor::{unpredict_float, unpredict_hdiff}, - reader::Endianness, - }; - use super::*; + use crate::predictor::{unpredict_float, unpredict_hdiff}; + use crate::reader::Endianness; const PRED_INFO: PredictorInfo = PredictorInfo { endianness: Endianness::LittleEndian, diff --git a/src/reader.rs b/src/reader.rs index 06520ec..da330b4 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -108,6 +108,7 @@ impl Toki async fn make_range_request(&self, range: Range) -> AsyncTiffResult { use std::io::SeekFrom; + use tokio::io::{AsyncReadExt, AsyncSeekExt}; use crate::error::AsyncTiffError; diff --git a/src/tiff/error.rs b/src/tiff/error.rs index 6cbf2af..a3fb73d 100644 --- a/src/tiff/error.rs +++ b/src/tiff/error.rs @@ -1,17 +1,13 @@ use std::error::Error; -use std::fmt; use std::fmt::Display; -use std::io; -use std::str; -use std::string; use std::sync::Arc; +use std::{fmt, io, str, string}; use jpeg::UnsupportedFeature; use super::ifd::Value; -use super::tags::Predictor; use super::tags::{ - CompressionMethod, PhotometricInterpretation, PlanarConfiguration, SampleFormat, Tag, + CompressionMethod, PhotometricInterpretation, PlanarConfiguration, Predictor, SampleFormat, Tag, }; /// Tiff error kinds. From bc85d34cad0d33ef669319264fe3362d42cf52d5 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sat, 22 Nov 2025 11:16:55 +1300 Subject: [PATCH 3/7] Move lints from test.yml and test-python.yml to lint.yml --- .github/workflows/lint.yml | 8 ++++++-- .github/workflows/test-python.yml | 12 ++---------- .github/workflows/test.yml | 12 ++---------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4a789a5..c5e0f23 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -25,7 +25,9 @@ jobs: persist-credentials: false - name: Run Clippy - run: cargo clippy --all-targets + run: | + cargo clippy --all-targets --all-features + cargo clippy --all-targets --all-features --manifest-path python/Cargo.toml format_check: runs-on: ubuntu-latest @@ -37,4 +39,6 @@ jobs: persist-credentials: false - name: Run Rustfmt - run: cargo fmt --check -- --config imports_granularity=Module,group_imports=StdExternalCrate + run: | + cargo fmt --all --check -- --config imports_granularity=Module,group_imports=StdExternalCrate + cargo fmt --all --check --manifest-path python/Cargo.toml -- --config imports_granularity=Module,group_imports=StdExternalCrate diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index c601d09..7914d2c 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -7,8 +7,8 @@ on: pull_request: jobs: - lint-test: - name: Lint and Test + test: + name: Test runs-on: ubuntu-latest defaults: run: @@ -18,17 +18,9 @@ jobs: - name: Install Rust uses: dtolnay/rust-toolchain@stable - with: - components: rustfmt, clippy - uses: Swatinem/rust-cache@v2 - - name: Cargo fmt - run: cargo fmt --all -- --check - - - name: "clippy --all" - run: cargo clippy --all --all-features --tests -- -D warnings - - name: "cargo check" run: cargo check --all --all-features diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 79510bf..e7a63d8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,25 +7,17 @@ on: pull_request: jobs: - lint-test: - name: Lint and Test + test: + name: Test runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Install Rust uses: dtolnay/rust-toolchain@stable - with: - components: rustfmt, clippy - uses: Swatinem/rust-cache@v2 - - name: Cargo fmt - run: cargo fmt --all -- --check - - - name: "clippy --all" - run: cargo clippy --all --all-features --tests -- -D warnings - - run: cargo install cargo-all-features - name: Check all combinations of features can build From ee5e549c98d9440dc40e357c2f2b81850c569cec Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sat, 22 Nov 2025 11:19:11 +1300 Subject: [PATCH 4/7] Format imports in python/ folder --- python/src/thread_pool.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/python/src/thread_pool.rs b/python/src/thread_pool.rs index 22309c2..e91424d 100644 --- a/python/src/thread_pool.rs +++ b/python/src/thread_pool.rs @@ -2,7 +2,6 @@ use std::sync::Arc; use pyo3::exceptions::PyValueError; use pyo3::prelude::*; - use pyo3::sync::PyOnceLock; use rayon::{ThreadPool, ThreadPoolBuilder}; From 4fef3f20988ac1a65a6d4e78c4c2f6d39e80fb74 Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Sat, 22 Nov 2025 13:52:13 +1300 Subject: [PATCH 5/7] Apply suggestions from code review --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c5e0f23..863e15a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -34,7 +34,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@v6 with: persist-credentials: false From e29d83d29f72c21b3a9101e67d6d475b77553ee1 Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Sat, 22 Nov 2025 13:53:10 +1300 Subject: [PATCH 6/7] Update .github/workflows/lint.yml --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 863e15a..b56a0e2 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -20,7 +20,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + uses: actions/checkout@v6 with: persist-credentials: false From ed4f10f9fd130cc35c4089b6ff9118d893165910 Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Sat, 22 Nov 2025 13:57:59 +1300 Subject: [PATCH 7/7] remove rustfmt component installation --- .github/workflows/test-python.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 7914d2c..b3a895a 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -39,8 +39,6 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust uses: dtolnay/rust-toolchain@stable - with: - components: rustfmt - uses: Swatinem/rust-cache@v2 - uses: actions/setup-python@v5