Skip to content

Commit 6cb406b

Browse files
authored
Merge pull request #725 from guardrails-ai/karan/ruffify
Replace black, isort and flake8 with ruff
2 parents 6de5641 + 119815e commit 6cb406b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+739
-769
lines changed

.flake8

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

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
run: |
4141
make full
4242
43-
- name: Lint with isort, black, docformatter, flake8
43+
- name: Lint with ruff
4444
run: |
4545
make lint
4646

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.4.1
4+
hooks:
5+
# Performs ruff check with safe fixes
6+
- id: ruff
7+
name: ruff
8+
description: "Run 'ruff' for linting"
9+
args: ["--fix"]
10+
# Performs ruff format
11+
- id: ruff-format
12+
name: ruff-format
13+
description: "Run 'ruff format' for formatting"

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ PYDANTIC_VERSION_MAJOR := $(shell poetry run python -c 'import pydantic; print(p
88
TYPING_CMD := type-pydantic-v$(PYDANTIC_VERSION_MAJOR)-openai-v$(OPENAI_VERSION_MAJOR)
99

1010
autoformat:
11-
poetry run black guardrails/ tests/
12-
poetry run isort --atomic guardrails/ tests/
11+
poetry run ruff check guardrails/ tests/ --fix
12+
poetry run ruff format guardrails/ tests/
1313
poetry run docformatter --in-place --recursive guardrails tests
1414

1515
.PHONY: type
@@ -37,9 +37,8 @@ type-pydantic-v2-openai-v1:
3737
rm pyrightconfig.json
3838

3939
lint:
40-
poetry run isort -c guardrails/ tests/
41-
poetry run black guardrails/ tests/ --check
42-
poetry run flake8 guardrails/ tests/
40+
poetry run ruff check guardrails/ tests/
41+
poetry run ruff format guardrails/ tests/ --check
4342

4443
test:
4544
poetry run pytest tests/
@@ -66,6 +65,7 @@ docs-deploy:
6665

6766
dev:
6867
poetry install
68+
poetry run pre-commit install
6969

7070
full:
7171
poetry install --all-extras

guardrails/classes/history/call.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ def validation_response(self) -> Optional[Union[str, Dict, ReAsk]]:
227227
self.inputs.full_schema_reask
228228
or number_of_iterations < 2
229229
or isinstance(
230-
self.iterations.last.validation_response, ReAsk # type: ignore
230+
self.iterations.last.validation_response, # type: ignore
231+
ReAsk, # type: ignore
231232
)
232233
or isinstance(self.iterations.last.validation_response, str) # type: ignore
233234
):
@@ -410,9 +411,7 @@ def tree(self) -> Tree:
410411
title="Validated Output",
411412
style="on #F0FFF0",
412413
)
413-
tree.children[
414-
-1
415-
].label.renderable._renderables = previous_panels + ( # type: ignore
414+
tree.children[-1].label.renderable._renderables = previous_panels + ( # type: ignore
416415
validated_outcome_panel,
417416
)
418417

guardrails/classes/history/iteration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def status(self) -> str:
166166
@property
167167
def rich_group(self) -> Group:
168168
def create_msg_history_table(
169-
msg_history: Optional[List[Dict[str, Prompt]]]
169+
msg_history: Optional[List[Dict[str, Prompt]]],
170170
) -> Union[str, Table]:
171171
if msg_history is None:
172172
return "No message history."

guardrails/cli/hub/create_validator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ruff: noqa: E501
12
import os
23
from datetime import date
34
from string import Template

guardrails/cli/hub/install.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ def install(
245245

246246
console.print(f"\nInstalling {package_uri}...\n")
247247
logger.log(
248-
level=LEVELS.get("SPAM"), msg=f"Installing {package_uri}..." # type: ignore
248+
level=LEVELS.get("SPAM"), # type: ignore
249+
msg=f"Installing {package_uri}...",
249250
)
250251

251252
# Validation

guardrails/cli/logger.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import logging
22
import os
33

4-
os.environ[
5-
"COLOREDLOGS_LEVEL_STYLES"
6-
] = "spam=white,faint;success=green,bold;debug=magenta;verbose=blue;notice=cyan,bold;warning=yellow;error=red;critical=background=red" # noqa
4+
os.environ["COLOREDLOGS_LEVEL_STYLES"] = (
5+
"spam=white,faint;success=green,bold;debug=magenta;verbose=blue;notice=cyan,bold;warning=yellow;error=red;critical=background=red" # noqa
6+
)
77
LEVELS = {
88
"SPAM": 5,
99
"VERBOSE": 15,

guardrails/document_store.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ class DocumentStoreBase(ABC):
5252
The store can be queried by text for similar documents.
5353
"""
5454

55-
def __init__(self, vector_db: VectorDBBase, path: Optional[str] = None):
56-
...
55+
def __init__(self, vector_db: VectorDBBase, path: Optional[str] = None): ...
5756

5857
@abstractmethod
5958
def add_document(self, document: Document) -> None:
@@ -182,9 +181,7 @@ class RealSqlDocument(Base):
182181
__tablename__ = "documents"
183182

184183
id: Mapped[int] = mapped_column(primary_key=True) # type: ignore
185-
page_num: Mapped[int] = mapped_column(
186-
sqlalchemy.Integer, primary_key=True
187-
) # type: ignore
184+
page_num: Mapped[int] = mapped_column(sqlalchemy.Integer, primary_key=True) # type: ignore
188185
text: Mapped[str] = mapped_column(sqlalchemy.String) # type: ignore
189186
meta: Mapped[dict] = mapped_column(sqlalchemy.PickleType) # type: ignore
190187
vector_index: Mapped[int] = mapped_column(sqlalchemy.Integer) # type: ignore

0 commit comments

Comments
 (0)