Skip to content

A fast, helpful, and open-source document parser

chore: add minimal ci

Clelia (Astra) Bertellie3c182583a7a
diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml
new file mode 100644
index 0000000..90a66b4
--- /dev/null
+++ b/.github/workflows/rust-ci.yml
@@ -0,0 +1,112 @@
+name: Rust CI
+
+on:
+ pull_request:
+ paths:
+ - crates/**/*.rs
+ - crates/**/Cargo.toml
+ - Cargo.toml
+env:
+ CARGO_TERM_COLOR: always
+
+jobs:
+ clippy:
+ name: Clippy
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Install Rust toolchain
+ uses: dtolnay/rust-toolchain@stable
+ with:
+ components: clippy
+
+ - name: Cache cargo registry
+ uses: actions/cache@v4
+ with:
+ path: |
+ ~/.cargo/registry
+ ~/.cargo/git
+ target
+ key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}
+
+ - name: Run clippy
+ run: make lint-strict
+
+ format:
+ name: Format
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Install Rust toolchain
+ uses: dtolnay/rust-toolchain@stable
+ with:
+ components: rustfmt
+
+ - name: Check formatting
+ run: make format-check
+
+ test:
+ name: Test on ${{ matrix.os }}
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ubuntu-latest, windows-latest, macos-latest]
+ rust: [stable]
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Install Rust toolchain
+ uses: dtolnay/rust-toolchain@master
+ with:
+ toolchain: ${{ matrix.rust }}
+
+ - name: Cache cargo registry
+ uses: actions/cache@v4
+ with:
+ path: |
+ ~/.cargo/registry
+ ~/.cargo/git
+ target
+ key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
+ restore-keys: |
+ ${{ runner.os }}-cargo-
+
+ - name: Run tests
+ run: make test
+
+ build:
+ name: Build on ${{ matrix.os }}
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ubuntu-latest, windows-latest, macos-latest]
+ rust: [stable]
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Install Rust toolchain
+ uses: dtolnay/rust-toolchain@master
+ with:
+ toolchain: ${{ matrix.rust }}
+
+ - name: Cache cargo registry
+ uses: actions/cache@v4
+ with:
+ path: |
+ ~/.cargo/registry
+ ~/.cargo/git
+ target
+ key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
+ restore-keys: |
+ ${{ runner.os }}-cargo-
+
+ - name: Run build
+ run: make build
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..36dc61f
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,31 @@
+.PHONY: test lint lint-strict format format-check build
+
+all: test lint format
+
+test:
+ $(info ****************** running tests ******************)
+ cargo test --all
+
+lint-strict:
+ $(info ****************** running clippy in strict mode ******************)
+ cargo clippy --all-targets --all-features -- -D warnings # treat warnings as errors
+
+lint:
+ $(info ****************** running clippy in strict mode ******************)
+ cargo clippy --all-targets --all-features
+
+lint-fix:
+ $(info ****************** running clippy in strict mode ******************)
+ cargo clippy --fix --allow-dirty --all-targets --all-features
+
+format:
+ $(info ****************** formatting ******************)
+ cargo fmt --all
+
+format-check:
+ $(info ****************** checking formatting ******************)
+ cargo fmt --all --check
+
+build:
+ $(info ****************** building ******************)
+ cargo build
diff --git a/crates/liteparse/src/ocr/http_simple.rs b/crates/liteparse/src/ocr/http_simple.rs
index ad58897..b894dfe 100644
--- a/crates/liteparse/src/ocr/http_simple.rs
+++ b/crates/liteparse/src/ocr/http_simple.rs
@@ -49,21 +49,21 @@ impl HttpOcrEngine {
let result = self.recognize(i, 0, 0, &options)?;
results.push(result);
}
- return Ok(results);
+ Ok(results)
}
}
impl OcrEngine for HttpOcrEngine {
fn name(&self) -> &str {
- return &self.name;
+ &self.name
}
- fn recognize<'a, 'b>(
+ fn recognize(
&self,
- image_data: &'a [u8],
+ image_data: &[u8],
_width: u32,
_height: u32,
- options: &'b OcrOptions,
+ options: &OcrOptions,
) -> Result<Vec<OcrResult>, Box<dyn std::error::Error>> {
let client = Client::new();
let form = Form::new()
diff --git a/crates/liteparse/src/ocr_merge.rs b/crates/liteparse/src/ocr_merge.rs
index e78b537..85c1a2f 100644
--- a/crates/liteparse/src/ocr_merge.rs
+++ b/crates/liteparse/src/ocr_merge.rs
@@ -11,7 +11,7 @@ pub fn ocr_and_merge_pages(
pages: &mut [Page],
pdf_path: &str,
dpi: f32,
- ocr_engine: &Box<dyn OcrEngine>,
+ ocr_engine: &dyn OcrEngine,
ocr_language: &str,
) -> Result<(), Box<dyn std::error::Error>> {
let lib = Library::init();
diff --git a/crates/liteparse/src/parser.rs b/crates/liteparse/src/parser.rs
index f4ba54e..6f67dae 100644
--- a/crates/liteparse/src/parser.rs
+++ b/crates/liteparse/src/parser.rs
@@ -82,7 +82,7 @@ impl LiteParse {
&mut pages,
&pdf_path,
self.config.dpi,
- &engine,
+ engine.as_ref(),
&self.config.ocr_language,
)?;
}