Skip to content

Commit 7c1d1f5

Browse files
Fix Makefile python executable and format codebase
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent ff4db9b commit 7c1d1f5

13 files changed

Lines changed: 88 additions & 49 deletions

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ Or:
5454
make test
5555
```
5656

57+
### Architecture guard suites
58+
59+
```bash
60+
make architecture-check
61+
```
62+
5763
### Full local CI parity
5864

5965
```bash

Makefile

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1-
.PHONY: install lint format-check format compile test build check ci
1+
.PHONY: install lint format-check format compile test architecture-check build check ci
2+
3+
PYTHON ?= python3
24

35
install:
4-
python -m pip install -e . pytest ruff build
6+
$(PYTHON) -m pip install -e . pytest ruff build
57

68
lint:
7-
python -m ruff check .
9+
$(PYTHON) -m ruff check .
810

911
format-check:
10-
python -m ruff format --check .
12+
$(PYTHON) -m ruff format --check .
1113

1214
format:
13-
python -m ruff format .
15+
$(PYTHON) -m ruff format .
1416

1517
test:
16-
python -m pytest -q
18+
$(PYTHON) -m pytest -q
19+
20+
architecture-check:
21+
$(PYTHON) -m pytest -q \
22+
tests/test_manager_model_dump_usage.py \
23+
tests/test_mapping_reader_usage.py \
24+
tests/test_mapping_keys_access_usage.py \
25+
tests/test_tool_mapping_reader_usage.py \
26+
tests/test_display_helper_usage.py
1727

1828
compile:
19-
python -m compileall -q hyperbrowser examples tests
29+
$(PYTHON) -m compileall -q hyperbrowser examples tests
2030

2131
build:
22-
python -m build
32+
$(PYTHON) -m build
2333

24-
check: lint format-check compile test build
34+
check: lint format-check compile architecture-check test build
2535

2636
ci: check

hyperbrowser/client/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,12 @@ def _build_url(self, path: str) -> str:
210210
normalized_path_only,
211211
normalized_path_query,
212212
_normalized_path_fragment,
213-
) = self._parse_url_components(normalized_path, component_label="normalized path")
214-
normalized_query_suffix = f"?{normalized_path_query}" if normalized_path_query else ""
213+
) = self._parse_url_components(
214+
normalized_path, component_label="normalized path"
215+
)
216+
normalized_query_suffix = (
217+
f"?{normalized_path_query}" if normalized_path_query else ""
218+
)
215219
decoded_path = ClientConfig._decode_url_component_with_limit(
216220
normalized_path_only, component_label="path"
217221
)

hyperbrowser/client/managers/response_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from typing import Any, Type, TypeVar
22

3-
from hyperbrowser.display_utils import format_string_key_for_error, normalize_display_text
3+
from hyperbrowser.display_utils import (
4+
format_string_key_for_error,
5+
normalize_display_text,
6+
)
47
from hyperbrowser.exceptions import HyperbrowserError
58
from hyperbrowser.mapping_utils import read_string_key_mapping
69

hyperbrowser/transport/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from abc import ABC, abstractmethod
22
from typing import Generic, Mapping, Optional, Type, TypeVar, Union
33

4-
from hyperbrowser.display_utils import format_string_key_for_error, normalize_display_text
4+
from hyperbrowser.display_utils import (
5+
format_string_key_for_error,
6+
normalize_display_text,
7+
)
58
from hyperbrowser.exceptions import HyperbrowserError
69
from hyperbrowser.mapping_utils import read_string_key_mapping
710

tests/test_client_timeout.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ def _raise_isfinite_error(value: float) -> bool:
163163
assert exc_info.value.original_error is not None
164164

165165

166-
def test_sync_client_wraps_unexpected_timeout_float_conversion_failures(
167-
):
166+
def test_sync_client_wraps_unexpected_timeout_float_conversion_failures():
168167
class _BrokenDecimal(Decimal):
169168
def __float__(self) -> float:
170169
raise RuntimeError("unexpected float conversion failure")
@@ -178,8 +177,7 @@ def __float__(self) -> float:
178177
assert isinstance(exc_info.value.original_error, RuntimeError)
179178

180179

181-
def test_async_client_wraps_unexpected_timeout_float_conversion_failures(
182-
):
180+
def test_async_client_wraps_unexpected_timeout_float_conversion_failures():
183181
class _BrokenDecimal(Decimal):
184182
def __float__(self) -> float:
185183
raise RuntimeError("unexpected float conversion failure")

tests/test_display_utils.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from hyperbrowser.display_utils import format_string_key_for_error, normalize_display_text
1+
from hyperbrowser.display_utils import (
2+
format_string_key_for_error,
3+
normalize_display_text,
4+
)
25

36

47
def test_normalize_display_text_keeps_valid_input():
@@ -7,15 +10,12 @@ def test_normalize_display_text_keeps_valid_input():
710

811
def test_normalize_display_text_replaces_control_characters_and_trims():
912
assert (
10-
normalize_display_text(" \nhello\tworld\r ", max_length=50)
11-
== "?hello?world?"
13+
normalize_display_text(" \nhello\tworld\r ", max_length=50) == "?hello?world?"
1214
)
1315

1416

1517
def test_normalize_display_text_truncates_long_values():
16-
assert (
17-
normalize_display_text("abcdefghij", max_length=7) == "... (truncated)"
18-
)
18+
assert normalize_display_text("abcdefghij", max_length=7) == "... (truncated)"
1919

2020

2121
def test_normalize_display_text_returns_empty_for_unreadable_inputs():
@@ -31,10 +31,7 @@ def test_normalize_display_text_returns_empty_for_non_string_inputs():
3131

3232

3333
def test_format_string_key_for_error_returns_normalized_key():
34-
assert (
35-
format_string_key_for_error(" \nkey\t ", max_length=20)
36-
== "?key?"
37-
)
34+
assert format_string_key_for_error(" \nkey\t ", max_length=20) == "?key?"
3835

3936

4037
def test_format_string_key_for_error_returns_blank_fallback_for_empty_keys():

tests/test_manager_model_dump_usage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
from pathlib import Path
33

44

5-
MANAGERS_DIR = Path(__file__).resolve().parents[1] / "hyperbrowser" / "client" / "managers"
5+
MANAGERS_DIR = (
6+
Path(__file__).resolve().parents[1] / "hyperbrowser" / "client" / "managers"
7+
)
68

79

810
def _manager_python_files() -> list[Path]:

tests/test_mapping_reader_usage.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ def _collect_mapping_reader_calls(module: ast.AST) -> list[int]:
3434
for node in ast.walk(module):
3535
if not isinstance(node, ast.Call):
3636
continue
37-
if isinstance(node.func, ast.Name) and node.func.id == "read_string_key_mapping":
37+
if (
38+
isinstance(node.func, ast.Name)
39+
and node.func.id == "read_string_key_mapping"
40+
):
3841
reader_calls.append(node.lineno)
3942
return reader_calls
4043

tests/test_mapping_utils.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def _read_mapping(mapping_value):
5454
mapping_value,
5555
expected_mapping_error="expected mapping",
5656
read_keys_error="failed keys",
57-
non_string_key_error_builder=lambda key: f"non-string key: {type(key).__name__}",
57+
non_string_key_error_builder=lambda key: (
58+
f"non-string key: {type(key).__name__}"
59+
),
5860
read_value_error_builder=lambda key_display: (
5961
f"failed value for '{key_display}'"
6062
),
@@ -84,25 +86,23 @@ def test_read_string_key_mapping_rejects_non_string_keys():
8486

8587

8688
def test_read_string_key_mapping_wraps_value_read_failures():
87-
with pytest.raises(
88-
HyperbrowserError, match="failed value for 'field'"
89-
) as exc_info:
89+
with pytest.raises(HyperbrowserError, match="failed value for 'field'") as exc_info:
9090
_read_mapping(_BrokenValueMapping())
9191

9292
assert isinstance(exc_info.value.original_error, RuntimeError)
9393

9494

9595
def test_read_string_key_mapping_preserves_hyperbrowser_value_failures():
96-
with pytest.raises(HyperbrowserError, match="custom value read failure") as exc_info:
96+
with pytest.raises(
97+
HyperbrowserError, match="custom value read failure"
98+
) as exc_info:
9799
_read_mapping(_HyperbrowserValueFailureMapping())
98100

99101
assert exc_info.value.original_error is None
100102

101103

102104
def test_read_string_key_mapping_falls_back_for_unreadable_key_display():
103-
with pytest.raises(
104-
HyperbrowserError, match="failed value for '<unreadable key>'"
105-
):
105+
with pytest.raises(HyperbrowserError, match="failed value for '<unreadable key>'"):
106106
read_string_key_mapping(
107107
_BrokenValueMapping(),
108108
expected_mapping_error="expected mapping",
@@ -180,9 +180,7 @@ def test_copy_mapping_values_by_string_keys_returns_selected_values():
180180

181181

182182
def test_copy_mapping_values_by_string_keys_wraps_value_read_failures():
183-
with pytest.raises(
184-
HyperbrowserError, match="failed value for 'field'"
185-
) as exc_info:
183+
with pytest.raises(HyperbrowserError, match="failed value for 'field'") as exc_info:
186184
copy_mapping_values_by_string_keys(
187185
_BrokenValueMapping(),
188186
["field"],
@@ -196,7 +194,9 @@ def test_copy_mapping_values_by_string_keys_wraps_value_read_failures():
196194

197195

198196
def test_copy_mapping_values_by_string_keys_preserves_hyperbrowser_failures():
199-
with pytest.raises(HyperbrowserError, match="custom value read failure") as exc_info:
197+
with pytest.raises(
198+
HyperbrowserError, match="custom value read failure"
199+
) as exc_info:
200200
copy_mapping_values_by_string_keys(
201201
_HyperbrowserValueFailureMapping(),
202202
["field"],
@@ -210,9 +210,7 @@ def test_copy_mapping_values_by_string_keys_preserves_hyperbrowser_failures():
210210

211211

212212
def test_copy_mapping_values_by_string_keys_falls_back_for_unreadable_key_display():
213-
with pytest.raises(
214-
HyperbrowserError, match="failed value for '<unreadable key>'"
215-
):
213+
with pytest.raises(HyperbrowserError, match="failed value for '<unreadable key>'"):
216214
copy_mapping_values_by_string_keys(
217215
_BrokenValueMapping(),
218216
["field"],

0 commit comments

Comments
 (0)