Skip to content

Add new --validate option - #642

Open
alranel wants to merge 1 commit into
elapouya:masterfrom
alranel:validate
Open

Add new --validate option#642
alranel wants to merge 1 commit into
elapouya:masterfrom
alranel:validate

Conversation

@alranel

@alranel alranel commented Jun 3, 2026

Copy link
Copy Markdown

This PR adds a new --validate option to the CLI tool, that allows to check whether a template has valid Jinja syntax without supplying any data JSON file.
A --report FILE option is also added that can be used to write the validation report to the given file path, in JSON format.

@CAOShurong CAOShurong left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I tested the exact head c1259ab66ec7e4ee6964a901b1486a730f1029eb from source and from a clean wheel install on Python 3.13.1. The valid-template path exits 0 and writes {"valid": true}; malformed Jinja exits 1 and writes {"valid": false, ...}; normal rendering still works. I also ran all 36 non-runner test scripts, flake8, and the sdist/wheel build successfully.

One exit-code issue blocks approval. Both newly introduced rejected invocations print an error but exit 0:

python -m docxtpl valid.docx --report report.json
Error: --report requires --validate.
EXIT=0

python -m docxtpl missing.docx --validate
Error: The specified template_path "...missing.docx" is not valid.
EXIT=0

validate_all_args() raises RuntimeError, but main() catches it and returns normally; SystemExit(1) is reached only after run_validation() starts. A CI script therefore cannot distinguish a rejected validation request from a successful validation.

Please make validation-related argument/path errors exit nonzero and add automated CLI coverage for valid syntax, invalid syntax, a missing template, and --report without --validate. No test file currently exercises the new CLI behavior.

I used OpenAI Codex to help run the exact-head regression matrix and inspect the control flow; I personally checked the commands, outputs, exit codes, and this review.

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