Skip to content

Commit 7c40b66

Browse files
committed
Use ruff for linting
Signed-off-by: Casper Beyer <[email protected]>
1 parent 3fc3f79 commit 7c40b66

19 files changed

+91
-44
lines changed

.github/workflows/check.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Check
1+
name: check
22
on:
33
push:
44
branches:
@@ -27,3 +27,24 @@ jobs:
2727

2828
- name: Run format check
2929
run: uv run ruff format --check
30+
31+
lint:
32+
runs-on: ubuntu-latest
33+
name: lint
34+
steps:
35+
- name: Check out repository
36+
uses: actions/checkout@v5
37+
38+
- name: Set up Python
39+
uses: actions/setup-python@v6
40+
with:
41+
python-version: "3.8"
42+
43+
- name: Install uv
44+
uses: astral-sh/setup-uv@v6
45+
46+
- name: Install the project
47+
run: uv sync --dev
48+
49+
- name: Run lint check
50+
run: uv run ruff check

nats/examples/advanced.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import asyncio
22

3-
import nats
43
from nats.errors import NoServersError, TimeoutError
54

5+
import nats
6+
67

78
async def main():
89
async def disconnected_cb():

nats/examples/basic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import asyncio
22

3-
import nats
43
from common import args
54
from nats.errors import TimeoutError
65

6+
import nats
7+
78

89
async def main():
910
arguments, _ = args.get_args("Run a basic example.")
@@ -33,7 +34,7 @@ async def message_handler(msg):
3334
async for msg in sub.messages:
3435
print(f"Received a message on '{msg.subject} {msg.reply}': {msg.data.decode()}")
3536
await sub.unsubscribe()
36-
except Exception as e:
37+
except Exception:
3738
pass
3839

3940
async def help_request(msg):

nats/examples/clustered.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import asyncio
22
from datetime import datetime
33

4-
import nats
54
from nats.aio.errors import ErrConnectionClosed, ErrNoServers, ErrTimeout
65

6+
import nats
7+
78

89
async def run():
910
# Setup pool of servers from a NATS cluster.
@@ -66,7 +67,7 @@ async def subscribe_handler(msg):
6667
try:
6768
await nc.publish(f"help.{i}", b"A")
6869
await nc.flush(0.500)
69-
except ErrConnectionClosed as e:
70+
except ErrConnectionClosed:
7071
print("Connection closed prematurely.")
7172
break
7273
except ErrTimeout as e:

nats/examples/connect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import asyncio
22

3-
import nats
43
from common import args
54

5+
import nats
6+
67

78
async def main():
89
async def disconnected_cb():

nats/examples/context-manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import asyncio
22

3-
import nats
43
from common import args
54

5+
import nats
6+
67

78
async def main():
89
is_done = asyncio.Future()

nats/examples/jetstream.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import asyncio
22

3-
import nats
43
from nats.errors import TimeoutError
54

5+
import nats
6+
67

78
async def main():
89
nc = await nats.connect("localhost")

nats/examples/micro/service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import contextlib
33
import signal
44

5-
import nats
65
import nats.micro
76

7+
import nats
8+
89

910
async def echo(req) -> None:
1011
"""Echo the request data back to the client."""

nats/examples/publish.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import asyncio
22

3-
import nats
43
from common import args
54

5+
import nats
6+
67

78
async def main():
89
arguments, _ = args.get_args("Run a publish example.", "Usage: python examples/publish.py")

nats/tests/test_client.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import urllib
99
from unittest import mock
1010

11-
import nats
1211
import nats.errors
1312
import pytest
14-
from nats.aio.client import Client as NATS, ServerVersion, __version__
13+
from nats.aio.client import Client as NATS
14+
from nats.aio.client import ServerVersion, __version__
15+
16+
import nats
1517
from tests.utils import (
1618
ClusteringDiscoveryAuthTestCase,
1719
ClusteringTestCase,
@@ -669,9 +671,9 @@ async def next_msg():
669671

670672
# FIXME: This message would be lost because cannot
671673
# reuse the future from the iterator that timed out.
672-
await nc.publish(f"tests.2", b"bar")
674+
await nc.publish("tests.2", b"bar")
673675

674-
await nc.publish(f"tests.3", b"bar")
676+
await nc.publish("tests.3", b"bar")
675677
await nc.flush()
676678

677679
# FIXME: this test is flaky
@@ -717,8 +719,8 @@ async def test_subscribe_next_msg(self):
717719
await sub.next_msg(timeout=0.5)
718720

719721
# Send again a couple of messages.
720-
await nc.publish(f"tests.2", b"bar")
721-
await nc.publish(f"tests.3", b"bar")
722+
await nc.publish("tests.2", b"bar")
723+
await nc.publish("tests.3", b"bar")
722724
await nc.flush()
723725
msg = await sub.next_msg()
724726
self.assertEqual("tests.2", msg.subject)
@@ -2809,7 +2811,7 @@ async def test_drain_cancelled_errors_raised(self):
28092811
async def cb(msg):
28102812
await asyncio.sleep(20)
28112813

2812-
sub = await nc.subscribe(f"test.sub", cb=cb)
2814+
sub = await nc.subscribe("test.sub", cb=cb)
28132815
await nc.publish("test.sub")
28142816
await nc.publish("test.sub")
28152817
await asyncio.sleep(0.1)

0 commit comments

Comments
 (0)