Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions .github/workflows/CI.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
62 changes: 62 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use_try_shorthand=true
6 changes: 1 addition & 5 deletions python/natsrpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from natsrpy._inner import (
Nats,
Subscription,
Message,
)
from natsrpy._inner import Message, Nats, Subscription

__all__ = [
"Nats",
Expand Down
2 changes: 1 addition & 1 deletion python/natsrpy/_inner/js/kv.pyi
Original file line number Diff line number Diff line change
@@ -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:
"""
Expand Down
5 changes: 1 addition & 4 deletions python/natsrpy/js/kv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from natsrpy._inner.js.kv import (
KVConfig,
KeyValue,
)
from natsrpy._inner.js.kv import KeyValue, KVConfig

__all__ = [
"KVConfig",
Expand Down
2 changes: 1 addition & 1 deletion python/natsrpy/js/stream.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from natsrpy._inner.js.stream import (
External,
Placement,
Republish,
Source,
StorageType,
SubjectTransform,
Placement,
)

__all__ = [
Expand Down
3 changes: 1 addition & 2 deletions src/exceptions/py_err.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use pyo3::create_exception;
use pyo3::pymodule;
use pyo3::{create_exception, pymodule};

create_exception!(
natsrpy.exceptions,
Expand Down
22 changes: 11 additions & 11 deletions src/js/jetstream.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
12 changes: 4 additions & 8 deletions src/js/stream.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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<String>) -> Self {
Self {
api_prefix,
Expand Down Expand Up @@ -114,7 +111,6 @@ impl TryFrom<Source> for async_nats::jetstream::stream::Source {
domain: value.domain.clone(),
subject_transforms: value
.subject_transforms

.into_iter()
.map(std::convert::Into::into)
.collect(),
Expand Down Expand Up @@ -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<String>, tags: Option<Vec<String>>) -> Self {
Self {
cluster,
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ 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 {
inner: Option<Arc<Mutex<async_nats::Subscriber>>>,
}

impl Subscription {
#[must_use]
#[must_use]
pub fn new(sub: async_nats::Subscriber) -> Self {
Self {
inner: Some(Arc::new(Mutex::new(sub))),
Expand Down
Loading