Skip to content

Commit c2f9df2

Browse files
Replace black/flake8/isort with ruff and bump pre-commit hooks
- Replace black, flake8, isort, pycln with ruff for linting and formatting - Bump pre-commit hooks: ruff-pre-commit v0.15.1, uv-pre-commit 0.10.2, docformatter v1.7.7 - Fix deprecated default_stages: 'commit' -> 'pre-commit' - Bump deps: ruff>=0.15.0, pre-commit>=4.0.0 (dropping autopep8, black, flake8, flake8-pyproject, isort) - Update CI: astral-sh/setup-uv@v7, remove separate setup-python step - Apply ruff formatting to source and tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d612306 commit c2f9df2

File tree

8 files changed

+64
-215
lines changed

8 files changed

+64
-215
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@ jobs:
1717
with:
1818
ref: ${{ github.event.release.tag_name }}
1919

20-
- uses: actions/setup-python@v5
21-
with:
22-
python-version: "3.12"
23-
2420
- name: Install uv
25-
uses: astral-sh/setup-uv@v5
21+
uses: astral-sh/setup-uv@v7
2622
with:
27-
version: "0.6.14"
23+
python-version: "3.12"
24+
enable-cache: true
2825

2926
- name: Build package
3027
run: uv build

.pre-commit-config.yaml

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
default_language_version:
77
python: python3
88
default_stages:
9-
- commit
9+
- pre-commit
1010
repos:
1111
- repo: https://github.com/pre-commit/pre-commit-hooks
1212
rev: v4.5.0
@@ -48,46 +48,14 @@ repos:
4848
hooks:
4949
- id: actionlint-docker
5050
args: [-ignore, 'label ".+" is unknown']
51-
- repo: https://github.com/psf/black
52-
rev: 24.2.0
51+
- repo: https://github.com/astral-sh/ruff-pre-commit
52+
rev: v0.15.1
5353
hooks:
54-
- id: black
55-
args: [--config=pyproject.toml, -l 88]
56-
language: system
57-
exclude: |
58-
(?x)^(
59-
pkgs/unstract-flags/src/unstract/flags/evaluation_.*\.py|
60-
)$
61-
- repo: https://github.com/pycqa/flake8
62-
rev: 7.0.0
63-
hooks:
64-
- id: flake8
65-
args: [--max-line-length=88]
66-
exclude: |
67-
(?x)^(
68-
.*migrations/.*\.py|
69-
unstract-core/tests/.*|
70-
pkgs/unstract-flags/src/unstract/flags/evaluation_.*\.py|
71-
)$
72-
- repo: https://github.com/pycqa/isort
73-
rev: 5.13.2
74-
hooks:
75-
- id: isort
76-
files: "\\.(py)$"
77-
args:
78-
[
79-
"--profile",
80-
"black",
81-
"--filter-files",
82-
--settings-path=pyproject.toml,
83-
]
84-
- repo: https://github.com/hadialqattan/pycln
85-
rev: v2.4.0
86-
hooks:
87-
- id: pycln
88-
args: [--config=pyproject.toml]
54+
- id: ruff
55+
args: [--fix]
56+
- id: ruff-format
8957
- repo: https://github.com/pycqa/docformatter
90-
rev: v1.7.5
58+
rev: v1.7.7
9159
hooks:
9260
- id: docformatter
9361
# - repo: https://github.com/MarcoGorelli/absolufy-imports
@@ -155,6 +123,6 @@ repos:
155123
- id: markdownlint-fix
156124
args: [--disable, MD013]
157125
- repo: https://github.com/astral-sh/uv-pre-commit
158-
rev: 0.6.14
126+
rev: 0.10.2
159127
hooks:
160128
- id: uv-lock

pyproject.toml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,18 @@ test = [
5050
"python-dotenv>=1.0.0",
5151
]
5252
lint = [
53-
"autopep8~=2.0.2",
54-
"black~=23.3.0",
53+
"ruff>=0.15.0",
5554
"docutils~=0.20.1",
56-
"flake8~=6.0.0",
57-
"flake8-pyproject~=1.2.2",
58-
"isort~=5.12.0",
59-
"pre-commit~=3.3.1",
55+
"pre-commit>=4.0.0",
6056
"yamllint>=1.35.1",
6157
"mypy~=1.10.0",
6258
]
6359

64-
[tool.isort]
65-
line_length = 88
66-
multi_line_output = 3
67-
include_trailing_comma = true
68-
force_grid_wrap = 0
69-
use_parentheses = true
70-
ensure_newline_before_comments = true
71-
profile = "black"
60+
[tool.ruff]
61+
line-length = 88
7262

73-
[tool.flake8]
74-
max-line-length = 88
63+
[tool.ruff.lint]
64+
select = ["E", "F", "W", "I"]
7565

7666
[tool.pytest.ini_options]
7767
env_files = ["tests/.env"]

src/unstract/api_deployments/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__version__ = "1.1.0"
22

3-
from .client import APIDeploymentsClient
3+
from .client import APIDeploymentsClient as APIDeploymentsClient
44

55

66
def get_sdk_version():

src/unstract/api_deployments/client.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ def __call__(self, retry_state: RetryCallState) -> float:
6666
outcome = retry_state.outcome
6767
if outcome and not outcome.failed:
6868
response = outcome.result()
69-
if (
70-
response is not None
71-
and getattr(response, "status_code", None) == 429
72-
):
69+
if response is not None and getattr(response, "status_code", None) == 429:
7370
retry_after = response.headers.get("Retry-After")
7471
if retry_after is not None:
7572
try:
@@ -209,8 +206,7 @@ def _before_sleep(retry_state: RetryCallState):
209206
if outcome.failed:
210207
exc = outcome.exception()
211208
self.logger.warning(
212-
"%s during request to %s. Retrying in %.1fs "
213-
"(attempt %d/%d).",
209+
"%s during request to %s. Retrying in %.1fs (attempt %d/%d).",
214210
type(exc).__name__,
215211
url,
216212
delay,
@@ -220,8 +216,7 @@ def _before_sleep(retry_state: RetryCallState):
220216
else:
221217
response = outcome.result()
222218
self.logger.warning(
223-
"Request to %s returned %d. Retrying in %.1fs "
224-
"(attempt %d/%d).",
219+
"Request to %s returned %d. Retrying in %.1fs (attempt %d/%d).",
225220
url,
226221
response.status_code,
227222
delay,
@@ -263,9 +258,7 @@ def _retry_error_callback(retry_state: RetryCallState):
263258
jitter=self.jitter,
264259
),
265260
retry=(
266-
retry_if_result(
267-
lambda r: self._is_retryable_status(r.status_code)
268-
)
261+
retry_if_result(lambda r: self._is_retryable_status(r.status_code))
269262
| retry_if_exception_type((ConnectionError, Timeout))
270263
),
271264
before_sleep=_before_sleep,

src/unstract/api_deployments/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def redact_key(api_key: str, reveal_length=4) -> str:
55
66
Args:
77
api_key (str): API key to redact
8-
reveal_length (int): Number of characters to reveal from the start of the key
8+
reveal_length (int): Number of characters to reveal from the start
99
1010
Returns:
1111
str: Redacted API key

tests/test_retry.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,16 @@ def test_default_retries_504(self, client):
108108
def test_default_retries_any_5xx(self, client):
109109
"""Any 5xx status code should be retried by default."""
110110
for code in (500, 501, 502, 503, 504, 507, 511, 599):
111-
assert (
112-
client._is_retryable_status(code) is True
113-
), f"Expected {code} retryable"
111+
assert client._is_retryable_status(code) is True, (
112+
f"Expected {code} retryable"
113+
)
114114

115115
def test_default_no_retry_4xx_except_429(self, client):
116116
"""4xx codes (except 429) should not be retried by default."""
117117
for code in (400, 401, 403, 404, 405, 408, 422):
118-
assert (
119-
client._is_retryable_status(code) is False
120-
), f"Expected {code} not retryable"
118+
assert client._is_retryable_status(code) is False, (
119+
f"Expected {code} not retryable"
120+
)
121121

122122
def test_default_no_retry_2xx(self, client):
123123
assert client._is_retryable_status(200) is False
@@ -203,9 +203,7 @@ def test_exception_outcome_uses_exponential(self):
203203
wait = _WaitRetryAfterOrExponentialJitter(
204204
initial=2.0, max=60.0, exp_base=2.0, jitter=1.0
205205
)
206-
rs = self._make_retry_state(
207-
attempt_number=1, exception=ConnectionError("fail")
208-
)
206+
rs = self._make_retry_state(attempt_number=1, exception=ConnectionError("fail"))
209207
delay = wait(rs)
210208
assert 2.0 <= delay <= 3.0
211209

0 commit comments

Comments
 (0)