diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..b56a0e2 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,44 @@ +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@v6 + with: + persist-credentials: false + + - name: Run Clippy + run: | + cargo clippy --all-targets --all-features + cargo clippy --all-targets --all-features --manifest-path python/Cargo.toml + + format_check: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v6 + with: + persist-credentials: false + + - name: Run Rustfmt + 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..b3a895a 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 @@ -47,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 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 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}; 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.