New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DM-41688: Add Pydantic data model to felis #25
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #25 +/- ##
==========================================
+ Coverage 98.12% 98.47% +0.35%
==========================================
Files 6 7 +1
Lines 427 592 +165
==========================================
+ Hits 419 583 +164
- Misses 8 9 +1 ☔ View full report in Codecov by Sentry. |
e31a3fd
to
b48c686
Compare
Sample output of new validation using Pydantic on |
deescription? (at start of validate.log) |
Someone misspelled "description" in the SDM schema itself, and the strict validation has caught the error. Before this would not have been caught because extra attributes were allowed in the YAML files and they are disallowed now. |
aa5f06a
to
6b2f62d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Some minor comments.
e7bb6b1
to
6c62c6e
Compare
6c62c6e
to
73b200b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good; I am just asking for a few edits to comments.
49d9916
to
56f5cea
Compare
This update adds a Pydantic v2 data model in the datamodel module along with unit tests for the new functionality. A new CLI command "validate" supports loading a YAML file in the top-level Schema class and validating it. Validation errors will result in a non-zero return code. Any number of YAML files may be provided at the command line and wildcards may be used to test all the files in a directory. The data model explicitly defines fields for all allowed keys, such that the usage of undefined keys, including misspellings or unknown annotations, will result in validation errors. All optional annotations currently found in the SDM Schemas YAML files are supported by the data model. Units and IVOA UCDs are checked using modules from astropy. Validation of the contents of other fields is initially loose, some accepting any string value. It is forseen that additional validation rules for fields and data model classes will be added in the future.
56f5cea
to
28f202c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to go
This PR adds a Pydantic v2 data model to felis describing the YAML schema format, as well as unit tests for the new module. A
validate
command was added to the CLI which will load any number of YAML files into Pydantic and print validation errors. This has been tested on all of the schemas insdm_schemas/yml
.To run tests covering the new module:
To run validation on all of the SDM schemas using the CLI tool:
These changes make no attempt to replace usage of the existing "simple" model that is used throughout Felis. All existing functionality should be unaffected.
For more details, please see the message on this PR's single commit. Updates to the Felis documentation will be forthcoming.