Multiline validation messages and pydantic validation #2411
cbrown1234
started this conversation in
Ideas
Replies: 1 comment
-
|
I've now published the jinja extensions to pypi at https://pypi.org/project/copier-pydantic/ and the repo code is here https://gitlab.com/cbrown1234/copier-pydantic |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Since the support for the
yieldkeyword in templates, there is a lot more motivation to have complex question answers for dynamic project generatione.g.
I've been playing around with a few ideas for a better user experience with more complex questions/answers, and I'm looking for some input on how to make these more accessible if there is interest, and/or for people to share other related ideas
Longer validation messages
The single-line limit always felt very constraining when trying to give a helpful error
POC: https://github.com/cbrown1234/example-template/blob/e4e0acb40011faf787877e7a696f32293d622679/extensions/multiline_validation.py
The implementation as a jinja extension to apply a monkeypatch is obviously quite hacky but this could maybe be made into an opt-in flag in the copier.yml via a change to copier itself
(And maybe some work could be done to make the setting more easily accessible in prompt_toolkit)
Pydantic model validation for answers
POC: https://github.com/cbrown1234/example-template/blob/8b6f1c18fb69661278ed4e21454cc4b1a1a67408/extensions/validators.py
I've played around with a few methods of trying to decouple the extension logic from the model definition, not got anything to stick quite yet, but somewhere between the approaches of jinja2_jsonschema and copier_templates_extensions might be able to work.(Updated POC link with separated models definition in the root of template repo). Or it could just be shared as a copier template itselfI see from the discussion here https://github.com/orgs/copier-org/discussions/376, that adding features that increase the surface area for untrusted code to run is preferred to not be included in copier itself. So not expecting this would be something people would want to add to copier, even though pydantic is already a dependency
Related
I also recently found that https://github.com/copier-org/jinja2-jsonschema exists, and can help solve similar problems. This extension could also pair well with the ability to see longer error messages
(Wish I had found it earlier, as it would probably have saved a lot of time reading docs :D)
Beta Was this translation helpful? Give feedback.
All reactions