Skip to content

Commit 6256449

Browse files
authored
fix: linter issues
1 parent f19f014 commit 6256449

File tree

16 files changed

+100
-70
lines changed

16 files changed

+100
-70
lines changed

Makefile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: up down clean-volumes help test setup clean-env
1+
.PHONY: up down clean-volumes help test setup clean-env lint
22

33
# Default target
44
.DEFAULT_GOAL := help
@@ -118,6 +118,22 @@ test:
118118
@echo "All tests passed."
119119
@echo ""
120120

121+
# Lint fix flag - set to 'true' to auto-fix issues
122+
# Usage: make lint fix=true
123+
fix ?= false
124+
125+
## lint: Run Ruff linter (use fix=true to auto-fix)
126+
lint:
127+
@echo ""
128+
@echo "Running Ruff linter..."
129+
@if [ "$(fix)" = "true" ]; then \
130+
uv run ruff check . --fix; \
131+
uv run ruff format .; \
132+
else \
133+
uv run ruff check .; \
134+
fi
135+
@echo ""
136+
121137
## clean-env: Remove virtual environment
122138
clean-env:
123139
@echo ""

libs/common/odt_common/config.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ class CalibratorConfig(BaseModel):
9595
description="Rolling time window in minutes for MAPE calculation",
9696
gt=0,
9797
)
98-
98+
9999
# Legacy fields for backwards compatibility (mapped to new fields)
100100
asym_util_min: float | None = Field(None, exclude=True)
101101
asym_util_max: float | None = Field(None, exclude=True)
102102
asym_util_points: int | None = Field(None, exclude=True)
103-
104-
@model_validator(mode='after')
103+
104+
@model_validator(mode="after")
105105
def handle_legacy_fields(self):
106106
"""Map legacy field names to new ones if present."""
107107
if self.asym_util_min is not None:
@@ -159,7 +159,9 @@ class WorkloadContext(BaseModel):
159159

160160
name: str = Field(default="", description="Workload name (e.g., 'SURF')")
161161
base_path: Path = Field(default=Path("/app/workload"), description="Base workload directory")
162-
workload_dir: Path | None = Field(None, description="Direct path to workload directory (overrides base_path/name)")
162+
workload_dir: Path | None = Field(
163+
None, description="Direct path to workload directory (overrides base_path/name)"
164+
)
163165
metadata: WorkloadMetadata | None = Field(None, description="Workload metadata")
164166

165167
def __init__(self, **data):

libs/common/odt_common/models/consumption.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ class Consumption(BaseModel):
2222
@classmethod
2323
def parse_timestamp(cls, v: datetime | int | float | str) -> datetime:
2424
"""Parse timestamp from epoch milliseconds to datetime (UTC-aware).
25-
25+
2626
Args:
2727
v: Timestamp as milliseconds (int/float), datetime object, or ISO string
28-
28+
2929
Returns:
3030
UTC-aware datetime object
3131
"""
@@ -34,7 +34,7 @@ def parse_timestamp(cls, v: datetime | int | float | str) -> datetime:
3434
return datetime.fromtimestamp(v / 1000.0, tz=UTC)
3535
elif isinstance(v, str):
3636
# Parse ISO format string
37-
dt = datetime.fromisoformat(v.replace('Z', '+00:00'))
37+
dt = datetime.fromisoformat(v.replace("Z", "+00:00"))
3838
# Ensure UTC if not already timezone-aware
3939
if dt.tzinfo is None:
4040
dt = dt.replace(tzinfo=UTC)

libs/common/odt_common/models/task.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ def parse_id(cls, v: str | int) -> int:
5151
@classmethod
5252
def parse_submission_time(cls, v: datetime | int | float | str) -> datetime:
5353
"""Parse submission time from epoch milliseconds to datetime (UTC-aware).
54-
54+
5555
Args:
5656
v: Timestamp as milliseconds (int/float), datetime object, or ISO string
57-
57+
5858
Returns:
5959
UTC-aware datetime object
6060
"""
@@ -63,7 +63,7 @@ def parse_submission_time(cls, v: datetime | int | float | str) -> datetime:
6363
return datetime.fromtimestamp(v / 1000.0, tz=UTC)
6464
elif isinstance(v, str):
6565
# Parse ISO format string
66-
dt = datetime.fromisoformat(v.replace('Z', '+00:00'))
66+
dt = datetime.fromisoformat(v.replace("Z", "+00:00"))
6767
# Ensure UTC if not already timezone-aware
6868
if dt.tzinfo is None:
6969
dt = dt.replace(tzinfo=UTC)

libs/common/odt_common/models/topology.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ class Cluster(BaseModel):
102102

103103
name: str = Field(..., description="Cluster identifier/name")
104104
hosts: list[Host] = Field(..., description="List of host types in this cluster", min_length=1)
105-
powerSource: PowerSource | None = Field(None, description="Power source configuration (optional)")
105+
powerSource: PowerSource | None = Field(
106+
None, description="Power source configuration (optional)"
107+
)
106108

107109

108110
class Topology(BaseModel):

libs/common/odt_common/models/workload_message.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ class WorkloadMessage(BaseModel):
2727
..., description="Type of message: 'task' for workload or 'heartbeat' for keepalive"
2828
)
2929
timestamp: datetime = Field(..., description="Simulation timestamp of this message")
30-
task: Task | None = Field(
31-
None, description="Task data (only present when message_type='task')"
32-
)
30+
task: Task | None = Field(None, description="Task data (only present when message_type='task')")
3331

3432
class Config:
3533
json_schema_extra = {

libs/common/odt_common/odc_runner/runner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ def run_simulation(
249249
tasks[-1].submission_time.replace(microsecond=0).isoformat() if tasks else None
250250
),
251251
"task_count": len(tasks),
252-
"wall_clock_time": datetime.now(UTC).replace(microsecond=0, tzinfo=None).isoformat(),
252+
"wall_clock_time": datetime.now(UTC)
253+
.replace(microsecond=0, tzinfo=None)
254+
.isoformat(),
253255
"cached": False,
254256
}
255257
with open(metadata_file, "w") as f:

libs/common/tests/test_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import pandas as pd
77
import pytest
8+
89
from odt_common import Consumption, Fragment, Task
910

1011
# Locate test data

libs/common/tests/test_topology.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66

77
import pytest
8+
89
from odt_common.models.topology import (
910
CPU,
1011
AsymptoticCPUPowerModel,
@@ -52,7 +53,7 @@ def test_cpu_model():
5253
assert cpu.coreSpeed == 2100.0
5354

5455
# Test validation
55-
with pytest.raises(Exception):
56+
with pytest.raises(ValueError):
5657
CPU(coreCount=0, coreSpeed=2100.0) # Invalid: coreCount must be > 0
5758

5859

@@ -62,7 +63,7 @@ def test_memory_model():
6263
assert memory.memorySize == 128000000
6364

6465
# Test validation
65-
with pytest.raises(Exception):
66+
with pytest.raises(ValueError):
6667
Memory(memorySize=0) # Invalid: memorySize must be > 0
6768

6869

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ select = [
7373
"UP", # pyupgrade
7474
]
7575
ignore = [
76+
"E501", # Line too long (handled by formatter)
77+
"C901", # Function too complex
7678
"B008", # Allow function calls in argument defaults (FastAPI pattern for Query, Body, etc.)
7779
]
7880

0 commit comments

Comments
 (0)