-
Notifications
You must be signed in to change notification settings - Fork 72
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
✨ Add error messages for constraint failures #1036
Conversation
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.
Thanks for the PR. Have only one suggesting regarding performance optimization.
sphinx_needs/need_constraints.py
Outdated
@@ -45,6 +46,11 @@ def process_constraints(app: Sphinx, need: NeedsInfoType) -> None: | |||
need["constraints_results"].setdefault(constraint, {})[name] = False | |||
need["constraints_passed"] = False | |||
|
|||
if "error_message" in executable_constraints: | |||
need["constraints_error"] = jinja2.Template(str(executable_constraints["error_message"])).render( |
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.
Initiating a jinja template takes some time, can we do it only once and execute only the rendering per need?
Thanks @danwos, this pushed me to do something I was already planning to do in #1018: process all constraints in a single pass, rather than per document. Do you know any reason why it was per document in the first place? |
No, can't say (anymore) why it was implemented like this. |
This commit adds the ability to set an optional `error_message` key for each constraint in the `needs_constraint` configuration. This can contain Jinja placeholders, for needs data fields, and will be added to the need data, under the `constraints_error` field, if the constraint fails.
closes #1011
@danwos I felt the name
help
was not very descriptive of its purpose, and having the config key aserror_message
and the needs fieldconstraints_error
was more understandable. What do you think?Also perhaps:
I'd note that, in principle, I feel it would be more "correct" to lay out the configuration like this:
i.e. having the checks under a namespace, rather than having "special" keys