From 4723fc6d5d702052157880c500a5717abad26f80 Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Mon, 16 Dec 2024 12:38:09 -0300 Subject: [PATCH] Add prebuilt binaries for Python 3.13 (#27) * Hopefully add prebuilt binaries for Python 3.13 * Setup mypy and bump minimal python version to 3.9 * fix * Setup MSRV * cleanup * clippy and MSRV * version bump * Explicit version range on setup-python action --- .github/workflows/maturin_upload_pypi.yml | 26 +++++++++++++++--- .github/workflows/mypy.yml | 24 +++++++++++++++++ .github/workflows/rust.yml | 33 ++++++++++++++++++++--- CHANGELOG.md | 14 ++++++++++ Cargo.lock | 4 +-- cli/Cargo.toml | 5 ++-- lib/Cargo.toml | 3 ++- lib/crunch64/__init__.py | 2 +- lib/pyproject.toml | 2 +- lib/src/mio0.rs | 6 +---- lib/src/yay0.rs | 6 +---- lib/src/yaz0.rs | 6 +---- mypy.ini | 3 +++ 13 files changed, 106 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/mypy.yml create mode 100644 mypy.ini diff --git a/.github/workflows/maturin_upload_pypi.yml b/.github/workflows/maturin_upload_pypi.yml index 830c3bb..e612c12 100644 --- a/.github/workflows/maturin_upload_pypi.yml +++ b/.github/workflows/maturin_upload_pypi.yml @@ -24,7 +24,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.9 - 3.13' - name: Build wheels uses: PyO3/maturin-action@v1 with: @@ -50,7 +50,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.13' architecture: ${{ matrix.target }} - name: Build wheels uses: PyO3/maturin-action@v1 @@ -76,7 +76,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.13' - name: Build wheels uses: PyO3/maturin-action@v1 with: @@ -113,6 +113,26 @@ jobs: path: dist if-no-files-found: error + check_clippy_python_bindings: + name: Check clippy for Python bindings + runs-on: ubuntu-latest + + steps: + - name: Checkout reposistory + uses: actions/checkout@v4 + + - name: Setup Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Setup clippy + run: rustup component add clippy + + - name: Run clippy + run: cargo clippy --all-targets --features python_bindings -- -D warnings + release: name: Release runs-on: ubuntu-latest diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml new file mode 100644 index 0000000..d0fb16c --- /dev/null +++ b/.github/workflows/mypy.yml @@ -0,0 +1,24 @@ +name: Check mypy + +# Build on every branch push, tag push, and pull request change: +on: [push, pull_request] + +jobs: + checks: + runs-on: ubuntu-latest + name: mypy + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3.9 + uses: actions/setup-python@v4 + with: + python-version: 3.9 + + - name: Install Dependencies + run: | + python3 -m pip install -U mypy + + - name: mypy + run: | + python3 -m mypy --show-column-numbers --hide-error-context . diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2e80f2f..0426770 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -6,14 +6,27 @@ env: CARGO_TERM_COLOR: always jobs: - rustfmt-check: + rustfmt: + name: Check formatting runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout reposistory + uses: actions/checkout@v4 + - name: Run cargo fmt run: cargo fmt --all -- --check + + clippy: + name: Check clippy + runs-on: ubuntu-latest + steps: + - name: Checkout reposistory + uses: actions/checkout@v4 + - name: Run cargo clippy - run: cargo clippy --all -- -D warnings + run: | + cargo clippy --version + cargo clippy --all --all-targets --all-features -- -D warnings macos-check: runs-on: macos-latest @@ -35,3 +48,17 @@ jobs: - uses: actions/checkout@v4 - name: Test run: cargo test + + msrv: + name: Check MSRV + runs-on: ubuntu-latest + steps: + - name: Checkout reposistory + uses: actions/checkout@v4 + + - name: Setup MSRV checker + uses: taiki-e/install-action@cargo-hack + + # To find current MSRV use `cargo msrv find`. Install it with `cargo install cargo-msrv --locked` + - name: Run MSRV checker + run: cargo hack check --rust-version --workspace --all-targets --ignore-private diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e203d5..21d38b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.5.2] - 2024-12-15 + +### Added + +- Prebuilt binaries for Python 3.13. +- Check Python files with mypy. +- Set MSRV (minimum supported Rust version) to 1.73. + +### Changed + +- Python 3.9 or later is now required. + - Mainly due to not being able to automatically check and build for older versions in CI. + ## [0.5.1] - 2024-07-25 ### Fixed @@ -73,6 +86,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - C bindings. [unreleased]: https://github.com/decompals/crunch64/compare/0.5.1...HEAD +[0.5.2]: https://github.com/decompals/crunch64/compare/0.5.1...0.5.2 [0.5.1]: https://github.com/decompals/crunch64/compare/0.5.0...0.5.1 [0.5.0]: https://github.com/decompals/crunch64/compare/0.4.0...0.5.0 [0.4.0]: https://github.com/decompals/crunch64/compare/0.3.1...0.4.0 diff --git a/Cargo.lock b/Cargo.lock index 5c99315..e955e5a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -134,7 +134,7 @@ dependencies = [ [[package]] name = "crunch64" -version = "0.5.1" +version = "0.5.2" dependencies = [ "crc32fast", "pyo3", @@ -144,7 +144,7 @@ dependencies = [ [[package]] name = "crunch64-cli" -version = "0.5.1" +version = "0.5.2" dependencies = [ "clap", "crunch64", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index a954dc2..38f5621 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,15 +1,16 @@ [package] name = "crunch64-cli" -version = "0.5.1" +version = "0.5.2" edition = "2021" description = "A utility for compressing/decompressing files with common n64 formats" repository = "https://github.com/decompals/crunch64" license = "MIT" +rust-version = "1.73.0" [[bin]] name = "crunch64" path = "src/main.rs" [dependencies] -crunch64 = { version = "0.5.1", path = "../lib" } +crunch64 = { version = "0.5.2", path = "../lib" } clap = { version = "4.4.11", features = ["derive"] } diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 320c5bd..dae5a29 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -1,11 +1,12 @@ [package] name = "crunch64" # Version should be synced with lib/pyproject.toml and lib/crunch64/__init__.py -version = "0.5.1" +version = "0.5.2" edition = "2021" description = "A library for handling common compression formats for N64 games" repository = "https://github.com/decompals/crunch64" license = "MIT" +rust-version = "1.73.0" [lib] name = "crunch64" diff --git a/lib/crunch64/__init__.py b/lib/crunch64/__init__.py index 0d61bf3..62221dd 100644 --- a/lib/crunch64/__init__.py +++ b/lib/crunch64/__init__.py @@ -3,7 +3,7 @@ from __future__ import annotations # Version should be synced with lib/Cargo.toml and lib/pyproject.toml -__version_info__ = (0, 5, 1) +__version_info__ = (0, 5, 2) __version__ = ".".join(map(str, __version_info__)) __author__ = "decompals" diff --git a/lib/pyproject.toml b/lib/pyproject.toml index 43a60cd..58c15eb 100644 --- a/lib/pyproject.toml +++ b/lib/pyproject.toml @@ -3,7 +3,7 @@ name = "crunch64" # Version should be synced with lib/Cargo.toml and lib/crunch64/__init__.py version = "0.5.1" description = "A library for handling common compression formats for N64 games" -requires-python = ">=3.7" +requires-python = ">=3.9" dependencies = [ ] classifiers = [ diff --git a/lib/src/mio0.rs b/lib/src/mio0.rs index 6ab63c0..21cd380 100644 --- a/lib/src/mio0.rs +++ b/lib/src/mio0.rs @@ -77,13 +77,9 @@ pub fn decompress(bytes: &[u8]) -> Result, Crunch64Error> { Ok(ret.into_boxed_slice()) } -fn divide_round_up(a: usize, b: usize) -> usize { - (a + b - 1) / b -} - fn size_for_compressed_buffer(input_size: usize) -> Result { // Taken from Yaz0 - Ok(input_size + divide_round_up(input_size, 8) + 0x10) + Ok(input_size + input_size.div_ceil(8) + 0x10) } pub fn compress(bytes: &[u8]) -> Result, Crunch64Error> { diff --git a/lib/src/yay0.rs b/lib/src/yay0.rs index 6be670d..c27544a 100644 --- a/lib/src/yay0.rs +++ b/lib/src/yay0.rs @@ -85,13 +85,9 @@ pub fn decompress(bytes: &[u8]) -> Result, Crunch64Error> { Ok(ret.into_boxed_slice()) } -fn divide_round_up(a: usize, b: usize) -> usize { - (a + b - 1) / b -} - fn size_for_compressed_buffer(input_size: usize) -> Result { // Taken from Yaz0 - Ok(input_size + divide_round_up(input_size, 8) + 0x10) + Ok(input_size + input_size.div_ceil(8) + 0x10) } pub fn compress(bytes: &[u8]) -> Result, Crunch64Error> { diff --git a/lib/src/yaz0.rs b/lib/src/yaz0.rs index 4af7620..9ec6fce 100644 --- a/lib/src/yaz0.rs +++ b/lib/src/yaz0.rs @@ -82,15 +82,11 @@ pub fn decompress(bytes: &[u8]) -> Result, Crunch64Error> { Ok(ret.into_boxed_slice()) } -fn divide_round_up(a: usize, b: usize) -> usize { - (a + b - 1) / b -} - fn size_for_compressed_buffer(input_size: usize) -> Result { // Worst-case size for output is zero compression on the input, meaning the input size plus the number of layout bytes plus the Yaz0 header. // There would be one layout byte for every 8 input bytes, so the worst-case size is: // input_size + ROUND_UP_DIVIDE(input_size, 8) + 0x10 - Ok(input_size + divide_round_up(input_size, 8) + 0x10) + Ok(input_size + input_size.div_ceil(8) + 0x10) } pub fn compress(bytes: &[u8]) -> Result, Crunch64Error> { diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..2145f40 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.9 +check_untyped_defs = True