|
1 | 1 | # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
3 | | - |
4 | | -""" |
5 | | -Configurator: A mini-library for Pydantic-based configuration systems with strong typing support. |
6 | | -
|
7 | | -This package provides a comprehensive set of tools for building type-safe, validated |
8 | | -configuration systems using Pydantic v2. It's designed for developers who need |
9 | | -sophisticated parameter management with excellent static analysis support. |
10 | | -
|
11 | | -Key Components: |
12 | | -
|
13 | | -Parameter Wrappers (parameter.py): |
14 | | - - Parameter: Generic wrapper for configuration values with Pydantic integration |
15 | | - - AutoParam: Parameter with automatic type-safe update capabilities |
16 | | - - UnsetParam: For handling unset/default parameter states |
17 | | - - ValidNoneParam: For parameters where None is a valid value |
18 | | -
|
19 | | -Validation & Collections (parameters.py): |
20 | | - - Parameters: Abstract base class for organizing parameter collections |
21 | | - - DependsOnValidator: Conditional field validation based on other fields |
22 | | - - ValueValidator: Custom validation functions for parameter values |
23 | | - - YAML serialization support for configuration persistence |
24 | | -
|
25 | | -Usage Examples: |
26 | | -
|
27 | | -Basic Parameter Usage: |
28 | | - >>> from nemo_safe_synthesizer.configurator.parameter import Parameter, AutoParam |
29 | | - >>> |
30 | | - >>> # Simple parameter |
31 | | - >>> max_size = Parameter(name="max_size", value=1000) |
32 | | - >>> |
33 | | - >>> # Auto-updating parameter |
34 | | - >>> batch_size = AutoParam(name="batch_size", value=32) |
35 | | - >>> batch_size.autoupdate(64) # Safe type-checked update |
36 | | -
|
37 | | -Parameter Collections: |
38 | | - >>> from nemo_safe_synthesizer.configurator.parameters import Parameters |
39 | | - >>> from nemo_safe_synthesizer.configurator.parameter import AutoParam |
40 | | - >>> from typing import Annotated |
41 | | - >>> from pydantic import Field |
42 | | - >>> class DatabaseConfig(Parameters): |
43 | | - ... host: Annotated[AutoParam[str], Field(default=AutoParam(name="host", value="localhost")] |
44 | | - ... port: Annotated[AutoParam[int], Field(default=AutoParam(name="port", value=5432)] |
45 | | - >>> |
46 | | - >>> config = DatabaseConfig() |
47 | | - >>> config.host |
48 | | - AutoParam(name='host', value='localhost') |
49 | | -
|
50 | | -Conditional Validation: |
51 | | - >>> from nemo_safe_synthesizer.configurator.parameters import Parameters |
52 | | - >>> from nemo_safe_synthesizer.configurator.validators import DependsOnValidator |
53 | | - >>> from nemo_safe_synthesizer.configurator.parameter import AutoParam |
54 | | - >>> from typing import Annotated |
55 | | - >>> |
56 | | - >>> class AdvancedConfig(Parameters): |
57 | | - ... debug_mode: bool = False |
58 | | - ... verbose_logging: Annotated[ |
59 | | - ... Parameter[bool], |
60 | | - ... DependsOnValidator(depends_on="debug_mode", depends_on_func=lambda x: x is True), |
61 | | - ... Field(default=Parameter(name="verbose_logging", value=False)), |
62 | | - ... ] |
63 | | -""" |
0 commit comments