From: Dean Marx <dmarx@iol.unh.edu>
To: Luca Vizzarro <luca.vizzarro@arm.com>
Cc: dev@dpdk.org,
"Honnappa Nagarahalli" <honnappa.nagarahalli@arm.com>,
"Juraj Linkeš" <juraj.linkes@pantheon.tech>,
"Paul Szczepanek" <paul.szczepanek@arm.com>
Subject: Re: [PATCH 3/5] dts: use Pydantic in the configuration
Date: Mon, 30 Sep 2024 17:45:10 -0400 [thread overview]
Message-ID: <CABD7UXN46-0DZ8ShsZ7Hus=w03EWd4kQ2EG3X0mb-wB9rW6Q_g@mail.gmail.com> (raw)
In-Reply-To: <20240822163941.1390326-4-luca.vizzarro@arm.com>
[-- Attachment #1: Type: text/plain, Size: 2656 bytes --]
On Thu, Aug 22, 2024 at 12:40 PM Luca Vizzarro <luca.vizzarro@arm.com>
wrote:
> This change brings in Pydantic in place of Warlock. Pydantic offers
> a built-in model validation system in the classes, which allows for
> a more resilient and simpler code. As a consequence of this change:
>
> - most validation is now built-in
> - further validation is added to verify:
> - cross referencing of node names and ports
> - test suite and test cases names
> - dictionaries representing the config schema are removed
> - the config schema is no longer used for validation but kept as an
> alternative format for the developer
> - the config schema can now be generated automatically from the
> Pydantic models
> - the TrafficGeneratorType enum has been changed from inheriting
> StrEnum to the native str and Enum. This change was necessary to
> enable the discriminator for object unions
> - the structure of the classes has been slightly changed to perfectly
> match the structure of the configuration files
> - updates the test suite argument to catch the ValidationError that
> TestSuiteConfig can now raise
>
> Bugzilla ID: 1508
>
> Signed-off-by: Luca Vizzarro <luca.vizzarro@arm.com>
> Reviewed-by: Paul Szczepanek <paul.szczepanek@arm.com>
<snip>
> -@dataclass(slots=True, frozen=True)
> +@dataclass(slots=True, frozen=True, kw_only=True,
> config=ConfigDict(extra="forbid"))
>
Up to you but I think it might be worth specifying what some of these extra
pydantic args are for if we're going to keep the name of the decorator as
"dataclass." For example, this ConfigDict "forbid" argument seems to be
commonly used, same with the "before/after" modes with the model_validator.
Maybe a brief description somewhere in the docstrings, just so others can
see how it differs from the previous implementation even without experience
using pydantic.
<snip>
> + @model_validator(mode="before")
> @classmethod
> - def from_dict(
> - cls,
> - entry: str | TestSuiteConfigDict,
> - ) -> Self:
> - """Create an instance from two different types.
> + def convert_from_string(cls, data: Any) -> Any:
> + """Convert the string representation into a valid mapping."""
> + if isinstance(data, str):
> + [test_suite, *test_cases] = data.split()
> + return dict(test_suite=test_suite, test_cases=test_cases)
> + return data
>
Again this is completely your call, but might be worth explaining in the
docstrings why this "before" method is used here while the other validators
are running with "after."
[-- Attachment #2: Type: text/html, Size: 3651 bytes --]
next prev parent reply other threads:[~2024-09-30 21:44 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-22 16:39 [PATCH 0/5] dts: Pydantic configuration Luca Vizzarro
2024-08-22 16:39 ` [PATCH 1/5] dts: add TestSuiteSpec class and discovery Luca Vizzarro
2024-09-16 13:00 ` Juraj Linkeš
2024-10-29 12:57 ` Luca Vizzarro
2024-09-19 20:01 ` Nicholas Pratte
2024-08-22 16:39 ` [PATCH 2/5] dts: add Pydantic and remove Warlock Luca Vizzarro
2024-09-16 13:17 ` Juraj Linkeš
2024-09-19 19:56 ` Nicholas Pratte
2024-09-30 20:41 ` Dean Marx
2024-08-22 16:39 ` [PATCH 3/5] dts: use Pydantic in the configuration Luca Vizzarro
2024-09-17 11:13 ` Juraj Linkeš
2024-10-29 13:00 ` Luca Vizzarro
2024-09-30 17:56 ` Nicholas Pratte
2024-10-29 12:41 ` Luca Vizzarro
2024-09-30 21:45 ` Dean Marx [this message]
2024-10-29 12:51 ` Luca Vizzarro
2024-08-22 16:39 ` [PATCH 4/5] dts: use TestSuiteSpec class imports Luca Vizzarro
2024-09-17 11:39 ` Juraj Linkeš
2024-10-29 12:52 ` Luca Vizzarro
2024-10-01 17:12 ` Dean Marx
2024-10-29 12:54 ` Luca Vizzarro
2024-10-01 20:45 ` Nicholas Pratte
2024-10-29 12:56 ` Luca Vizzarro
2024-11-04 17:49 ` Nicholas Pratte
2024-08-22 16:39 ` [PATCH 5/5] dts: add JSON schema generation script Luca Vizzarro
2024-09-17 11:59 ` Juraj Linkeš
2024-10-01 20:48 ` Nicholas Pratte
2024-10-25 15:58 ` [PATCH v2 0/5] dts: Pydantic configuration Luca Vizzarro
2024-10-25 15:58 ` [PATCH v2 1/5] dts: add pydantic dependency Luca Vizzarro
2024-10-25 15:58 ` [PATCH v2 2/5] dts: add TestSuiteSpec class and discovery Luca Vizzarro
2024-10-25 15:58 ` [PATCH v2 3/5] dts: use pydantic in the configuration Luca Vizzarro
2024-10-25 15:58 ` [PATCH v2 4/5] dts: remove warlock dependency Luca Vizzarro
2024-10-25 15:58 ` [PATCH v2 5/5] dts: use TestSuiteSpec class imports Luca Vizzarro
2024-10-25 16:43 ` [PATCH v3 0/5] dts: Pydantic configuration Luca Vizzarro
2024-10-25 16:43 ` [PATCH v3 1/5] dts: add pydantic dependency Luca Vizzarro
2024-10-25 16:43 ` [PATCH v3 2/5] dts: add TestSuiteSpec class and discovery Luca Vizzarro
2024-10-25 16:43 ` [PATCH v3 3/5] dts: use pydantic in the configuration Luca Vizzarro
2024-10-25 16:43 ` [PATCH v3 4/5] dts: remove warlock dependency Luca Vizzarro
2024-10-25 16:43 ` [PATCH v3 5/5] dts: use TestSuiteSpec class imports Luca Vizzarro
2024-10-28 17:49 ` [PATCH v4 0/8] dts: Pydantic configuration Luca Vizzarro
2024-10-28 17:49 ` [PATCH v4 1/8] dts: add pydantic dependency Luca Vizzarro
2024-10-31 18:42 ` Nicholas Pratte
2024-10-28 17:49 ` [PATCH v4 2/8] dts: add TestSuiteSpec class and discovery Luca Vizzarro
2024-10-31 19:32 ` Nicholas Pratte
2024-10-31 20:21 ` Nicholas Pratte
2024-10-28 17:49 ` [PATCH v4 3/8] dts: refactor build and node info classes Luca Vizzarro
2024-10-31 20:16 ` Nicholas Pratte
2024-10-28 17:49 ` [PATCH v4 4/8] dts: use pydantic in the configuration Luca Vizzarro
2024-10-31 20:20 ` Nicholas Pratte
2024-10-28 17:49 ` [PATCH v4 5/8] dts: remove warlock dependency Luca Vizzarro
2024-10-31 20:23 ` Nicholas Pratte
2024-10-28 17:49 ` [PATCH v4 6/8] dts: add autodoc pydantic Luca Vizzarro
2024-10-31 20:52 ` Nicholas Pratte
2024-10-28 17:49 ` [PATCH v4 7/8] dts: improve configuration API docs Luca Vizzarro
2024-11-04 17:34 ` Nicholas Pratte
2024-10-28 17:49 ` [PATCH v4 8/8] dts: use TestSuiteSpec class imports Luca Vizzarro
2024-11-04 17:50 ` Nicholas Pratte
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CABD7UXN46-0DZ8ShsZ7Hus=w03EWd4kQ2EG3X0mb-wB9rW6Q_g@mail.gmail.com' \
--to=dmarx@iol.unh.edu \
--cc=dev@dpdk.org \
--cc=honnappa.nagarahalli@arm.com \
--cc=juraj.linkes@pantheon.tech \
--cc=luca.vizzarro@arm.com \
--cc=paul.szczepanek@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).