Skip to content

Commit b234a24

Browse files
authored
ci: move to ruff (#20)
1 parent 8393f81 commit b234a24

File tree

10 files changed

+499
-79
lines changed

10 files changed

+499
-79
lines changed

.pre-commit-config.yaml

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
default_language_version:
2+
python: "3.11"
13
repos:
24
- repo: https://github.com/pre-commit/pre-commit-hooks
35
rev: v4.4.0
@@ -9,50 +11,29 @@ repos:
911
- id: end-of-file-fixer
1012
exclude: "\\.idea/(.)*|test_data"
1113
- id: trailing-whitespace
12-
- repo: https://github.com/asottile/pyupgrade
13-
rev: v3.3.1
14+
- repo: https://github.com/charliermarsh/ruff-pre-commit
15+
rev: "v0.0.280"
1416
hooks:
15-
- id: pyupgrade
16-
args: ["--py311-plus"]
17-
- repo: https://github.com/pycqa/isort
18-
rev: 5.12.0
19-
hooks:
20-
- id: isort
17+
- id: ruff
18+
args: ["--fix"]
19+
exclude: "frameworks*"
2120
- repo: https://github.com/psf/black
22-
rev: 23.1.0
21+
rev: 23.7.0
2322
hooks:
2423
- id: black
2524
args: [--config=./pyproject.toml]
2625
- repo: https://github.com/codespell-project/codespell
27-
rev: v2.2.2
26+
rev: v2.2.5
2827
hooks:
2928
- id: codespell
3029
exclude: "test_data*"
3130
- repo: https://github.com/pre-commit/mirrors-prettier
32-
rev: "v3.0.0-alpha.6"
31+
rev: "v3.0.0"
3332
hooks:
3433
- id: prettier
3534
exclude: "test_data*"
36-
- repo: https://github.com/hadialqattan/pycln
37-
rev: v2.1.3
38-
hooks:
39-
- id: pycln
40-
args: [--config=pyproject.toml]
41-
- repo: https://github.com/pycqa/flake8
42-
rev: 6.0.0
43-
hooks:
44-
- id: flake8
45-
additional_dependencies:
46-
[
47-
"flake8-bugbear",
48-
"flake8-comprehensions",
49-
"flake8-mutable",
50-
"flake8-print",
51-
"flake8-simplify",
52-
]
53-
exclude: "frameworks*"
5435
- repo: https://github.com/pre-commit/mirrors-mypy
55-
rev: "v1.1.1"
36+
rev: "v1.4.1"
5637
hooks:
5738
- id: mypy
5839
exclude: "frameworks|test_data"

.sourcery.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
ignore:
2+
- .tox/
3+
- .venv/
4+
- dist/
5+
- node_modules/
6+
- vendor/
7+
- venv/
8+
9+
rule_settings:
10+
enable: [default]
11+
disable: [dont-import-test-modules]
12+
rule_types:
13+
- refactoring
14+
- suggestion
15+
- comment
16+
python_version: "3.11"
17+
18+
rules: []
19+
20+
metrics:
21+
quality_threshold: 25.0
22+
23+
github:
24+
ignore_labels:
25+
- sourcery-ignore
26+
- docs
27+
labels:
28+
- build-ignore
29+
request_review:
30+
origin: owner
31+
forked: author
32+
sourcery_branch: sourcery/{base_branch}
33+
34+
clone_detection:
35+
min_lines: 3
36+
min_duplicates: 2
37+
identical_clones_only: false
38+
39+
proxy:
40+
no_ssl_verify: false

asgi_bench/cli.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ def run(
5858
) -> None:
5959
if not frameworks:
6060
frameworks = FRAMEWORKS
61-
benchmark_modes: tuple[BenchmarkMode, ...] = ()
62-
if rps:
63-
benchmark_modes = ("rps",)
61+
benchmark_modes: tuple[BenchmarkMode, ...] = ("rps",) if rps else ()
6462
if latency:
6563
benchmark_modes = (*benchmark_modes, "latency")
6664

@@ -120,7 +118,7 @@ def run(
120118
@click.option("-P", "--plots", is_flag=True, help="output plots")
121119
def results_command(
122120
run_name: int | None,
123-
format: tuple[str, ...],
121+
format: tuple[str, ...], # noqa: A002
124122
percentile: tuple[str, ...],
125123
split_percentiles: bool,
126124
tolerance: float,

asgi_bench/results.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ def _data_for_plot(
106106

107107
if ret:
108108
data = sorted(ret, key=lambda r: r["target"])
109-
df = pd.DataFrame(data)
110-
return df
109+
return pd.DataFrame(data)
111110

112111
return None
113112

@@ -121,10 +120,7 @@ def _draw_plot(
121120
category: str | None = None,
122121
percentile: str | None = None,
123122
):
124-
if benchmark_mode == "rps":
125-
title = "Requests per second (higher is better)"
126-
else:
127-
title = "Latency (lower is better)"
123+
title = "Requests per second (higher is better)" if benchmark_mode == "rps" else "Latency (lower is better)"
128124

129125
df = df.query(f"category == '{category}'")
130126

@@ -149,8 +145,6 @@ def _draw_plot(
149145
height=280 * percentile_count if percentile_count > 1 else None,
150146
width=600 if percentile_count > 1 else None,
151147
labels={"score": "RPS", "endpoint_mode": "mode", "name": "", "target": "framework"},
152-
# hover_data=["stddev"],
153-
# color_discrete_map={target: COLOR_PALETTE[i] for i, target in enumerate(df["target"].unique())},
154148
)
155149

156150
for format_ in formats:
@@ -183,7 +177,7 @@ def make_plots(
183177
benchmark_modes: tuple[BenchmarkMode, ...] = ("rps", "latency")
184178

185179
for benchmark_mode in benchmark_modes:
186-
if not all(benchmark_mode in mode_results for mode_results in results.values()):
180+
if any(benchmark_mode not in mode_results for mode_results in results.values()):
187181
continue
188182
df = _data_for_plot(
189183
results, benchmark_mode, tolerance=tolerance, percentiles=percentiles, frameworks=frameworks
@@ -218,7 +212,7 @@ def _data_for_tables(
218212

219213
for benchmark_mode in benchmark_modes:
220214
acc_bench_mode_results = accumulated_results.setdefault(benchmark_mode, {})
221-
if not all(benchmark_mode in mode_results for mode_results in results.values()):
215+
if any(benchmark_mode not in mode_results for mode_results in results.values()):
222216
continue
223217
for framework, framework_results in results.items():
224218
if frameworks and framework not in frameworks:

asgi_bench/runner.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,7 @@ def _init_results_file(self) -> Path:
121121
return self.results_dir / f"run_{run_number}.json"
122122

123123
def _write_results(self, target: str, spec: TestSpec, results: dict[str, Any]) -> None:
124-
if not self.results_file.exists():
125-
current_results = {}
126-
else:
127-
current_results = json.loads(self.results_file.read_text())
124+
current_results = json.loads(self.results_file.read_text()) if self.results_file.exists() else {}
128125
current_results.setdefault(target, {})
129126
current_results[target].setdefault(spec.benchmark_mode, {})
130127
current_results[target][spec.benchmark_mode].setdefault(spec.endpoint_mode, {})

asgi_bench/spec.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class TestCategory:
5050
Endpoint(path="plaintext-100K", name="plaintext 100 kB"),
5151
Endpoint(path="plaintext-500K", name="plaintext 500 kB"),
5252
Endpoint(path="plaintext-1M", name="plaintext 1 MB"),
53-
# Endpoint(path="plaintext-5M", name="plaintext 5 MB"),
5453
],
5554
),
5655
TestCategory(
@@ -61,7 +60,6 @@ class TestCategory:
6160
Endpoint(path="json-100K", name="json 100 kB"),
6261
Endpoint(path="json-500K", name="json 500 kB"),
6362
Endpoint(path="json-1M", name="json 1 MB"),
64-
# Endpoint(path="json-5M", name="json 5 MB"),
6563
],
6664
),
6765
TestCategory(
@@ -233,7 +231,7 @@ def make_spec(
233231
slug_name=f"{endpoint_mode}-{endpoint.path.split('?')[0]}",
234232
is_supported=(
235233
framework_name in category.frameworks
236-
and endpoint.supports_framework(framework_name, endpoint_mode) # noqa: W503
234+
and endpoint.supports_framework(framework_name, endpoint_mode)
237235
),
238236
body_file=endpoint.body_file,
239237
)

asgi_bench/types.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
]
1818
BenchmarkMode = Literal["rps", "latency"]
1919
VersionPrefix = Literal["pip", "git", "docker", "file"]
20-
Framework = Literal["starlite", "starlette", "fastapi", "sanic", "blacksheep"]
20+
Framework = Literal["starlite", "starlette", "fastapi", "sanic", "blacksheep", "quart", "litestar"]
2121

2222

2323
@dataclass
@@ -89,9 +89,7 @@ def image_tag(self) -> str:
8989

9090
@property
9191
def build_stage_image(self) -> str | None:
92-
if self.is_docker_target:
93-
return self.typed_version[1]
94-
return None
92+
return self.typed_version[1] if self.is_docker_target else None
9593

9694
@property
9795
def version_name(self) -> str:
@@ -118,16 +116,12 @@ def pip_package(self) -> str:
118116
from .spec import FRAMEWORK_REPOS
119117

120118
return f"git+{FRAMEWORK_REPOS[self.name]}@{version}"
121-
elif prefix == "file":
122-
return version
123-
return f"{self.name}=={self.version}"
119+
return version if prefix == "file" else f"{self.name}=={self.version}"
124120

125121
@property
126122
def extra_requirements(self) -> list[str]:
127123
path = self.path.parent / f"requirements-{self.name}.txt"
128-
if path.exists():
129-
return path.read_text().splitlines()
130-
return []
124+
return path.read_text().splitlines() if path.exists() else []
131125

132126
@property
133127
def pip_install_targets(self) -> str:

asgi_bench/util.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ def get_error_percentage(test_result: TestResult) -> float:
1515
success_count = get_success_response_count(test_result)
1616
error_count = get_error_response_count(test_result)
1717
total_count = success_count + error_count
18-
if not error_count:
19-
return 0
20-
return 100 * (error_count / total_count)
18+
return 100 * (error_count / total_count) if error_count else 0
2119

2220

2321
def has_no_responses(test_result: TestResult) -> bool:
2422
return not get_error_response_count(test_result) + get_success_response_count(test_result)
2523

2624

27-
template_env = jinja2.Environment(loader=jinja2.FileSystemLoader("templates"))
25+
template_env = jinja2.Environment(loader=jinja2.FileSystemLoader("templates"), autoescape=True)

0 commit comments

Comments
 (0)