Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .hooks/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
PythonHandler,
)

# ruff: noqa: T201


class CustomMarkdownConverter(MarkdownConverter): # type: ignore[misc]
# Strip extra whitespace from code blocks
Expand Down
2 changes: 1 addition & 1 deletion dreadnode/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class TaskAgent(Agent):
"""

def model_post_init(self, _: t.Any) -> None:
from dreadnode.agent.tools import finish_task, update_todo
from dreadnode.agent.tools import finish_task, update_todo # noqa: PLC0415

if not any(tool for tool in self.tools if tool.name == "finish_task"):
self.tools.append(finish_task)
Expand Down
8 changes: 4 additions & 4 deletions dreadnode/agent/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ class AgentEnd(Event):


def rebuild_event_models() -> None:
from dreadnode.agent.agent import Agent # noqa: F401
from dreadnode.agent.reactions import Reaction # noqa: F401
from dreadnode.agent.result import AgentResult # noqa: F401
from dreadnode.agent.thread import Thread # noqa: F401
from dreadnode.agent.agent import Agent # noqa: F401,PLC0415
from dreadnode.agent.reactions import Reaction # noqa: F401,PLC0415
from dreadnode.agent.result import AgentResult # noqa: F401,PLC0415
from dreadnode.agent.thread import Thread # noqa: F401,PLC0415

rebuild_dataclass(Event) # type: ignore[arg-type]
rebuild_dataclass(AgentStart) # type: ignore[arg-type]
Expand Down
2 changes: 1 addition & 1 deletion dreadnode/agent/hooks/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
def _is_context_length_error(error: Exception) -> bool:
"""Checks if an exception is likely due to exceeding the context window."""
with contextlib.suppress(ImportError):
from litellm.exceptions import ContextWindowExceededError
from litellm.exceptions import ContextWindowExceededError # noqa: PLC0415

if isinstance(error, ContextWindowExceededError):
return True
Expand Down
8 changes: 4 additions & 4 deletions dreadnode/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def export_runs(
Returns:
A DataFrame containing the exported run data.
"""
import pandas as pd
import pandas as pd # noqa: PLC0415

response = self.request(
"GET",
Expand Down Expand Up @@ -430,7 +430,7 @@ def export_metrics(
Returns:
A DataFrame containing the exported metric data.
"""
import pandas as pd
import pandas as pd # noqa: PLC0415

response = self.request(
"GET",
Expand Down Expand Up @@ -470,7 +470,7 @@ def export_parameters(
Returns:
A DataFrame containing the exported parameter data.
"""
import pandas as pd
import pandas as pd # noqa: PLC0415

response = self.request(
"GET",
Expand Down Expand Up @@ -511,7 +511,7 @@ def export_timeseries(
Returns:
A DataFrame containing the exported timeseries data.
"""
import pandas as pd
import pandas as pd # noqa: PLC0415

response = self.request(
"GET",
Expand Down
2 changes: 1 addition & 1 deletion dreadnode/cli/agent/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async def run(
config_default = None
with contextlib.suppress(Exception):
config_default = config_model()
config_parameter = t.Optional[config_parameter] # type: ignore [assignment] # noqa: UP007
config_parameter = config_parameter | None # type: ignore [assignment]

async def agent_cli(*, config: t.Any = config_default) -> None:
agent = hydrate_agent(agent_blueprint, config)
Expand Down
6 changes: 3 additions & 3 deletions dreadnode/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ def clone(

@cli.command(help="Show versions and exit.", group="Meta")
def version() -> None:
import importlib.metadata
import platform
import sys
import importlib.metadata # noqa: PLC0415
import platform # noqa: PLC0415
import sys # noqa: PLC0415

version = importlib.metadata.version("dreadnode")
python_version = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
Expand Down
2 changes: 1 addition & 1 deletion dreadnode/cli/profile/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def switch(

# If no profile provided, prompt user to choose
if profile is None:
from rich.prompt import Prompt
from rich.prompt import Prompt # noqa: PLC0415

profiles = list(config.servers.keys())
rich.print("\nAvailable profiles:")
Expand Down
2 changes: 1 addition & 1 deletion dreadnode/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def run_span_to_graph(run: "RunSpan") -> "nx.DiGraph":
try:
import networkx as nx
import networkx as nx # noqa: PLC0415 # pyright: ignore[reportMissingModuleSource]
except ImportError as e:
raise RuntimeError("The `networkx` package is required for graph conversion") from e

Expand Down
14 changes: 7 additions & 7 deletions dreadnode/data_types/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

def check_imports() -> None:
try:
import soundfile as sf # type: ignore[import-untyped,unused-ignore] # noqa: F401
import soundfile as sf # type: ignore[import-untyped,unused-ignore] # noqa: F401,PLC0415
except ImportError as e:
raise ImportError(
"Audio processing requires `soundfile`. Install with: pip install dreadnode[multimodal]"
) from e

try:
import numpy as np # type: ignore[import-untyped,unused-ignore] # noqa: F401
import numpy as np # type: ignore[import-untyped,unused-ignore] # noqa: F401,PLC0415
except ImportError as e:
raise ImportError(
"Audio processing requires `numpy`. Install with: pip install dreadnode[multimodal]"
Expand Down Expand Up @@ -78,7 +78,7 @@ def _process_audio_data(self) -> tuple[bytes, str, int | None, float | None]:
Returns:
A tuple of (audio_bytes, format_name, sample_rate, duration)
"""
import numpy as np
import numpy as np # noqa: PLC0415

if isinstance(self._data, str | Path) and Path(self._data).exists():
return self._process_file_path()
Expand All @@ -94,7 +94,7 @@ def _process_file_path(self) -> tuple[bytes, str, int | None, float | None]:
Returns:
A tuple of (audio_bytes, format_name, sample_rate, duration)
"""
import soundfile as sf # type: ignore[import-not-found,unused-ignore]
import soundfile as sf # type: ignore[import-not-found,unused-ignore] # noqa: PLC0415

path_str = str(self._data)
audio_bytes = Path(path_str).read_bytes()
Expand All @@ -113,8 +113,8 @@ def _process_numpy_array(self) -> tuple[bytes, str, int | None, float | None]:
Returns:
A tuple of (audio_bytes, format_name, sample_rate, duration)
"""
import numpy as np # type: ignore[import-not-found,unused-ignore]
import soundfile as sf # type: ignore[import-not-found,unused-ignore]
import numpy as np # type: ignore[import-not-found,unused-ignore] # noqa: PLC0415
import soundfile as sf # type: ignore[import-not-found,unused-ignore] # noqa: PLC0415

if self._sample_rate is None:
raise ValueError('Argument "sample_rate" is required when using numpy arrays.')
Expand Down Expand Up @@ -151,7 +151,7 @@ def _generate_metadata(
Returns:
A dictionary of metadata
"""
import numpy as np # type: ignore[import-not-found,unused-ignore]
import numpy as np # type: ignore[import-not-found,unused-ignore] # noqa: PLC0415

metadata: dict[str, str | int | float | None] = {
"extension": format_name.lower(),
Expand Down
26 changes: 13 additions & 13 deletions dreadnode/data_types/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

def check_imports() -> None:
try:
import PIL # type: ignore[import,unused-ignore] # noqa: F401
import PIL # type: ignore[import,unused-ignore] # noqa: F401,PLC0415
except ImportError as e:
raise ImportError(
"Image processing requires `pillow`. Install with: pip install dreadnode[multimodal]"
) from e

try:
import numpy as np # type: ignore[import,unused-ignore] # noqa: F401
import numpy as np # type: ignore[import,unused-ignore] # noqa: F401,PLC0415
except ImportError as e:
raise ImportError(
"Image processing requires `numpy`. Install with: pip install dreadnode[multimodal]"
Expand Down Expand Up @@ -83,8 +83,8 @@ def _process_image_data(self) -> tuple[bytes, str, str | None, int | None, int |
Returns:
A tuple of (image_bytes, image_format, mode, width, height)
"""
import numpy as np # type: ignore[import,unused-ignore]
import PIL.Image # type: ignore[import,unused-ignore]
import numpy as np # type: ignore[import,unused-ignore] # noqa: PLC0415
import PIL.Image # type: ignore[import,unused-ignore] # noqa: PLC0415

if isinstance(self._data, (str, Path)) and Path(self._data).exists():
return self._process_file_path()
Expand All @@ -104,7 +104,7 @@ def _process_file_path(self) -> tuple[bytes, str, str | None, int | None, int |
Returns:
A tuple of (image_bytes, image_format, mode, width, height)
"""
import PIL.Image # type: ignore[import,unused-ignore]
import PIL.Image # type: ignore[import,unused-ignore] # noqa: PLC0415

path_str = str(self._data)
image_bytes = Path(path_str).read_bytes()
Expand All @@ -122,7 +122,7 @@ def _process_pil_image(self) -> tuple[bytes, str, str | None, int | None, int |
Returns:
A tuple of (image_bytes, image_format, mode, width, height)
"""
import PIL.Image # type: ignore[import,unused-ignore]
import PIL.Image # type: ignore[import,unused-ignore] # noqa: PLC0415

if not isinstance(self._data, PIL.Image.Image):
raise TypeError(f"Expected PIL.Image, got {type(self._data)}")
Expand Down Expand Up @@ -160,8 +160,8 @@ def _process_numpy_array(self) -> tuple[bytes, str, str | None, int | None, int
Returns:
A tuple of (image_bytes, image_format, mode, width, height)
"""
import numpy as np # type: ignore[import,unused-ignore]
import PIL.Image # type: ignore[import,unused-ignore]
import numpy as np # type: ignore[import,unused-ignore] # noqa: PLC0415
import PIL.Image # type: ignore[import,unused-ignore] # noqa: PLC0415

buffer = io.BytesIO()
image_format = self._format or "png"
Expand Down Expand Up @@ -191,7 +191,7 @@ def _process_raw_bytes(self) -> tuple[bytes, str, str | None, int | None, int |
Returns:
A tuple of (image_bytes, image_format, mode, width, height)
"""
import PIL.Image # type: ignore[import,unused-ignore]
import PIL.Image # type: ignore[import,unused-ignore] # noqa: PLC0415

if not isinstance(self._data, bytes):
raise TypeError(f"Expected bytes, got {type(self._data)}")
Expand All @@ -216,7 +216,7 @@ def _process_base64_string(self) -> tuple[bytes, str, str | None, int | None, in
Returns:
A tuple of (image_bytes, image_format, mode, width, height)
"""
import PIL.Image # type: ignore[import,unused-ignore]
import PIL.Image # type: ignore[import,unused-ignore] # noqa: PLC0415

if not isinstance(self._data, str):
raise TypeError(f"Expected str, got {type(self._data)}")
Expand Down Expand Up @@ -253,8 +253,8 @@ def _generate_metadata(
self, image_format: str, mode: str | None, width: int | None, height: int | None
) -> dict[str, str | int | None]:
"""Generate metadata for the image."""
import numpy as np # type: ignore[import,unused-ignore]
import PIL.Image # type: ignore[import,unused-ignore]
import numpy as np # type: ignore[import,unused-ignore] # noqa: PLC0415
import PIL.Image # type: ignore[import,unused-ignore] # noqa: PLC0415

metadata: dict[str, str | int | None] = {
"extension": image_format.lower(),
Expand Down Expand Up @@ -313,7 +313,7 @@ def _ensure_valid_image_array(
self, array: "np.ndarray[t.Any, np.dtype[t.Any]]"
) -> "np.ndarray[t.Any, np.dtype[t.Any]]":
"""Convert numpy array to a format suitable for PIL."""
import numpy as np # type: ignore[import,unused-ignore]
import numpy as np # type: ignore[import,unused-ignore] # noqa: PLC0415

grayscale_dim = 2
rgb_dim = 3
Expand Down
8 changes: 4 additions & 4 deletions dreadnode/data_types/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def _to_dataframe(self) -> "pd.DataFrame":
Returns:
A pandas DataFrame representation of the input data
"""
import numpy as np
import pandas as pd
import numpy as np # noqa: PLC0415
import pandas as pd # noqa: PLC0415

if isinstance(self._data, pd.DataFrame):
return self._data
Expand Down Expand Up @@ -134,8 +134,8 @@ def _generate_metadata(self, data_frame: "pd.DataFrame") -> dict[str, t.Any]:
Returns:
A dictionary of metadata
"""
import numpy as np
import pandas as pd
import numpy as np # noqa: PLC0415
import pandas as pd # noqa: PLC0415

metadata = {
"extension": self._format,
Expand Down
20 changes: 13 additions & 7 deletions dreadnode/data_types/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ def to_serializable(self) -> tuple[bytes, dict[str, t.Any]]:
Returns:
A tuple of (video_bytes, metadata_dict)
"""
import numpy as np # type: ignore[import,unused-ignore]
import numpy as np # type: ignore[import,unused-ignore] # noqa: PLC0415

try:
from moviepy.video.VideoClip import VideoClip # type: ignore[import,unused-ignore]
from moviepy.video.VideoClip import ( # type: ignore[import,unused-ignore,import-untyped] # noqa: PLC0415
VideoClip,
)
except ImportError:
VideoClip = None # noqa: N806

Expand Down Expand Up @@ -120,7 +122,7 @@ def _process_numpy_array(self) -> tuple[bytes, dict[str, t.Any]]:
Returns:
A tuple of (video_bytes, metadata_dict)
"""
import numpy as np # type: ignore[import,unused-ignore]
import numpy as np # type: ignore[import,unused-ignore] # noqa: PLC0415

if not self._fps:
raise ValueError("fps is required for numpy array video frames")
Expand All @@ -135,7 +137,7 @@ def _process_numpy_array(self) -> tuple[bytes, dict[str, t.Any]]:

def _extract_frames_from_data(self) -> "list[NDArray[t.Any]]":
"""Extract frames from numpy array or list data."""
import numpy as np # type: ignore[import,unused-ignore]
import numpy as np # type: ignore[import,unused-ignore] # noqa: PLC0415

frames = []
rgb_dim = 3
Expand All @@ -157,10 +159,12 @@ def _create_video_from_frames_data(
self, frames: "list[NDArray[t.Any]]"
) -> tuple[bytes, dict[str, t.Any]]:
"""Create video file from frames."""
import numpy as np # type: ignore[import,unused-ignore]
import numpy as np # type: ignore[import,unused-ignore] # noqa: PLC0415

try:
from moviepy.video.io import ImageSequenceClip # type: ignore[import,unused-ignore]
from moviepy.video.io import ( # type: ignore[import,unused-ignore,import-untyped] # noqa: PLC0415
ImageSequenceClip,
)
except ImportError as e:
raise ImportError(
"Video processing from numpy arrays requires moviepy. "
Expand Down Expand Up @@ -207,7 +211,9 @@ def _process_moviepy_clip(self) -> tuple[bytes, dict[str, t.Any]]:
Returns:
A tuple of (video_bytes, metadata_dict)
"""
from moviepy.video.VideoClip import VideoClip # type: ignore[import,unused-ignore]
from moviepy.video.VideoClip import ( # noqa: PLC0415
VideoClip, # type: ignore[import,unused-ignore]
)

if not isinstance(self._data, VideoClip):
raise TypeError("data must be a MoviePy VideoClip object")
Expand Down
9 changes: 3 additions & 6 deletions dreadnode/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,7 @@ def configure(
with contextlib.suppress(Exception):
user_config = UserConfig.read()
profile_name = profile or os.environ.get(ENV_PROFILE)
if profile_name:
active_profile = profile_name
else:
active_profile = user_config.active_profile_name
active_profile = profile_name or user_config.active_profile_name

if active_profile:
config_source = f"profile: {active_profile}"
Expand Down Expand Up @@ -945,7 +942,7 @@ def log_params(self, **params: JsonValue) -> None:
def log_metric(
self,
name: str,
value: float | bool,
value: float | bool, # noqa: FBT001
*,
step: int = 0,
origin: t.Any | None = None,
Expand Down Expand Up @@ -1036,7 +1033,7 @@ def log_metric(
def log_metric(
self,
name: str,
value: float | bool | Metric,
value: float | bool | Metric, # noqa: FBT001
*,
step: int = 0,
origin: t.Any | None = None,
Expand Down
2 changes: 1 addition & 1 deletion dreadnode/scorers/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def zero_shot_classification(
)

try:
from transformers import ( # type: ignore [attr-defined,import-not-found,unused-ignore]
from transformers import ( # type: ignore [attr-defined,import-not-found,unused-ignore] # noqa: PLC0415
pipeline,
)
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion dreadnode/scorers/harm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def detect_harm_with_openai(
model: The moderation model to use.
name: Name of the scorer.
"""
import openai
import openai # noqa: PLC0415

async def evaluate(data: t.Any) -> Metric:
text = str(data)
Expand Down
Loading