When autodoc-pydantic is not installed in the system, autodoc has some trouble parsing Pydantic's field_validator decorators. As a consequence some unwanted warnings are printed when building the docs.
This commit removes any use of field validators in favour of "after" model validators. Therefore eliminating autodoc's warnings, making it no longer needed to warn the user about the possible warnings. Signed-off-by: Luca Vizzarro <luca.vizza...@arm.com> --- doc/guides/conf.py | 9 ++------- dts/framework/config/__init__.py | 18 ++++++++---------- dts/framework/remote_session/__init__.py | 2 +- .../interactive_remote_session.py | 2 +- dts/framework/remote_session/remote_session.py | 2 +- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/doc/guides/conf.py b/doc/guides/conf.py index e7508ea1d5..50cbc7f612 100644 --- a/doc/guides/conf.py +++ b/doc/guides/conf.py @@ -61,17 +61,12 @@ if environ.get('DTS_DOC_BUILD'): extensions = ['sphinx.ext.napoleon', 'sphinx.ext.autodoc'] - # Pydantic models require autodoc_pydantic for the right formatting + # Pydantic models require autodoc_pydantic for the right formatting. Add if installed. try: import sphinxcontrib.autodoc_pydantic extensions.append("sphinxcontrib.autodoc_pydantic") except ImportError: - print( - "The DTS API doc dependencies are missing. " - "The generated output won't be as intended, " - "and autodoc may throw unexpected warnings.", - file=stderr, - ) + pass # Napoleon enables the Google format of Python doscstrings. napoleon_numpy_docstring = False diff --git a/dts/framework/config/__init__.py b/dts/framework/config/__init__.py index adbd4e952d..08712d2384 100644 --- a/dts/framework/config/__init__.py +++ b/dts/framework/config/__init__.py @@ -32,14 +32,13 @@ from typing import Annotated, Any, Literal, NamedTuple, TypeVar, cast import yaml -from pydantic import Field, TypeAdapter, ValidationError, field_validator, model_validator +from pydantic import Field, TypeAdapter, ValidationError, model_validator from typing_extensions import Self from framework.exception import ConfigurationError from .common import FrozenModel, ValidationContext from .node import ( - NodeConfiguration, NodeConfigurationTypes, SutNodeConfiguration, TGNodeConfiguration, @@ -105,19 +104,18 @@ def test_runs_with_nodes(self) -> list[TestRunWithNodesConfiguration]: return test_runs_with_nodes - @field_validator("nodes") - @classmethod - def validate_node_names(cls, nodes: list[NodeConfiguration]) -> list[NodeConfiguration]: + @model_validator(mode="after") + def validate_node_names(self) -> Self: """Validate that the node names are unique.""" nodes_by_name: dict[str, int] = {} - for node_no, node in enumerate(nodes): + for node_no, node in enumerate(self.nodes): assert node.name not in nodes_by_name, ( f"node {node_no} cannot have the same name as node {nodes_by_name[node.name]} " f"({node.name})" ) nodes_by_name[node.name] = node_no - return nodes + return self @model_validator(mode="after") def validate_ports(self) -> Self: @@ -130,9 +128,9 @@ def validate_ports(self) -> Self: for port_no, port in enumerate(node.ports): peer_port_identifier = (port.peer_node, port.peer_pci) peer_port = port_links.get(peer_port_identifier, None) - assert peer_port is not None, ( - "invalid peer port specified for " f"nodes.{node_no}.ports.{port_no}" - ) + assert ( + peer_port is not None + ), f"invalid peer port specified for nodes.{node_no}.ports.{port_no}" assert peer_port is False, ( f"the peer port specified for nodes.{node_no}.ports.{port_no} " f"is already linked to nodes.{peer_port[0]}.ports.{peer_port[1]}" diff --git a/dts/framework/remote_session/__init__.py b/dts/framework/remote_session/__init__.py index 0668e9c884..1a5cf6abd3 100644 --- a/dts/framework/remote_session/__init__.py +++ b/dts/framework/remote_session/__init__.py @@ -12,7 +12,7 @@ allowing it to send and receive data within that particular shell. """ -from framework.config import NodeConfiguration +from framework.config.node import NodeConfiguration from framework.logger import DTSLogger from .interactive_remote_session import InteractiveRemoteSession diff --git a/dts/framework/remote_session/interactive_remote_session.py b/dts/framework/remote_session/interactive_remote_session.py index 509a284aaf..c8156b4345 100644 --- a/dts/framework/remote_session/interactive_remote_session.py +++ b/dts/framework/remote_session/interactive_remote_session.py @@ -15,7 +15,7 @@ SSHException, ) -from framework.config import NodeConfiguration +from framework.config.node import NodeConfiguration from framework.exception import SSHConnectionError from framework.logger import DTSLogger diff --git a/dts/framework/remote_session/remote_session.py b/dts/framework/remote_session/remote_session.py index ab83f5b266..89d4618c41 100644 --- a/dts/framework/remote_session/remote_session.py +++ b/dts/framework/remote_session/remote_session.py @@ -14,7 +14,7 @@ from dataclasses import InitVar, dataclass, field from pathlib import Path, PurePath -from framework.config import NodeConfiguration +from framework.config.node import NodeConfiguration from framework.exception import RemoteCommandExecutionError from framework.logger import DTSLogger from framework.settings import SETTINGS -- 2.43.0