Code review comment for lp:~adiroiban/launchpad/bug-525371

Revision history for this message
Данило Шеган (danilo) wrote :

Hi Adi,

Thanks for the updates. There's still just a little bit more to do :)

У сре, 19. 05 2010. у 20:13 +0000, Adi Roiban пише:

> There are still some warnings for code like:
>
> @operation_parameters(
> pocket=Choice(
> title=_("Pocket"), required=True,
> vocabulary=DBEnumeratedType))
>
> and it looks fine to me, but pylint complains about:
>
> lib/lp/registry/interfaces/sourcepackage.py
> 191: [C0322, ISourcePackage.getBranch] Operator not preceded by a
> space
> required=True,
> ^
> vocabulary=DBEnumeratedType))
>
>
> > > == Pyflakes notices ==
> > >
> > > lib/lp/translations/interfaces/webservice.py
> > > 8: 'IHasTranslationImports' imported but unused
> > > 8: 'ITranslationImportQueue' imported but unused
> > > 8: 'ITranslationImportQueueEntry' imported but unused
> > > 13: 'IPOTemplate' imported but unused
> > > 15: 'IPOFile' imported but unused
> >
> > You should add the following to webservice.py if that's the intention:
> >
> > __all__ = [
> > 'IHasTranslationImports',
> > 'IPOFile',
> > 'IPOTemplate',
> > 'ITranslationImportQueue',
> > 'ITranslationImportQueueEntry',
> > ]
> >
> > But, why is this necessary?
>
> Only interfaces listed in webservices.py will be exported by
> lazr.restful.
>
> Adding __all__ will still generate Pyflakes notices as they are still
> unused in that file.

It actually fixed it for me. I'm attaching a patch which fixes all the
lint issues I've seen. It would be nicer if you did that instead :)

Also, "operator not preceded by space" lint issues in this particular
context seem to be opposed to our style guide. It would be best to
raise this on launchpad-dev mailing list to come to an agreement and to
see if we can fix either pylint or style guide.

> > > warning: Not importing directory '/usr/share/pyshared/lazr': missing
> > __init__.py
> > > warning: Not importing directory '/usr/share/pyshared/lazr': missing
> > __init__.py
> > > warning: Not importing directory '/usr/share/pyshared/lazr': missing
> > __init__.py
> >
> > This might be a bug in lazr that needs fixing. Can you please check and
> > file appropriate bug if it is?
>
> Is is not a problem in lazr. I have the same problem with:
> '/usr/share/pyshared/google': missing __init__.py
>
> Those file were installed as dependencies for ubuntuone-client-gnome by
> python-protobuf and python-lazr-uri, python-lazr-restfulclient and are
> maintained by main Ubuntu developers... not in the LP PPA.

Well, LAZR is a library shared between Launchpad and UbuntuOne. It's
still a bug that would need to be filed. I've worked-around it locally
by doing "sudo touch /usr/share/pyshared/lazr/__init__.py", and there is
probably no reason why the package shouldn't do the same for everybody.

> Should POTemplate and POFile API be available only to authenticated
> users?

Not, it's fine if they are anonymously available.

> > === modified file
> > 'lib/lp/registry/stories/webservice/xx-distroseries.txt'
> > === modified file
> > 'lib/lp/registry/stories/webservice/xx-project-registry.txt'
> > === modified file
> > 'lib/lp/registry/stories/webservice/xx-source-package.txt'
> >
> > It would be nice if we could unify these. And, I actually believe these
> > additions should be put into lib/lp/translations/stories/webservice
> > test instead: they are testing the IHasTranslationTemplates, not the
> > above objects.
>
> I moved them into
> lib/lp/translations/stories/webservice/xx-potemplate.txt

Thanks.

> > > === modified file 'lib/lp/translations/interfaces/potemplate.py'
> > ...
> > > source_file = Object(
> > > title=_('Source file for this translation template'),
> > > readonly=True, schema=ILibraryFileAlias)
> >
> > I don't remember why we decided not to export this one? It could be
> > useful for things like xpipo conversion (with XPI-based translations,
> > it should contain a reference to imported en-US.xpi).
> >
> > Though, we should probably just export it as the public URL, so not a
> > big deal (let's not block this branch on this).
>
> I will leave it for another branch, but for me, it would make sense if
> this attribute would be used for all translation templates, not only
> XPI.

Well, we can reconstruct the gettext POT file completely from what we
have in the DB. Thus, it's not needed.

> > > === modified file 'lib/lp/translations/interfaces/webservice.py'
> > > --- lib/lp/translations/interfaces/webservice.py 2009-07-17
> > 02:25:09
> > +0000
> > > +++ lib/lp/translations/interfaces/webservice.py 2010-05-19
> > 12:09:43
> > +0000
> > > @@ -1,9 +1,16 @@
> > > # Copyright 2009 Canonical Ltd. This software is licensed under the
> > > # GNU Affero General Public License version 3 (see the file LICENSE).
> > >
> > > +# pylint: disable-msg=W0611
> > > +
> > > """All the interfaces that are exposed through the webservice."""
> > >
> > > from lp.translations.interfaces.translationimportqueue import (
> > > IHasTranslationImports,
> > > ITranslationImportQueue,
> > > ITranslationImportQueueEntry)
> > > +
> > > +from lp.translations.interfaces.potemplate import (
> > > + IPOTemplate)
> > > +from lp.translations.interfaces.pofile import (
> > > + IPOFile)
> >
> > See comment above on the lint output.
>
> I added # pylint: disable-msg=W0611, but I don't know what else can be
> done to avoid the pyflakes warnings.

Add __all__: have you tried it at all? It totally works for me, and I'd
be very surprised if it doesn't work for you. Also, __all__ is required
in all our modules as well (importfascist used to check that before,
maybe it doesn't anymore)

> === modified file 'lib/lp/translations/interfaces/pofile.py'
> --- lib/lp/translations/interfaces/pofile.py 2010-03-08 21:06:34 +0000
> +++ lib/lp/translations/interfaces/pofile.py 2010-05-19 17:04:11 +0000
> @@ -127,9 +127,9 @@
> '''),
> required=False)
>
> - translation_messages = Attribute(_(
> - 'All `ITranslationMessage` objects related to this translation
> file.'
> - ))
> + translation_messages = Attribute(_('''
> + All `ITranslationMessage` objects related to this translation
> file.
> + '''))

Was this change really required? It makes the description contain a
bunch of spaces and newlines instead, which is not really desired.

Rest of it is good.

Cheers,
Danilo

1=== modified file 'lib/lp/registry/interfaces/distroseries.py'
2--- lib/lp/registry/interfaces/distroseries.py 2010-05-19 17:04:11 +0000
3+++ lib/lp/registry/interfaces/distroseries.py 2010-05-20 16:10:38 +0000
4@@ -114,7 +114,7 @@ class DistroSeriesVersionField(UniqueFie
5
6 def _validate(self, version):
7 """See `UniqueField`."""
8- super(DistroSeriesVersionField, self)._validate(version)
9+ DistroSeriesVersionField._validate(self, version)
10 if not sane_version(version):
11 raise LaunchpadValidationError(
12 "%s is not a valid version" % version)
13@@ -423,38 +423,38 @@ class IDistroSeriesPublic(
14
15 @operation_parameters(
16 created_since_date=Datetime(
17- title=_("Created Since Timestamp"),
18- description=_(
19+ title = _("Created Since Timestamp"),
20+ description = _(
21 "Return items that are more recent than this timestamp."),
22- required=False),
23+ required = False),
24 status=Choice(
25 # Really PackageUploadCustomFormat, patched in
26 # _schema_circular_imports.py
27- vocabulary=DBEnumeratedType,
28- title=_("Package Upload Status"),
29- description=_("Return only items that have this status."),
30- required=False),
31+ vocabulary = DBEnumeratedType,
32+ title = _("Package Upload Status"),
33+ description = _("Return only items that have this status."),
34+ required = False),
35 archive=Reference(
36 # Really IArchive, patched in _schema_circular_imports.py
37- schema=Interface,
38- title=_("Archive"),
39- description=_("Return only items for this archive."),
40- required=False),
41+ schema = Interface,
42+ title = _("Archive"),
43+ description = _("Return only items for this archive."),
44+ required = False),
45 pocket=Choice(
46 # Really PackagePublishingPocket, patched in
47 # _schema_circular_imports.py
48- vocabulary=DBEnumeratedType,
49- title=_("Pocket"),
50- description=_("Return only items targeted to this pocket"),
51- required=False),
52+ vocabulary = DBEnumeratedType,
53+ title = _("Pocket"),
54+ description = _("Return only items targeted to this pocket"),
55+ required = False),
56 custom_type=Choice(
57 # Really PackageUploadCustomFormat, patched in
58 # _schema_circular_imports.py
59- vocabulary=DBEnumeratedType,
60- title=_("Custom Type"),
61- description=_("Return only items with custom files of this "
62+ vocabulary = DBEnumeratedType,
63+ title = _("Custom Type"),
64+ description = _("Return only items with custom files of this "
65 "type."),
66- required=False),
67+ required = False)
68 )
69 # Really IPackageUpload, patched in _schema_circular_imports.py
70 @operation_returns_collection_of(Interface)
71
72=== modified file 'lib/lp/registry/interfaces/sourcepackage.py'
73--- lib/lp/registry/interfaces/sourcepackage.py 2010-05-17 10:16:03 +0000
74+++ lib/lp/registry/interfaces/sourcepackage.py 2010-05-20 16:13:43 +0000
75@@ -187,8 +187,8 @@ class ISourcePackage(IBugTarget, IHasBra
76 # in _schema_circular_imports.
77 @operation_parameters(
78 pocket=Choice(
79- title=_("Pocket"), required=True,
80- vocabulary=DBEnumeratedType))
81+ title = _("Pocket"), required = True,
82+ vocabulary = DBEnumeratedType))
83 # Actually returns an IBranch, but we say Interface here to avoid circular
84 # imports. Correct interface specified in _schema_circular_imports.
85 @operation_returns_entry(Interface)
86@@ -205,9 +205,9 @@ class ISourcePackage(IBugTarget, IHasBra
87 # imports. Correct interface specific in _schema_circular_imports.
88 @operation_parameters(
89 pocket=Choice(
90- title=_("Pocket"), required=True,
91- vocabulary=DBEnumeratedType),
92- branch=Reference(Interface, title=_("Branch"), required=False))
93+ title = _("Pocket"), required = True,
94+ vocabulary = DBEnumeratedType),
95+ branch = Reference(Interface, title = _("Branch"), required = False))
96 @call_with(registrant=REQUEST_USER)
97 @export_write_operation()
98 def setBranch(pocket, branch, registrant):
99
100=== modified file 'lib/lp/translations/interfaces/webservice.py'
101--- lib/lp/translations/interfaces/webservice.py 2010-05-18 15:27:05 +0000
102+++ lib/lp/translations/interfaces/webservice.py 2010-05-20 16:02:50 +0000
103@@ -14,3 +14,11 @@ from lp.translations.interfaces.potempla
104 IPOTemplate)
105 from lp.translations.interfaces.pofile import (
106 IPOFile)
107+
108+__all__ = [
109+ 'IHasTranslationImports',
110+ 'IPOFile',
111+ 'IPOTemplate',
112+ 'ITranslationImportQueue',
113+ 'ITranslationImportQueueEntry',
114+ ]
115
116=== modified file 'lib/lp/translations/model/potemplate.py'
117--- lib/lp/translations/model/potemplate.py 2010-05-17 10:16:03 +0000
118+++ lib/lp/translations/model/potemplate.py 2010-05-20 16:19:09 +0000
119@@ -1297,8 +1297,8 @@ class POTemplateSet:
120 elif sourcepackagename is None:
121 # Multiple matches, and for a product not a package.
122 logging.warn(
123- "Found %d templates with path '%s' for productseries %s" % (
124- len(matches), path, productseries.title))
125+ "Found %d templates with path '%s' for productseries %s",
126+ len(matches), path, productseries.title)
127 return None
128 else:
129 # Multiple matches, for a distribution package. Prefer a
130@@ -1316,9 +1316,9 @@ class POTemplateSet:
131 else:
132 logging.warn(
133 "Found %d templates with path '%s' for package %s "
134- "(%d matched on from_sourcepackagename)." % (
135- len(matches), path, sourcepackagename.name,
136- len(preferred_matches)))
137+ "(%d matched on from_sourcepackagename).",
138+ len(matches), path, sourcepackagename.name,
139+ len(preferred_matches))
140 return None
141
142 @staticmethod
143@@ -1510,10 +1510,6 @@ class POTemplateToTranslationFileDataAda
144 if flag
145 ])
146
147- # Store sequences so we can detect later whether we changed the
148- # message.
149- sequence = row.sequence
150-
151 # Store the message.
152 messages.append(msgset)
153
154

« Back to merge proposal