Refactor config dumps to use Pydantic model introspection#133
Open
ayushk687 wants to merge 1 commit intoOSIPI:mainfrom
Open
Refactor config dumps to use Pydantic model introspection#133ayushk687 wants to merge 1 commit intoOSIPI:mainfrom
ayushk687 wants to merge 1 commit intoOSIPI:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR replaces the current hard-coded YAML templates used in dump_defaults() with an auto-generated YAML output derived directly from the project’s Pydantic configuration models. This ensures that all config fields are always up-to-date with the underlying model definitions and eliminates the risk of drift between template strings and actual config fields.
CLOSES #129
Motivation
The existing implementation of dump_defaults() in osipy/cli/config.py returns static YAML templates stored in the _DEFAULT_TEMPLATES dictionary. These templates have already diverged from the true set of config fields — for example, fields such as fit_delay and delay_bounds are defined in the Pydantic models but missing from the templates. Manual maintenance of these templates is error-prone and unsustainable as the project evolves.
What Changed
Removed: The
_DEFAULT_TEMPLATESdictionary of hard-coded YAML strings.Added: A new YAML generator that introspects
Pydantic models using: model_json_schema()Field metadata such as defaults, types, and descriptions
Improved:
Human-readability of generated YAMLby grouping fields by section and preserving comments from model Field(description=...).Ensured: All config classes now appear accurately in the output, automatically reflecting any additions or changes.
📌 Summary
This PR improves YAML generation.
🧪 Example Output
📂 Changes
Example Output
Here is a snippet of the new generated YAML for a config class (illustrative example):