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

Extraction check for CI integration #1034

Open
azmeuk opened this issue Oct 11, 2023 · 9 comments
Open

Extraction check for CI integration #1034

azmeuk opened this issue Oct 11, 2023 · 9 comments

Comments

@azmeuk
Copy link

azmeuk commented Oct 11, 2023

I would like to setup a CI job that would check if users have forgotten to extract the catalogs. The idea is that the CI would extract the catalogs, and fail if there was differences.

I was thinking a simple way to achieve this was to add a --dry-run for pybabel extract, that would return 0 if nothing changed and 1 elsewise. I suppose the return code would need to ignore some fields in the header that would always be updated (POT-Creation-Date or Generated-By).

What do you think?

Related to #910 and #725

@oprypin
Copy link
Contributor

oprypin commented Oct 11, 2023

@azmeuk
Copy link
Author

azmeuk commented Oct 11, 2023

I did not thought about this but this would be even simpler, thanks.

However, in any cases the POT-Creation-Date and the Generated-By headers are updated, and I could not find any option to ask pybabel to not update them.

Would a PR for adding options like --no-creation-date-update and --no-generated-by - or a --no-headers-update be OK?

@oprypin
Copy link
Contributor

oprypin commented Oct 11, 2023

Hm there is actually something for POT-Creation-Date

But maybe not for Generated-By

@oprypin
Copy link
Contributor

oprypin commented Oct 11, 2023

Also there is update-header-comment, but that's just for the # comment. Doesn't seem to be a way to avoid updating Generated-By, it would be nice.

@oprypin
Copy link
Contributor

oprypin commented Oct 11, 2023

This command might do it?

git diff --exit-code --ignore-matching-lines '^"(POT-Creation-Date|Generated-By):'

@oprypin
Copy link
Contributor

oprypin commented Oct 11, 2023

But I think I'd like to have a way to avoid updating Generated-By, or a flag to override its value.
Then this can be used for not only checking diffs in CI but actually applying them automatically too.

Just note that I'm not a contributor to this project, I'm just making random comments 😅

@azmeuk
Copy link
Author

azmeuk commented Oct 11, 2023

Thank your for your investigation and your workaround. I will try to test this soon.

@azmeuk
Copy link
Author

azmeuk commented Oct 12, 2023

Strangely enough, the --ignore-matching-lines seems to not be very constant:

git clone https://github.com/numerique-gouv/b3desk.git
cd b3desk
make install-dev
make translation-extract

git diff -I "POT-Creation-Date"
# expected result, POT-Creation-Date diff is hidden

git diff -I "Generated-By"
# unexpectedly, Generated-By diff is NOT hidden

git diff -I "#:"
# Most location comments are hidden, but not everyone.

It feels like a bug in git though and not related to python-babel.

@oprypin
Copy link
Contributor

oprypin commented Oct 12, 2023

Yes it is like that, it's not a bug in Git but instead it's a stupid but documented behavior.

The behavior is: show diff hunks where at least one line still differs after filtering undesired lines.

So:
if you filter out all irrelevant lines within 1 command
and there is no diff
then you can be sure that there are no other diffs
(and exit status 0 is consistent)

If instead there is still some diff
then there were in fact other diffs
but the diff output is pretty much garbage
(exit status 1 is still 100% correctly returned though!)

Not ideal for sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants