Add a --check mode to the extract command - #1326
Open
ChrisJr404 wants to merge 1 commit into
Open
Conversation
The update command already supports a --check mode that verifies catalogs are up to date without writing them, which is handy in CI. This adds the equivalent for extract: with --check, messages are extracted as usual but the output file is not written; instead the freshly extracted catalog is compared against the existing output file, and a non-zero exit code is returned if the file is missing or would be changed. Differences in the POT-Creation-Date header alone are ignored, since it is regenerated on every extraction. Closes python-babel#900
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.
Closes #900.
The
updatecommand already has a--checkmode that verifies catalogs are up to date without writing them, which is very handy in CI. This adds the equivalent forextract.With
--check, messages are extracted from the source as usual, but the output file is not written. Instead the freshly extracted catalog is compared against the existing--output-file, and a non-zero exit code (aBaseError) is raised if:If nothing would change, the command logs that the file is up to date and returns normally.
POT-Creation-Date
A fresh extraction always regenerates the
POT-Creation-Dateheader, so a naive comparison would always report a difference. The check therefore ignores that header alone (it copies the existing file's creation date onto the freshly extracted catalog before comparing), mirroring howupdate --checkneutralises the volatile revision date. Any real change to the messages or the other headers is still reported.The comparison round-trips the extracted catalog through
write_po/read_powith the same options that would be used to write it, so the check reflects exactly what would end up on disk.Usage
$ pybabel extract --check -o messages.pot mypackage/Tests
Added
test_extract_checkandtest_extract_check_ignores_pot_creation_dateintests/messages/frontend/test_cli.py, covering the up-to-date, changed, and missing-file cases, that the check never writes/creates the output file, and that a differingPOT-Creation-Datealone does not trigger a failure. The docs for theextractcommand are updated as well.pytest tests/messagespasses (389 tests) andruff checkis clean.