Skip to content

Commit 798e59e

Browse files
chore/ruff formatting (#128)
Why === Breaking out ruff changes from #123 What changed ============ Separation of concerns, increasing revertability Test plan ========= CI
1 parent 7ce86bd commit 798e59e

File tree

10 files changed

+39
-95
lines changed

10 files changed

+39
-95
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
2525
- name: Format check
2626
run: |
27-
uv run black --check .
27+
uv run ruff format --check .
2828
2929
- name: Lint check
3030
run: |

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
lint:
2-
uv run black --check .
2+
uv run ruff format --check .
33
uv run ruff check .
44
uv run mypy .
55
uv run pyright-python .
6+
uv run deptry .
67

78
format:
8-
uv run black .
9+
uv run ruff format .
910
uv run ruff check . --fix

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ classifiers = [
2222
dependencies = [
2323
"pydantic==2.9.2",
2424
"aiochannel>=1.2.1",
25-
"black>=23.11,<25.0",
2625
"grpcio-tools>=1.59.3",
2726
"grpcio>=1.59.3",
2827
"msgpack-types>=0.3.0",
@@ -63,6 +62,7 @@ disallow_untyped_defs = true
6362
warn_return_any = true
6463

6564
[tool.pytest.ini_options]
65+
asyncio_default_fixture_loop_scope = "function"
6666
asyncio_mode = "auto" # auto-detect async tests/fixtures
6767
addopts = "--tb=short"
6868
env = [

replit_river/codegen/client.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import re
3+
import subprocess
34
from pathlib import Path
45
from textwrap import dedent
56
from typing import (
@@ -16,7 +17,6 @@
1617
cast,
1718
)
1819

19-
import black
2020
from pydantic import BaseModel, Field, RootModel
2121

2222
from replit_river.codegen.format import reindent
@@ -831,9 +831,14 @@ def __init__(self, client: river.Client[Any]):
831831
exclude_none=True,
832832
)
833833
"""
834-
if isinstance(
835-
procedure.input, RiverConcreteType
836-
) and procedure.input.type not in ["object", "array"]:
834+
if (
835+
(
836+
isinstance(procedure.input, RiverConcreteType)
837+
and procedure.input.type not in ["object", "array"]
838+
)
839+
or isinstance(procedure.input, RiverNotType)
840+
or procedure.input is None
841+
):
837842
render_input_method = "lambda x: x"
838843

839844
assert (
@@ -1077,11 +1082,10 @@ def schema_to_river_client_codegen(
10771082
module_path.parent.mkdir(mode=0o755, parents=True, exist_ok=True)
10781083
with open(module_path, "w") as f:
10791084
try:
1080-
f.write(
1081-
black.format_str(
1082-
contents, mode=black.FileMode(string_normalization=False)
1083-
)
1085+
popen = subprocess.Popen(
1086+
["ruff", "format", "-"], stdin=subprocess.PIPE, stdout=f
10841087
)
1088+
popen.communicate(contents.encode())
10851089
except:
10861090
f.write(contents)
10871091
raise

replit_river/codegen/server.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import collections
22
import os.path
3+
import subprocess
34
import tempfile
45
from textwrap import dedent
56
from typing import DefaultDict, List, Sequence
67

7-
import black
88
import grpc_tools # type: ignore
99
from google.protobuf import descriptor_pb2
1010
from google.protobuf.descriptor import FieldDescriptor
@@ -412,11 +412,11 @@ def proto_to_river_server_codegen(
412412
with open(descriptor_path, "rb") as f:
413413
fds.ParseFromString(f.read())
414414
pb_module_name = os.path.splitext(os.path.basename(proto_path))[0]
415-
contents = black.format_str(
416-
"\n".join(generate_river_module(module_name, pb_module_name, fds)),
417-
mode=black.FileMode(string_normalization=False),
418-
)
415+
contents = "\n".join(generate_river_module(module_name, pb_module_name, fds))
419416
os.makedirs(target_directory, exist_ok=True)
420417
output_path = f"{target_directory}/{pb_module_name}_river.py"
421418
with open(output_path, "w") as f:
422-
f.write(contents)
419+
popen = subprocess.Popen(
420+
["ruff", "format", "-"], stdin=subprocess.PIPE, stdout=f
421+
)
422+
popen.communicate(contents.encode())

scripts/format.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

scripts/lint.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/river_fixtures/clientserver.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@ async def client(
3838
transport_options: TransportOptions,
3939
no_logging_error: NoErrors,
4040
) -> AsyncGenerator[Client, None]:
41-
async def websocket_uri_factory() -> UriAndMetadata[None]:
42-
return {
43-
"uri": "ws://localhost:8765",
44-
"metadata": None,
45-
}
46-
4741
try:
48-
async with serve(server.serve, "localhost", 8765):
42+
async with serve(server.serve, "127.0.0.1") as binding:
43+
sockets = list(binding.sockets)
44+
assert len(sockets) == 1, "Too many sockets!"
45+
socket = sockets[0]
46+
47+
async def websocket_uri_factory() -> UriAndMetadata[None]:
48+
return {
49+
"uri": "ws://%s:%d" % socket.getsockname(),
50+
"metadata": None,
51+
}
52+
4953
client: Client[Literal[None]] = Client[None](
5054
uri_and_metadata_factory=websocket_uri_factory,
5155
client_id="test_client",

tests/test_handshake.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ def transport_options() -> TransportOptions:
1717
@pytest.mark.asyncio
1818
@pytest.mark.parametrize("handlers", [{}])
1919
async def test_handshake_timeout(server: Server) -> None:
20-
async with serve(server.serve, "localhost", 8765):
20+
async with serve(server.serve, "127.0.0.1") as binding:
21+
sockets = list(binding.sockets)
22+
assert len(sockets) == 1, "Too many sockets!"
23+
socket = sockets[0]
2124
start = time()
22-
ws = await websockets.connect("ws://localhost:8765")
25+
ws = await websockets.connect("ws://%s:%d" % socket.getsockname())
2326
with pytest.raises(ConnectionClosedOK):
2427
await ws.recv()
2528
diff = time() - start

uv.lock

Lines changed: 0 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)