Merge lp:~jtv/launchpad/recife-diverge into lp:~launchpad/launchpad/recife
| Status: | Merged |
|---|---|
| Merged at revision: | 9168 |
| Proposed branch: | lp:~jtv/launchpad/recife-diverge |
| Merge into: | lp:~launchpad/launchpad/recife |
| Diff against target: |
380 lines (+288/-12) 6 files modified
lib/lp/testing/factory.py (+5/-11) lib/lp/testing/tests/test_factory.py (+0/-1) lib/lp/translations/interfaces/translationmessage.py (+3/-0) lib/lp/translations/model/potmsgset.py (+64/-0) lib/lp/translations/model/translationmessage.py (+9/-0) lib/lp/translations/tests/test_translationmessage.py (+207/-0) |
| To merge this branch: | bzr merge lp:~jtv/launchpad/recife-diverge |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Michael Nelson (community) | code | 2010-09-02 | Approve on 2010-09-09 |
|
Review via email:
|
|||
Commit Message
TranslationMess
Description of the Change
= approveAsDiverged =
For the Recife feature branch. This implements the option to approve a translation suggestion, not as the new shared translation as you'd normally want, but as a diverged translation specific to one particular POTemplate.
Interface-wise, the new method is on TranslationMessage: "approve this one in this POFile." The actual implementation is in POTMsgSet, where all the supporting infrastructure is, and the published one forwards to it.
To test:
{{{
./bin/test -vvc lp.translations
}}}
(Although of course I ran the rest of 'em as well).
I also seized this opportunity to replace a factory method, previously a hack to work around the lack of this new method, to do things more properly.
No lint,
Jeroen
| Michael Nelson (michael.nelson) wrote : | # |
| Данило Шеган (danilo) wrote : | # |
У чет, 02. 09 2010. у 13:55 +0000, Michael Nelson пише:
>
> Should it be obvious to me what traits.
> means, without going and looking it up?
It should at least be "more obvious". We should probably make the
method be named "traits.
different branch ("make the traits class understandable"), because
setFlags was not introduced with this branch.
Anyway, I agree we should make code more understandable and I am sure
Jeroen and you can make a good job out of it :)
> + def test_makeCounte
> > + # self.factory.
side by
> > + # default. self._makeCount
the
> > + # Ubuntu side.
> > + pofile = self.factory.
> > + other_pofile = self._makeCount
> > +
> > + self.assertEqua
> > + self.assertNotE
> > + pofile.
> > + other_pofile.
>
> Wow... a test for your factory method.
That should be a norm these days (perhaps worth raising in the reviewers
meeting if not everybody is aware of it :). Though, that's for "real"
factory methods with tests in lib/lp/
| Jeroen T. Vermeulen (jtv) wrote : | # |
Hi Michael,
As I mentioned on IRC when you started on this, it's a good thing to get an outside view from time to time. Like Soyuz, Translations suffers from a lot of "inside knowledge" that one needs before certain things become clear. We'll try to come up with a clearer naming pattern for the TranslationSide
I greatly simplified approveAsDiverged, leaving a sequence of top-level "if"s and two early return statements as the only signs of structural complexity.
With that, on to your individual notes:
> > === modified file 'lib/lp/
> > --- lib/lp/
> > +++ lib/lp/
> > @@ -2300,18 +2298,16 @@
> > """Create a diverged, current `TranslationMes
> > if pofile is None:
> > pofile = self.makePOFile
> > + if reviewer is None:
> > + reviewer = self.makePerson()
> >
> > # This creates a suggestion, then diverges it, then activates it.
> > # Once we have a method for diverging messages, do this in a more
> > # proper way.
>
> With your changes below, is it time to update the above comment?
Yes, thank you for spotting that. This is exactly the change that that comment foreshadowed.
> > === modified file 'lib/lp/
> > --- lib/lp/
> > +++ lib/lp/
> > @@ -1145,6 +1145,61 @@
> > template.
> 'translationsug
> > template.
> >
> > + def approveAsDiverg
> > + lock_timestamp=
> > + """Approve a suggestion to become a diverged translation."""
> > + template = pofile.potemplate
> > + traits = getUtility(
> > + template.
> > + if suggestion.
> traits.
> > + # The suggestion is already current and diverged for the
> > + # right template.
> > + return suggestion
>
> Could this be extracted (so that this method doesn't deal with traits and
> flags - which I have no idea about), into
> suggestion.
I was unable to extract the traits and the flags, because they are at the very core of what this message does. But you could say I managed to simplify everything else so that the intent of the traits-related code stands out more.
Also, I introduced some explanatory variables. This is a say-it-in-code pattern: give an expression or statement a name, not because it's long or complex or highly reusable, but because it allows the code that uses it to be phrased in terms of intent rather than implementationn.
As a relevant example, we used to say "foo.potemplate is None" instead of "foo.is_diverged" and that worked relatively well, but the introduction of the i...
| Michael Nelson (michael.nelson) wrote : | # |
On Wed, Sep 8, 2010 at 5:16 AM, Jeroen T. Vermeulen <email address hidden> wrote:
> Hi Michael,
>
> As I mentioned on IRC when you started on this, it's a good thing to get an outside view from time to time. Like Soyuz, Translations suffers from a lot of "inside knowledge" that one needs before certain things become clear. We'll try to come up with a clearer naming pattern for the TranslationSide
>
> I greatly simplified approveAsDiverged, leaving a sequence of top-level "if"s and two early return statements as the only signs of structural complexity.
Great! Thanks Jeroen. In summary, it's much easier for me to
understand now. Approved, with a few comments that you can
take-or-leave below.
Cheers,
Michael
>
> With that, on to your individual notes:
>
[snip]
>
>> > === modified file 'lib/lp/
>> > --- lib/lp/
>> > +++ lib/lp/
>> > @@ -1145,6 +1145,61 @@
>> > template.
>> 'translationsug
>> > template.
>> >
>> > + def approveAsDiverg
>> > + lock_timestamp
>> > + """Approve a suggestion to become a diverged translation."""
>> > + template = pofile.potemplate
>> > + traits = getUtility(
>> > + template.
>> > + if suggestion.
>> traits.
>> > + # The suggestion is already current and diverged for the
>> > + # right template.
>> > + return suggestion
>>
>> Could this be extracted (so that this method doesn't deal with traits and
>> flags - which I have no idea about), into
>> suggestion.
>
> I was unable to extract the traits and the flags, because they are at the very core of what this message does. But you could say I managed to simplify everything else so that the intent of the traits-related code stands out more.
>
> Also, I introduced some explanatory variables. This is a say-it-in-code pattern: give an expression or statement a name, not because it's long or complex or highly reusable, but because it allows the code that uses it to be phrased in terms of intent rather than implementationn.
Yes, that makes a huge difference! Small point: you could move the
definition of used_on_other_side down to where it is first checked.
>
> As a relevant example, we used to say "foo.potemplate is None" instead of "foo.is_diverged" and that worked relatively well, but the introduction of the is_diverged attribute made a lot of code much clearer despite hiding the relationship between divergence and potemplate.
>
>
>> > +
>> > + incumbent = traits.
>> pofile.language)
>> > + if incumbent is not None:
>> > + self._
>> > + if incumben...

Hi Jeroen,
As a person not-so-familiar with the translations infrastructure, I find a lot about this branch hard to understand... but I'm not sure if they are things that are just due to the complexity of the problem, or could be improved by the vocabulary. See what you think. To me it seems to be going the direction that soyuz went a while ago (methods that are hard for anyone without insider knowledge to understand) and we've been trying to make it easier to maintain ever since.
Also, if possible, it would be great if approvedAsDiver ged() could be simplified (by creating smaller methods that encapsulate sections of it... some thoughts below).
That said, if you look at what I've written and think it doesn't apply, I'll recant and approve - but I would love to be able to understand more easily what's going on in this branch.
> === modified file 'lib/lp/ testing/ factory. py' testing/ factory. py 2010-09-01 13:47:24 +0000 testing/ factory. py 2010-09-02 12:37:46 +0000 sage`." "" ('lt')
> --- lib/lp/
> +++ lib/lp/
> @@ -2300,18 +2298,16 @@
> """Create a diverged, current `TranslationMes
> if pofile is None:
> pofile = self.makePOFile
> + if reviewer is None:
> + reviewer = self.makePerson()
>
> # This creates a suggestion, then diverges it, then activates it.
> # Once we have a method for diverging messages, do this in a more
> # proper way.
With your changes below, is it time to update the above comment?
> - message = self.makeShared TranslationMess age( tion( potmsgset, translator= translator, translations, suggestion=True) ITranslationSid eTraitsSet) .getTraits( potemplate. translation_ side) roxy(message) .potemplate = pofile.potemplate setFlag( message, True) translations) approveAsDiverg ed(pofile, reviewer) (self, pofile, sequence, translations/ model/potmsgset .py' translations/ model/potmsgset .py 2010-09-01 15:11:18 +0000 translations/ model/potmsgset .py 2010-09-02 12:37:46 +0000 awardKarma( translator, 'translationsug gestionapproved ') awardKarma( reviewer, 'translationrev iew') ed(self, pofile, suggestion, reviewer, None): ITranslationSid eTraitsSet) .getTraits( translation_ side) potemplate == template and traits. getFlag( suggestion) :
> + message = self.makeSugges
> pofile=pofile, potmsgset=
> - reviewer=reviewer, translations=
> - traits = getUtility(
> - pofile.
> - removeSecurityP
> - traits.
> - return message
> + translations=
> + return message.
>
> def makeTranslation
> english=None, translated=None,
>
> === modified file 'lib/lp/
> --- lib/lp/
> +++ lib/lp/
> @@ -1145,6 +1145,61 @@
> template.
> template.
>
> + def approveAsDiverg
> + lock_timestamp=
> + """Approve a suggestion to become a diverged translation."""
> + template = pofile.potemplate
> + traits = getUtility(
> + template.
> + if suggestion.
> + # The suggestion is already current and diverged for the
> + # right template.
> + return suggestion
Could this be extracted (so that this method...