diff --git a/.github/workflows/CI.yml b/.github/workflows/release.yml similarity index 97% rename from .github/workflows/CI.yml rename to .github/workflows/release.yml index eb7ca0c..8cde0d3 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,4 @@ -# This file is autogenerated by maturin v1.12.6 -# To update, run -# -# maturin generate-ci github -# -name: CI +name: Release workflow on: release: @@ -37,7 +32,7 @@ jobs: python-version: 3.x - name: Setting correct version run: | - python scripts/bump_version.py "${{ github.ref_name }}" + python scripts/bump_version.py "${{ github.ref_name }}" - name: Build wheels uses: PyO3/maturin-action@v1 with: @@ -73,7 +68,7 @@ jobs: python-version: 3.x - name: Setting correct version run: | - python scripts/bump_version.py "${{ github.ref_name }}" + python scripts/bump_version.py "${{ github.ref_name }}" - name: Build wheels uses: PyO3/maturin-action@v1 with: @@ -112,7 +107,7 @@ jobs: architecture: ${{ matrix.platform.python_arch }} - name: Setting correct version run: | - python scripts/bump_version.py "${{ github.ref_name }}" + python scripts/bump_version.py "${{ github.ref_name }}" - name: Build wheels uses: PyO3/maturin-action@v1 with: @@ -141,7 +136,7 @@ jobs: python-version: 3.x - name: Setting correct version run: | - python scripts/bump_version.py "${{ github.ref_name }}" + python scripts/bump_version.py "${{ github.ref_name }}" - name: Build wheels uses: PyO3/maturin-action@v1 with: @@ -163,7 +158,7 @@ jobs: python-version: 3.x - name: Setting correct version run: | - python scripts/bump_version.py "${{ github.ref_name }}" + python scripts/bump_version.py "${{ github.ref_name }}" - name: Build sdist uses: PyO3/maturin-action@v1 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..9e4c607 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,51 @@ +name: "Testing package" + +on: + pull_request: + +jobs: + py-lint: + strategy: + matrix: + cmd: + - black + - ruff + - mypy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" + - name: Run lint check + uses: pre-commit/action@v3.0.0 + with: + extra_args: -a ${{ matrix.cmd }} + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: rustfmt + override: true + - name: Check code format + run: cargo fmt -- --check + + clippy: + permissions: + checks: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: clippy + override: true + - uses: auguwu/clippy-action@1.4.0 + with: + token: ${{secrets.GITHUB_TOKEN}} + deny: warnings diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..e5cfcf7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,62 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: trailing-whitespace + - repo: https://github.com/psf/black + rev: 26.3.0 + hooks: + - id: black + name: python black + pass_filenames: false + always_run: true + args: ["python"] + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.19.1 + hooks: + - id: mypy + name: python mypy + always_run: true + pass_filenames: false + args: ["python"] + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.15.5 + hooks: + - id: ruff + name: ruff + pass_filenames: false + always_run: true + args: ["python", "--fix"] + - repo: local + hooks: + - id: fmt + types: + - rust + name: rust fmt + language: system + entry: cargo + pass_filenames: false + args: + - fmt + + - id: clippy + types: + - rust + name: rust clippy + language: system + pass_filenames: false + entry: cargo + args: + - clippy + - --fix + - --allow-dirty + + - id: check + types: + - rust + name: rust cargo check + language: system + entry: cargo + pass_filenames: false + args: + - check diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..6575192 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1 @@ +use_try_shorthand=true diff --git a/python/natsrpy/__init__.py b/python/natsrpy/__init__.py index 163da45..6dfc866 100644 --- a/python/natsrpy/__init__.py +++ b/python/natsrpy/__init__.py @@ -1,8 +1,4 @@ -from natsrpy._inner import ( - Nats, - Subscription, - Message, -) +from natsrpy._inner import Message, Nats, Subscription __all__ = [ "Nats", diff --git a/python/natsrpy/_inner/js/kv.pyi b/python/natsrpy/_inner/js/kv.pyi index 22c2b4f..684bcfc 100644 --- a/python/natsrpy/_inner/js/kv.pyi +++ b/python/natsrpy/_inner/js/kv.pyi @@ -1,4 +1,4 @@ -from natsrpy._inner.js.stream import StorageType, Source, Placement, Republish +from natsrpy._inner.js.stream import Placement, Republish, Source, StorageType class KVConfig: """ diff --git a/python/natsrpy/js/kv.py b/python/natsrpy/js/kv.py index 85f593a..faabf69 100644 --- a/python/natsrpy/js/kv.py +++ b/python/natsrpy/js/kv.py @@ -1,7 +1,4 @@ -from natsrpy._inner.js.kv import ( - KVConfig, - KeyValue, -) +from natsrpy._inner.js.kv import KeyValue, KVConfig __all__ = [ "KVConfig", diff --git a/python/natsrpy/js/stream.py b/python/natsrpy/js/stream.py index aa2f33a..589c47b 100644 --- a/python/natsrpy/js/stream.py +++ b/python/natsrpy/js/stream.py @@ -1,10 +1,10 @@ from natsrpy._inner.js.stream import ( External, + Placement, Republish, Source, StorageType, SubjectTransform, - Placement, ) __all__ = [ diff --git a/src/exceptions/py_err.rs b/src/exceptions/py_err.rs index 264a238..30482a8 100644 --- a/src/exceptions/py_err.rs +++ b/src/exceptions/py_err.rs @@ -1,5 +1,4 @@ -use pyo3::create_exception; -use pyo3::pymodule; +use pyo3::{create_exception, pymodule}; create_exception!( natsrpy.exceptions, diff --git a/src/js/jetstream.rs b/src/js/jetstream.rs index b65bd52..afb8eb0 100644 --- a/src/js/jetstream.rs +++ b/src/js/jetstream.rs @@ -1,17 +1,17 @@ -use std::ops::Deref; -use std::sync::Arc; +use std::{ops::Deref, sync::Arc}; -use async_nats::Subject; -use async_nats::client::traits::Publisher; -use async_nats::connection::State; -use pyo3::types::{PyBytesMethods, PyDict}; -use pyo3::{Bound, PyAny, Python, pyclass, pymethods, types::PyBytes}; +use async_nats::{Subject, client::traits::Publisher, connection::State}; +use pyo3::{ + Bound, PyAny, Python, pyclass, pymethods, + types::{PyBytes, PyBytesMethods, PyDict}, +}; use tokio::sync::RwLock; -use crate::exceptions::rust_err::NatsrpyError; -use crate::js::kv::{KVConfig, KeyValue}; -use crate::utils::headers::NatsrpyHeadermapExt; -use crate::{exceptions::rust_err::NatsrpyResult, utils::natsrpy_future}; +use crate::{ + exceptions::rust_err::{NatsrpyError, NatsrpyResult}, + js::kv::{KVConfig, KeyValue}, + utils::{headers::NatsrpyHeadermapExt, natsrpy_future}, +}; #[pyclass] pub struct JetStream { diff --git a/src/js/stream.rs b/src/js/stream.rs index cecda21..53d7e6e 100644 --- a/src/js/stream.rs +++ b/src/js/stream.rs @@ -1,10 +1,7 @@ use std::ops::Deref; -use crate::exceptions::rust_err::NatsrpyError; -use crate::exceptions::rust_err::NatsrpyResult; -use pyo3::Bound; -use pyo3::pyclass; -use pyo3::pymethods; +use crate::exceptions::rust_err::{NatsrpyError, NatsrpyResult}; +use pyo3::{Bound, pyclass, pymethods}; #[pyclass(from_py_object)] #[derive(Clone, Copy, Default)] @@ -52,7 +49,7 @@ pub struct External { impl External { #[new] #[pyo3(signature = (api_prefix, delivery_prefix=None))] - #[must_use] + #[must_use] pub const fn __new__(api_prefix: String, delivery_prefix: Option) -> Self { Self { api_prefix, @@ -114,7 +111,6 @@ impl TryFrom for async_nats::jetstream::stream::Source { domain: value.domain.clone(), subject_transforms: value .subject_transforms - .into_iter() .map(std::convert::Into::into) .collect(), @@ -169,7 +165,7 @@ pub struct Placement { impl Placement { #[new] #[pyo3(signature=(cluster=None, tags=None))] - #[must_use] + #[must_use] pub fn __new__(cluster: Option, tags: Option>) -> Self { Self { cluster, diff --git a/src/lib.rs b/src/lib.rs index f9d35f3..aca93a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,13 +9,13 @@ #![ allow( // I don't care about this. - clippy::module_name_repetitions, + clippy::module_name_repetitions, // Yo, the hell you should put // it in docs, if signature is clear as sky. clippy::missing_errors_doc, // Because pythonic way is // to have many args with defaults. - clippy::too_many_arguments + clippy::too_many_arguments )] pub mod exceptions; pub mod js; diff --git a/src/subscription.rs b/src/subscription.rs index 4ba35fb..591690c 100644 --- a/src/subscription.rs +++ b/src/subscription.rs @@ -5,8 +5,10 @@ use std::{sync::Arc, time::Duration}; use pyo3::{Bound, PyAny, PyRef, Python, pyclass, pymethods}; use tokio::sync::Mutex; -use crate::exceptions::rust_err::NatsrpyError; -use crate::{exceptions::rust_err::NatsrpyResult, utils::natsrpy_future}; +use crate::{ + exceptions::rust_err::{NatsrpyError, NatsrpyResult}, + utils::natsrpy_future, +}; #[pyclass] pub struct Subscription { @@ -14,7 +16,7 @@ pub struct Subscription { } impl Subscription { - #[must_use] + #[must_use] pub fn new(sub: async_nats::Subscriber) -> Self { Self { inner: Some(Arc::new(Mutex::new(sub))),