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

Bug 1321279 - Read target FTL files before migrations. #24

Merged
merged 2 commits into from
Nov 3, 2017

Conversation

stasm
Copy link
Contributor

@stasm stasm commented Oct 30, 2017

Copy link
Contributor

@Pike Pike left a comment

Choose a reason for hiding this comment

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

This looks generally good, got some inline nits, and, we'll need to adjust https://github.com/stasm/python-fluent/blob/00443015fb5fd0901649bcece2d9b69b1a27ae9e/tools/migrate/migrate-l10n.py#L65 now that a migration might actually not do anything. That should raise an hglib.errors.CommandError when trying to commit without file changes. We want to catch and pass that, I guess?

except UnicodeDecodeError as err:
logger = logging.getLogger('migrate')
logger.error('Error reading file {}: {}'.format(refpath, err))
sys.exit()
Copy link
Contributor

Choose a reason for hiding this comment

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

Raise a custom exception for these, and then in main(), parser.exit()?

Cleaner, and also makes the exit code become 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, that's going to be cleaner indeed. I'll still use sys.exit because I don't have access to the ArgumentParser instance inside of main. Also parser.exit is just a wrapper around sys.exit anyways, intended AFAICT for errors about the argument setup.

@stasm
Copy link
Contributor Author

stasm commented Nov 2, 2017

we'll need to adjust https://github.com/stasm/python-fluent/blob/00443015fb5fd0901649bcece2d9b69b1a27ae9e/tools/migrate/migrate-l10n.py#L65 now that a migration might actually not do anything. That should raise an hglib.errors.CommandError when trying to commit without file changes. We want to catch and pass that, I guess?

What do you mean by "pass"? The Python pass or "hand off" to someone or something?

FWIW, here's the output after applying the PR when trying to run the same migrations a second time:

Annotating /home/stas/moz/l10n-central/it
Running migration examples.bug_1291693
Running migration examples.about_dialog
Running migration examples.about_downloads

No commits are made. Would you like to throw instead?

@stasm stasm force-pushed the 1321279-read-ftl-when-migrating branch from 0044301 to e38a550 Compare November 2, 2017 12:51
@stasm stasm requested a review from Pike November 2, 2017 13:15
Copy link
Contributor

@Pike Pike left a comment

Choose a reason for hiding this comment

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

Can you adjust the comment in https://github.com/stasm/python-fluent/blob/e38a55086f66279418d512a9f9fc1f400c8e28a7/fluent/migrate/context.py#L259 to include the case where all our migrations are already in the existing localization?

That's the thing that makes us not even hit the hg commit line now, which I thought we would ;-)

Also, tests/migrate/fixtures/pl/existing.ftl doesn't seem to be used?

Lastly, the tests for NotSupportedError are done once per subclass of Source, should we just have a test_source.py and test that once?

`in_changeset`; then check for an existing translation in the current FTL
`localization` or for a migration specification in `transforms`.
reference, first check for an existing translation in the current FTL
`localization` and return early if it's present; then if the string has
Copy link
Contributor

Choose a reason for hiding this comment

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

The "return early" here is confusing, because merge_entry returns early, not merge_resource.


# Migrate an extra string to populate the iterator returned by
# ctx.merge_changeset(). Otherwise it won't yield anything if the
# merged contents are the same as the existing file.
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at how confused I was that that could happen, maybe it's worth explicitly testing that re-applying a transform returns an empty merge_changeset?

@stasm stasm requested a review from Pike November 3, 2017 14:42
@stasm stasm force-pushed the 1321279-read-ftl-when-migrating branch from 95747f1 to eb9108e Compare November 3, 2017 15:01
Read target Fluent localization files before migrating translations into
them from legacy resources.  This change also explicitly prohibits
specifying Fluent resources as sources of migration. They could only be
used with the COPY transform anyways.
Remove MergeContext.add_reference in favor of an additional argument to
MergeContext.add_transforms. This removes the redundancy of speficying
the destination path twice.
@stasm stasm force-pushed the 1321279-read-ftl-when-migrating branch from eb9108e to 9de0f5d Compare November 3, 2017 16:36
@stasm stasm merged commit fee4c63 into projectfluent:master Nov 3, 2017
@stasm stasm deleted the 1321279-read-ftl-when-migrating branch November 3, 2017 16:40
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