Skip to content
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

Use Pydantic for validation and serialisation #1661

Merged
merged 67 commits into from
Jan 19, 2024
Merged

Conversation

JimMadge
Copy link
Member

@JimMadge JimMadge commented Nov 7, 2023

✅ Checklist

  • You have given your pull request a meaningful title (e.g. Enable foobar integration rather than 515 foobar).
  • You are targeting the appropriate branch. If you're not certain which one this is, it should be develop.
  • Your branch is up-to-date with the target branch (it probably was when you started, but it may have changed since then).
  • You have marked this pull request as a draft and added '[WIP]' to the title if needed (if you're not yet ready to merge).
  • You have formatted your code using appropriate automated tools (for example ./tests/AutoFormat_Powershell.ps1 -TargetPath <path to file or directory> for Powershell).

⤴️ Summary

  • Add Pydantic, replace Schema and Chili for both validation and serialisation
  • Use Pydantic BaseModel features to improve validation
    • Ensure selected context is defined
  • Redefine Config and ConfigSection* classes using Pydantic BaseModel
    • This is neater than before.
      Less reinventing the wheel of validation/serialisation
      I think it can be improved further by adding dsh config ... commands so that fewer (or no) fields need to be optional
  • Dynamically construct determininistic config items
  • Reduce redundancy and verbosity of config file
  • Restructure validation functions
    • Less functions needed as Pydantic has many
    • Functions now operate as Pydantic validators
    • Factory added to build Typer validators from Pydantic validators
  • Add tests for Config and ConfigSection* classes

🌂 Related issues

Closes #1658
Contributes to #1640

🔬 Tests

Base automatically changed from context to python-migration November 15, 2023 09:57
This simplifies the construction of a Config object and makes the
serialised configuration less verbose and redundant.
@JimMadge JimMadge changed the title [WIP] Use Pydantic for validation and serialisation Use Pydantic for validation and serialisation Jan 15, 2024
@JimMadge JimMadge marked this pull request as ready for review January 15, 2024 15:38
@JimMadge JimMadge requested a review from craddm January 15, 2024 15:39
Copy link
Contributor

@craddm craddm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than that one comment on the readme, LGTM

Co-authored-by: Matt Craddock <mcraddock@turing.ac.uk>
@JimMadge JimMadge merged commit ec972a6 into python-migration Jan 19, 2024
5 checks passed
@JimMadge JimMadge deleted the pydantic branch January 19, 2024 09:00
@JimMadge JimMadge mentioned this pull request Feb 9, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants