Skip to content

Commit be1756f

Browse files
authored
clean(oculus): Standardize linting for oculus sub repository. (#4734)
1 parent 8700b6d commit be1756f

File tree

10 files changed

+180
-64
lines changed

10 files changed

+180
-64
lines changed

servers/oculus/makefile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
install:
2-
poetry install
1+
code-cleanup:
2+
poetry run black .
3+
poetry run ruff check --unsafe-fixes --fix src/ tests/
4+
poetry run ruff format src/ tests/
35

46
test:
57
poetry run pytest -sv
68

79
typecheck:
810
poetry run mypy src/
9-
10-
lint:
11-
poetry run ruff check src/
12-
13-
format:
14-
poetry run ruff format src/

servers/oculus/poetry.lock

Lines changed: 98 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

servers/oculus/pyproject.toml

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ fern-ai = {path = "../fai", develop = true}
2121
[tool.poetry.group.dev.dependencies]
2222
pytest = "^8.0.0"
2323
mypy = "^1.8.0"
24-
ruff = "^0.3.0"
24+
black = "^24.3.0"
25+
isort = "^5.13.2"
26+
ruff = "^0.1.0"
2527

2628
[tool.poetry.scripts]
2729
oculus = "oculus.__main__:main"
@@ -30,17 +32,47 @@ oculus = "oculus.__main__:main"
3032
requires = ["poetry-core"]
3133
build-backend = "poetry.core.masonry.api"
3234

33-
[tool.ruff]
34-
line-length = 120
35-
target-version = "py311"
36-
37-
[tool.ruff.lint]
38-
select = ["E", "F", "I", "UP"]
39-
4035
[tool.mypy]
4136
python_version = "3.11"
4237
strict = true
4338
warn_return_any = true
4439
warn_unused_configs = true
4540
mypy_path = "src"
4641
explicit_package_bases = true
42+
43+
[tool.ruff]
44+
line-length = 120
45+
target-version = "py311"
46+
47+
[tool.ruff.lint]
48+
select = [
49+
"E", # pycodestyle errors
50+
"W", # pycodestyle warnings
51+
"F", # pyflakes
52+
"I", # isort
53+
"UP", # pyupgrade
54+
]
55+
ignore = []
56+
57+
[tool.ruff.lint.isort]
58+
known-first-party = ["fai", "tests", "utils"]
59+
60+
[tool.ruff.format]
61+
quote-style = "double"
62+
indent-style = "space"
63+
64+
[tool.black]
65+
line-length = 120
66+
67+
[tool.isort]
68+
multi_line_output = 3
69+
include_trailing_comma = true
70+
force_grid_wrap = 2
71+
line_length = 120
72+
profile = "black"
73+
use_parentheses = true
74+
known_first_party = ["fai", "tests", "utils"]
75+
src_paths = ["src"]
76+
77+
[tool.autoflake]
78+
in-place = true

servers/oculus/src/oculus/__main__.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from pathlib import Path
44

55
from dotenv import load_dotenv
6-
76
from oculus.framework.runner import EvaluationRunner
87
from oculus.integrations.fai_integration import create_fai_answer_function
98

@@ -50,10 +49,10 @@ def main() -> int:
5049

5150
if not suite_path.exists():
5251
print(f"Error: Suite directory not found: {suite_path}", file=sys.stderr)
53-
print(f"\nExpected structure:", file=sys.stderr)
52+
print("\nExpected structure:", file=sys.stderr)
5453
print(f" {suite_path}/", file=sys.stderr)
55-
print(f" questions/", file=sys.stderr)
56-
print(f" question_0.json", file=sys.stderr)
54+
print(" questions/", file=sys.stderr)
55+
print(" question_0.json", file=sys.stderr)
5756
return 1
5857

5958
questions_dir = suite_path / "questions"
@@ -90,15 +89,15 @@ def main() -> int:
9089
return 0
9190

9291
except ImportError as e:
93-
print(f"\nError: Failed to import required modules", file=sys.stderr)
92+
print("\nError: Failed to import required modules", file=sys.stderr)
9493
print(f"{e}", file=sys.stderr)
95-
print(f"\nMake sure:", file=sys.stderr)
96-
print(f" 1. FAI dependencies are installed (poetry install in servers/fai)", file=sys.stderr)
97-
print(f" 2. PYTHONPATH includes the FAI source directory", file=sys.stderr)
94+
print("\nMake sure:", file=sys.stderr)
95+
print(" 1. FAI dependencies are installed (poetry install in servers/fai)", file=sys.stderr)
96+
print(" 2. PYTHONPATH includes the FAI source directory", file=sys.stderr)
9897
return 1
9998

10099
except Exception as e:
101-
print(f"\nError: Evaluation failed", file=sys.stderr)
100+
print("\nError: Evaluation failed", file=sys.stderr)
102101
print(f"{e}", file=sys.stderr)
103102
import traceback
104103

servers/oculus/src/oculus/evaluators/llm_judge.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from oculus.utils.anthropic_utils import generate_with_claude
32
from pydantic import BaseModel
43

servers/oculus/src/oculus/framework/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from pydantic import BaseModel, Field
1+
from pydantic import (
2+
BaseModel,
3+
Field,
4+
)
25

36

47
class Question(BaseModel):

servers/oculus/src/oculus/framework/runner.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
import concurrent.futures
2+
from collections.abc import Callable
23
from datetime import datetime
34
from pathlib import Path
4-
from typing import Callable, Optional
55

66
from oculus.evaluators.llm_judge import evaluate_answer
7-
from oculus.framework.models import Answer, Evaluation, EvaluationMetrics, EvaluationRun, Question
8-
from oculus.utils.file_utils import load_json, load_json_files, save_json
7+
from oculus.framework.models import (
8+
Answer,
9+
Evaluation,
10+
EvaluationMetrics,
11+
EvaluationRun,
12+
Question,
13+
)
14+
from oculus.utils.file_utils import (
15+
load_json,
16+
save_json,
17+
)
918

1019

1120
class EvaluationRunner:
1221
def __init__(
1322
self,
1423
suite_name: str,
1524
suite_path: Path,
16-
run_id: Optional[str] = None,
25+
run_id: str | None = None,
1726
max_workers: int = 16,
1827
):
1928
self.suite_name = suite_name

servers/oculus/src/oculus/generators/openapi_questions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Optional
1+
from typing import Any
22

33
QUESTION_TEMPLATES = [
44
"Tell me about the {method} {path} endpoint.",
@@ -12,7 +12,7 @@
1212
]
1313

1414

15-
def extract_operation_id(spec: dict[str, Any], method: str, path: str) -> Optional[str]:
15+
def extract_operation_id(spec: dict[str, Any], method: str, path: str) -> str | None:
1616
for path_key, path_item in spec.get("paths", {}).items():
1717
if path_key == path:
1818
operation = path_item.get(method, {})
@@ -21,7 +21,7 @@ def extract_operation_id(spec: dict[str, Any], method: str, path: str) -> Option
2121
return None
2222

2323

24-
def extract_first_request_property(spec: dict[str, Any], method: str, path: str) -> Optional[str]:
24+
def extract_first_request_property(spec: dict[str, Any], method: str, path: str) -> str | None:
2525
for path_key, path_item in spec.get("paths", {}).items():
2626
if path_key == path:
2727
operation = path_item.get(method, {})
@@ -38,7 +38,7 @@ def extract_first_request_property(spec: dict[str, Any], method: str, path: str)
3838
return None
3939

4040

41-
def extract_first_response_property(spec: dict[str, Any], method: str, path: str) -> Optional[str]:
41+
def extract_first_response_property(spec: dict[str, Any], method: str, path: str) -> str | None:
4242
for path_key, path_item in spec.get("paths", {}).items():
4343
if path_key == path:
4444
operation = path_item.get(method, {})

0 commit comments

Comments
 (0)