Skip to content

Commit 44dab31

Browse files
Berik AshimovBerik Ashimov
authored andcommitted
style: apply ruff format
1 parent d489abe commit 44dab31

9 files changed

Lines changed: 87 additions & 61 deletions

File tree

benchmarks/bench_cold_start.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ def main() -> None:
3636
print("=" * 40)
3737
for mod in modules:
3838
avg = bench_import_time(mod)
39-
print(f" {mod:<30s} {avg*1000:.1f}ms")
39+
print(f" {mod:<30s} {avg * 1000:.1f}ms")
4040
print()
4141

4242
# Compare with serverless-relevant: just the core
4343
print("Comparison:")
4444
for mod in ["json", "msgspec"]:
4545
avg = bench_import_time(mod)
46-
print(f" {mod:<30s} {avg*1000:.1f}ms")
46+
print(f" {mod:<30s} {avg * 1000:.1f}ms")
4747

4848

4949
if __name__ == "__main__":

benchmarks/bench_request_response.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ async def create_item(body: Item):
4343

4444
body = msgspec.json.encode({"name": "Widget", "price": 9.99})
4545
_bench_endpoint(
46-
app_body, "POST", "/items", body, "POST + body decode + JSON response",
46+
app_body,
47+
"POST",
48+
"/items",
49+
body,
50+
"POST + body decode + JSON response",
4751
extra_headers=[(b"content-type", b"application/json")],
4852
)
4953

benchmarks/bench_routing.py

Lines changed: 67 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,63 +12,87 @@
1212
def _make_handler():
1313
async def handler():
1414
pass
15+
1516
return handler
1617

1718

1819
def bench_routing():
1920
tree = RadixTree()
2021

2122
# Register realistic routes (REST API pattern)
22-
prefixes = ["users", "posts", "comments", "tags", "categories", "products", "orders", "payments"]
23+
prefixes = [
24+
"users",
25+
"posts",
26+
"comments",
27+
"tags",
28+
"categories",
29+
"products",
30+
"orders",
31+
"payments",
32+
]
2333
routes_registered = 0
2434

2535
for prefix in prefixes:
26-
tree.insert(Route(
27-
path=f"/{prefix}",
28-
handler=_make_handler(),
29-
methods=frozenset({"GET", "HEAD"}),
30-
name=f"list_{prefix}",
31-
))
32-
tree.insert(Route(
33-
path=f"/{prefix}",
34-
handler=_make_handler(),
35-
methods=frozenset({"POST"}),
36-
name=f"create_{prefix}",
37-
))
38-
tree.insert(Route(
39-
path=f"/{prefix}/{{id:int}}",
40-
handler=_make_handler(),
41-
methods=frozenset({"GET", "HEAD"}),
42-
name=f"get_{prefix}",
43-
))
44-
tree.insert(Route(
45-
path=f"/{prefix}/{{id:int}}",
46-
handler=_make_handler(),
47-
methods=frozenset({"PUT"}),
48-
name=f"update_{prefix}",
49-
))
50-
tree.insert(Route(
51-
path=f"/{prefix}/{{id:int}}",
52-
handler=_make_handler(),
53-
methods=frozenset({"DELETE"}),
54-
name=f"delete_{prefix}",
55-
))
36+
tree.insert(
37+
Route(
38+
path=f"/{prefix}",
39+
handler=_make_handler(),
40+
methods=frozenset({"GET", "HEAD"}),
41+
name=f"list_{prefix}",
42+
)
43+
)
44+
tree.insert(
45+
Route(
46+
path=f"/{prefix}",
47+
handler=_make_handler(),
48+
methods=frozenset({"POST"}),
49+
name=f"create_{prefix}",
50+
)
51+
)
52+
tree.insert(
53+
Route(
54+
path=f"/{prefix}/{{id:int}}",
55+
handler=_make_handler(),
56+
methods=frozenset({"GET", "HEAD"}),
57+
name=f"get_{prefix}",
58+
)
59+
)
60+
tree.insert(
61+
Route(
62+
path=f"/{prefix}/{{id:int}}",
63+
handler=_make_handler(),
64+
methods=frozenset({"PUT"}),
65+
name=f"update_{prefix}",
66+
)
67+
)
68+
tree.insert(
69+
Route(
70+
path=f"/{prefix}/{{id:int}}",
71+
handler=_make_handler(),
72+
methods=frozenset({"DELETE"}),
73+
name=f"delete_{prefix}",
74+
)
75+
)
5676
routes_registered += 5
5777

5878
# Also add some nested routes
5979
for prefix in prefixes[:4]:
60-
tree.insert(Route(
61-
path=f"/{prefix}/{{id:int}}/comments",
62-
handler=_make_handler(),
63-
methods=frozenset({"GET", "HEAD"}),
64-
name=f"{prefix}_comments",
65-
))
66-
tree.insert(Route(
67-
path=f"/{prefix}/{{id:int}}/comments/{{comment_id:int}}",
68-
handler=_make_handler(),
69-
methods=frozenset({"GET", "HEAD"}),
70-
name=f"{prefix}_comment_detail",
71-
))
80+
tree.insert(
81+
Route(
82+
path=f"/{prefix}/{{id:int}}/comments",
83+
handler=_make_handler(),
84+
methods=frozenset({"GET", "HEAD"}),
85+
name=f"{prefix}_comments",
86+
)
87+
)
88+
tree.insert(
89+
Route(
90+
path=f"/{prefix}/{{id:int}}/comments/{{comment_id:int}}",
91+
handler=_make_handler(),
92+
methods=frozenset({"GET", "HEAD"}),
93+
name=f"{prefix}_comment_detail",
94+
)
95+
)
7296
routes_registered += 2
7397

7498
print(f"Registered {routes_registered} routes across {len(prefixes)} resources\n")

benchmarks/bench_serialization.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ def bench_serialization():
8181
hawk_struct_time = time.perf_counter() - start
8282

8383
print(f"Small Struct:")
84-
print(f" HawkAPI (msgspec): {hawk_struct_time:.3f}s ({iterations / hawk_struct_time:,.0f} ops/sec)")
84+
print(
85+
f" HawkAPI (msgspec): {hawk_struct_time:.3f}s ({iterations / hawk_struct_time:,.0f} ops/sec)"
86+
)
8587
print(f" Speedup vs dict: {hawk_time / hawk_struct_time:.1f}x\n")
8688

8789
# --- Medium list (100 items) ---

benchmarks/competitive/runner.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ def _spawn_server(framework: str, port: int) -> subprocess.Popen[bytes]:
135135
)
136136

137137

138-
_LATENCY_RE = re.compile(
139-
r"Latency\s+([\d.]+)(\w+)\s+([\d.]+)(\w+)\s+([\d.]+)(\w+)\s+([\d.]+)%"
140-
)
138+
_LATENCY_RE = re.compile(r"Latency\s+([\d.]+)(\w+)\s+([\d.]+)(\w+)\s+([\d.]+)(\w+)\s+([\d.]+)%")
141139
_REQ_RE = re.compile(r"Requests/sec:\s+([\d.]+)")
142140
_TRANSFER_RE = re.compile(r"Transfer/sec:\s+([\d.]+\w+)")
143141
_LATENCY_DIST_RE = re.compile(r"\s+(\d+)%\s+([\d.]+)(\w+)")
@@ -191,9 +189,7 @@ def _wrk_lua_script(scenario: Scenario) -> str:
191189
"""Build a Lua script for non-GET wrk runs."""
192190
if scenario.method == "GET":
193191
return ""
194-
headers = "\n".join(
195-
f'wrk.headers["{k}"] = "{v}"' for k, v in (scenario.headers or {}).items()
196-
)
192+
headers = "\n".join(f'wrk.headers["{k}"] = "{v}"' for k, v in (scenario.headers or {}).items())
197193
body = (scenario.body or "").replace('"', '\\"')
198194
return f"""
199195
wrk.method = "{scenario.method}"

benchmarks/e2e/run_benchmarks.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ def main() -> None:
106106
print(f"\n--- {fw_name} ---")
107107
for scenario in scenarios:
108108
scope = _make_scope(scenario["method"], scenario["path"], scenario["body"])
109-
elapsed = loop.run_until_complete(
110-
_bench_asgi(app, scope, scenario["body"], iterations)
111-
)
109+
elapsed = loop.run_until_complete(_bench_asgi(app, scope, scenario["body"], iterations))
112110
per_req_us = (elapsed / iterations) * 1_000_000
113111
rps = iterations / elapsed
114112
results[fw_name][scenario["name"]] = per_req_us

hatch_build.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ def initialize(self, version: str, build_data: dict[str, Any]) -> None:
6464
force_include[absolute_path] = relative_target
6565

6666

67-
def _run_build_ext(
68-
project_root: str, extensions: list[Any]
69-
) -> list[tuple[str, str]]:
67+
def _run_build_ext(project_root: str, extensions: list[Any]) -> list[tuple[str, str]]:
7068
"""Drive setuptools' ``build_ext --inplace`` and return compiled .so paths.
7169
7270
Returns a list of ``(absolute_source_path, wheel_relative_target)`` pairs

src/hawkapi/routing/router.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ def _compute_trivial(
7878
return False
7979
if response_model is not None:
8080
return False
81-
if response_model_exclude_none or response_model_exclude_unset or response_model_exclude_defaults: # noqa: E501
81+
if (
82+
response_model_exclude_none
83+
or response_model_exclude_unset
84+
or response_model_exclude_defaults
85+
): # noqa: E501
8286
return False
8387
if deprecated:
8488
return False

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)