Skip to content

Commit ba26d93

Browse files
committed
Added CI + some fixes.
1 parent 26f119d commit ba26d93

File tree

15 files changed

+455
-59
lines changed

15 files changed

+455
-59
lines changed

.github/workflows/test.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: "Testing package"
22

33
on:
4-
pull_request:
4+
push:
55

66
jobs:
77
py-lint:
@@ -47,5 +47,36 @@ jobs:
4747
override: true
4848
- uses: auguwu/clippy-action@1.4.0
4949
with:
50-
token: ${{secrets.GITHUB_TOKEN}}
51-
deny: warnings
50+
token: ${{secrets.GITHUB_TOKEN}}
51+
deny: warnings
52+
pytest:
53+
runs-on: ubuntu-latest
54+
steps:
55+
- uses: actions/checkout@v1
56+
- uses: actions-rs/toolchain@v1
57+
with:
58+
toolchain: stable
59+
components: clippy
60+
override: true
61+
- uses: actions/setup-python@v6
62+
with:
63+
python-version: 3.x
64+
- id: setup-uv
65+
uses: astral-sh/setup-uv@v7
66+
with:
67+
enable-cache: true
68+
version: "latest"
69+
python-version: 3.x
70+
- id: prepare-container
71+
name: Prepare docker container
72+
run: docker compose up -d --wait
73+
- id: setup-venv
74+
name: Setup virtualenv
75+
run: uv venv
76+
- name: Build wheels
77+
uses: PyO3/maturin-action@v1
78+
with:
79+
comand: dev --uv
80+
sccache: true
81+
- name: Run pytest
82+
run: uv run pytest -vv -n auto python/tests

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,3 @@ For lints please use `pre-commit`.
3333
```bash
3434
pre-commit run -a
3535
```
36-
37-
For tests we use pytest.

docker-compose.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
nats:
3+
image: nats:2.12.5-alpine
4+
command: -m 8222 --jetstream
5+
healthcheck:
6+
test:
7+
- CMD
8+
- "sh"
9+
- "-c"
10+
- "wget http://localhost:8222/healthz -q -O - | xargs | grep ok || exit 1"
11+
interval: 5s
12+
timeout: 3s
13+
retries: 20
14+
ports:
15+
- 4222:4222

pyproject.toml

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "natsrpy"
33
description = "Nats client library written in rust"
44
readme = "README.md"
5-
requires-python = ">=3.8"
5+
requires-python = ">=3.10"
66
license-files = ["LICENSE"]
77
classifiers = [
88
"Programming Language :: Python :: Implementation :: CPython",
@@ -12,7 +12,11 @@ classifiers = [
1212
dynamic = ["version"]
1313

1414
[dependency-groups]
15-
dev = ["pytest>=9,<10"]
15+
dev = [
16+
"anyio>=4,<5",
17+
"pytest>=9,<10",
18+
"pytest-xdist>=3,<4",
19+
]
1620

1721
[build-system]
1822
requires = ["maturin>=1.12,<2.0"]
@@ -23,3 +27,85 @@ bindings = "pyo3"
2327
features = ["pyo3/extension-module"]
2428
module-name = "natsrpy._inner"
2529
python-source = "python"
30+
31+
[tool.pytest]
32+
anyio_mode = "auto"
33+
34+
[tool.mypy]
35+
python_version = "3.10"
36+
strict = true
37+
ignore_missing_imports = true
38+
allow_subclassing_any = true
39+
allow_untyped_calls = true
40+
packages = ["taskiq_nats"]
41+
pretty = true
42+
implicit_reexport = true
43+
allow_untyped_decorators = true
44+
warn_return_any = false
45+
46+
[tool.ruff]
47+
target-version="py310"
48+
exclude = [".venv/"]
49+
line-length = 88
50+
51+
[tool.ruff.lint]
52+
mccabe = { max-complexity = 10 }
53+
# List of enabled rulsets.
54+
# See https://docs.astral.sh/ruff/rules/ for more information.
55+
select = [
56+
"E", # Error
57+
"F", # Pyflakes
58+
"W", # Pycodestyle
59+
"C90", # McCabe complexity
60+
"I", # Isort
61+
"N", # pep8-naming
62+
"D", # Pydocstyle
63+
"ANN", # Pytype annotations
64+
"S", # Bandit
65+
"B", # Bugbear
66+
"COM", # Commas
67+
"C4", # Comprehensions
68+
"ISC", # Implicit string concat
69+
"PIE", # Unnecessary code
70+
"T20", # Catch prints
71+
"PYI", # validate pyi files
72+
"Q", # Checks for quotes
73+
"RSE", # Checks raise statements
74+
"RET", # Checks return statements
75+
"SLF", # Self checks
76+
"SIM", # Simplificator
77+
"PTH", # Pathlib checks
78+
"ERA", # Checks for commented out code
79+
"PL", # PyLint checks
80+
"RUF", # Specific to Ruff checks
81+
"UP", # Pyupgrade
82+
]
83+
ignore = [
84+
"D105", # Missing docstring in magic method
85+
"D107", # Missing docstring in __init__
86+
"D212", # Multi-line docstring summary should start at the first line
87+
"D401", # First line should be in imperative mood
88+
"D104", # Missing docstring in public package
89+
"D100", # Missing docstring in public module
90+
"ANN401", # typing.Any are disallowed in `**kwargs
91+
"PLR0913", # Too many arguments for function call
92+
"D106", # Missing docstring in public nested class
93+
"PYI021", # Docstrings should not be included in stubs
94+
]
95+
96+
[tool.ruff.lint.per-file-ignores]
97+
"python/tests/*" = [
98+
"S101", # Use of assert detected
99+
"S301", # Use of pickle detected
100+
"D103", # Missing docstring in public function
101+
"SLF001", # Private member accessed
102+
"S311", # Standard pseudo-random generators are not suitable for security/cryptographic purposes
103+
"D101", # Missing docstring in public class
104+
]
105+
106+
[tool.ruff.lint.pydocstyle]
107+
convention = "pep257"
108+
ignore-decorators = ["typing.overload"]
109+
110+
[tool.ruff.lint.pylint]
111+
allow-magic-value-types = ["int", "str", "float"]

python/natsrpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from natsrpy._inner import Message, Nats, Subscription
22

33
__all__ = [
4+
"Message",
45
"Nats",
56
"Subscription",
6-
"Message",
77
]

python/natsrpy/_inner/__init__.pyi

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
11
from datetime import timedelta
2-
from typing import Tuple
2+
from typing import Any
3+
34
from natsrpy._inner.js import JetStream
45
from natsrpy._inner.message import Message
56

67
class Subscription:
7-
def __aiter__(self) -> "Subscription": ...
8+
def __aiter__(self) -> Subscription: ...
89
async def __anext__(self) -> Message: ...
910

1011
class Nats:
1112
def __init__(
1213
self,
1314
/,
1415
addrs: list[str] = ["nats://localhost:4222"],
15-
user_and_pass: Tuple[str, str] | None = None,
16+
user_and_pass: tuple[str, str] | None = None,
1617
nkey: str | None = None,
1718
token: str | None = None,
1819
custom_inbox_prefix: str | None = None,
1920
read_buffer_capacity: int = 65535,
2021
sender_capacity: int = 128,
2122
max_reconnects: int | None = None,
22-
connection_timeout: timedelta = timedelta(seconds=5),
23-
request_timeout: timedelta = timedelta(seconds=10),
23+
connection_timeout: timedelta = ...,
24+
request_timeout: timedelta = ...,
2425
) -> None: ...
2526
async def startup(self) -> None: ...
27+
async def shutdown(self) -> None: ...
2628
async def publish(
2729
self,
2830
subject: str,
2931
payload: bytes,
3032
*,
31-
headers: dict[str, str] | None = None,
33+
headers: dict[str, Any] | None = None,
3234
reply: str | None = None,
3335
err_on_disconnect: bool = False,
3436
) -> None: ...
3537
async def request(self, subject: str, payload: bytes) -> None: ...
3638
async def drain(self) -> None: ...
3739
async def flush(self) -> None: ...
38-
async def close(self) -> None: ...
39-
async def subscribe(self, topic: str) -> Subscription: ...
40+
async def subscribe(self, subject: str) -> Subscription: ...
4041
async def jetstream(self) -> JetStream: ...
4142

42-
__all__ = ["Subscription", "Nats", "Message"]
43+
__all__ = ["Message", "Nats", "Subscription"]

python/natsrpy/_inner/js/stream.pyi

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ from datetime import datetime, timedelta
22
from typing import Any
33

44
class StorageType:
5-
FILE: "StorageType"
6-
MEMORY: "StorageType"
5+
FILE: StorageType
6+
MEMORY: StorageType
77

88
class DiscardPolicy:
9-
OLD: "DiscardPolicy"
10-
NEW: "DiscardPolicy"
9+
OLD: DiscardPolicy
10+
NEW: DiscardPolicy
1111

1212
class RetentionPolicy:
13-
LIMITS: "RetentionPolicy"
14-
INTEREST: "RetentionPolicy"
15-
WORKQUEUE: "RetentionPolicy"
13+
LIMITS: RetentionPolicy
14+
INTEREST: RetentionPolicy
15+
WORKQUEUE: RetentionPolicy
1616

1717
class Compression:
18-
S2: "Compression"
19-
NONE: "Compression"
18+
S2: Compression
19+
NONE: Compression
2020

2121
class PersistenceMode:
22-
Default: "PersistenceMode"
23-
Async: "PersistenceMode"
22+
Default: PersistenceMode
23+
Async: PersistenceMode
2424

2525
class ConsumerLimits:
2626
inactive_threshold: timedelta

python/natsrpy/_inner/message.pyi

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,3 @@ class Message:
88
status: int | None
99
description: str | None
1010
length: int
11-
12-
def __repr__(self) -> str: ...
13-
def __str__(self) -> str: ...

python/natsrpy/js/__init__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
from natsrpy._inner.js import JetStream
2+
from natsrpy.js.kv import KeyValue, KVConfig
23
from natsrpy.js.stream import (
3-
StreamConfig,
4-
Source,
54
Compression,
65
ConsumerLimits,
76
DiscardPolicy,
7+
External,
88
PersistenceMode,
99
Placement,
1010
Republish,
1111
RetentionPolicy,
12+
Source,
1213
StorageType,
1314
Stream,
14-
SubjectTransform,
15-
External,
15+
StreamConfig,
1616
StreamMessage,
17+
SubjectTransform,
1718
)
18-
from natsrpy.js.kv import KVConfig, KeyValue
1919

2020
__all__ = [
21-
"JetStream",
22-
"StreamConfig",
23-
"Source",
2421
"Compression",
2522
"ConsumerLimits",
2623
"DiscardPolicy",
24+
"External",
25+
"JetStream",
26+
"KVConfig",
27+
"KeyValue",
2728
"PersistenceMode",
2829
"Placement",
2930
"Republish",
3031
"RetentionPolicy",
32+
"Source",
3133
"StorageType",
3234
"Stream",
33-
"SubjectTransform",
34-
"External",
35-
"KVConfig",
36-
"KeyValue",
35+
"StreamConfig",
3736
"StreamMessage",
37+
"SubjectTransform",
3838
]

python/natsrpy/js/stream.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
from natsrpy._inner.js.stream import (
2+
Compression,
3+
ConsumerLimits,
4+
DiscardPolicy,
25
External,
6+
PersistenceMode,
37
Placement,
48
Republish,
9+
RetentionPolicy,
510
Source,
611
StorageType,
7-
SubjectTransform,
8-
DiscardPolicy,
9-
PersistenceMode,
10-
RetentionPolicy,
11-
Compression,
12-
ConsumerLimits,
13-
StreamConfig,
1412
Stream,
13+
StreamConfig,
1514
StreamMessage,
15+
SubjectTransform,
1616
)
1717

1818
__all__ = [
19+
"Compression",
20+
"ConsumerLimits",
21+
"DiscardPolicy",
1922
"External",
23+
"PersistenceMode",
2024
"Placement",
2125
"Republish",
26+
"RetentionPolicy",
2227
"Source",
2328
"StorageType",
24-
"SubjectTransform",
25-
"DiscardPolicy",
26-
"PersistenceMode",
27-
"RetentionPolicy",
28-
"Compression",
29-
"ConsumerLimits",
30-
"StreamConfig",
3129
"Stream",
30+
"StreamConfig",
3231
"StreamMessage",
32+
"SubjectTransform",
3333
]

0 commit comments

Comments
 (0)