Make config models into schemas#256
Draft
TeresiaOlsson wants to merge 17 commits into
Draft
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.
The purpose of this PR is to separate the config model classes from the classes which are performing the business logic and add separate functionality for validation and handling schemas.
The advantages of this is:
Pydantic becomes a more lose dependency. It is no longer used inside the business logic parts of the code but can be separated out to only be used for validation of input data. This makes it possible to separate validation from object creation making it easier to remove the dependency of Pydantic in the future if necessary without having to rewrite the business logic parts of the code.
It becomes possible to make validation optional. This is required to be able to integrate third-party devices and applications where validation models might not exist. Also for standard pyAML devices and applications it can be useful to be able to turn validation off since there is no need to do it when you know that your configuration has already been validated and validation just takes extra time during loading.
Nested Pydantic BaseModels now only contain built-in types or other BaseModels which makes it easier to use the functionality of Pydantic to validate nested data and generate json schemas. Arbitrary types in the BaseModel is no longer allowed.
The config models now only have a single purpose: to define the schema that should be used for validation. They are therefore no longer config models and have been renamed as Schema instead to make their purpose more clear for new users/developers.
Users can create objects directly in Python without having to first create a ConfigModel. They can do things like:
which makes it easier for new users to test and play around a bit without having to generate a configuration file and load it. No configuration file feels necessary if you just want to create a single device and test how it works to read the values for it and compare to how you currently might do it with
pytango,pyepicsetc.It becomes easier to implement a registry for schemas that can serve as a backend for creating a GUI application helping the users to set up the configuration.
Disadvantages:
The PR is work in progress and the code is definitely broken at the moment since this affects everywhere.
To do:
__repr__which is currently broken since it relied on Pydantic.