From b82d4e3dcb986294870e00401be2ebeb840c00b7 Mon Sep 17 00:00:00 2001 From: Tim Paine <3105306+timkpaine@users.noreply.github.com> Date: Sun, 12 Jul 2026 17:07:17 -0400 Subject: [PATCH] Make simulation profiles pydantic models MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit VerilatorProfile and CocotbProfile were frozen dataclasses. Convert them to frozen pydantic BaseModels so they validate on construction and expose model_validate — letting downstream packages (dau-build) validate profile mappings declaratively instead of by hand. Adds pydantic (already present transitively via csp) as an explicit dependency. --- dau_sim/integrations/cocotb.py | 8 +++++--- dau_sim/integrations/verilator_profiles.py | 8 +++++--- pyproject.toml | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/dau_sim/integrations/cocotb.py b/dau_sim/integrations/cocotb.py index e932904..aae04a2 100644 --- a/dau_sim/integrations/cocotb.py +++ b/dau_sim/integrations/cocotb.py @@ -10,17 +10,19 @@ from __future__ import annotations from collections.abc import Mapping, Sequence -from dataclasses import dataclass from pathlib import Path +from pydantic import BaseModel, ConfigDict + DEFAULT_BUILD_ARGS = ("--timing", "-Wno-fatal") -@dataclass(frozen=True) -class CocotbProfile: +class CocotbProfile(BaseModel): """A registered cocotb bench: HDL sources, the toplevel they build, and the cocotb test module that drives it.""" + model_config = ConfigDict(frozen=True) + name: str sources: tuple[Path, ...] hdl_toplevel: str diff --git a/dau_sim/integrations/verilator_profiles.py b/dau_sim/integrations/verilator_profiles.py index 775d326..8cb8f6b 100644 --- a/dau_sim/integrations/verilator_profiles.py +++ b/dau_sim/integrations/verilator_profiles.py @@ -1,11 +1,13 @@ from __future__ import annotations -from dataclasses import dataclass from pathlib import Path +from pydantic import BaseModel, ConfigDict + + +class VerilatorProfile(BaseModel): + model_config = ConfigDict(frozen=True) -@dataclass(frozen=True) -class VerilatorProfile: name: str sources: tuple[Path, ...] top_module: str diff --git a/pyproject.toml b/pyproject.toml index f10a328..f1e000e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,7 @@ classifiers = [ dependencies = [ "amaranth", "csp", + "pydantic", "pyslang", "typer", "rich",