Merge ~cjwatson/launchpad:schema-circular-imports-decentralize-remaining into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 64c013c907cf4c139d0db688c73b591ab372af3b
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:schema-circular-imports-decentralize-remaining
Merge into: launchpad:master
Diff against target: 348 lines (+60/-42)
14 files modified
dev/null (+0/-16)
lib/lp/buildmaster/interfaces/builder.py (+3/-1)
lib/lp/buildmaster/interfaces/buildfarmjob.py (+1/-2)
lib/lp/buildmaster/interfaces/webservice.py (+8/-0)
lib/lp/configure.zcml (+0/-1)
lib/lp/services/auth/interfaces.py (+1/-1)
lib/lp/services/auth/webservice.py (+5/-0)
lib/lp/services/comments/interfaces/conversation.py (+2/-4)
lib/lp/services/identity/interfaces/webservice.py (+1/-1)
lib/lp/services/messages/interfaces/message.py (+15/-5)
lib/lp/services/messages/interfaces/webservice.py (+22/-4)
lib/lp/services/temporaryblobstorage/webservice.py (+1/-1)
lib/lp/services/webservice/webservice.py (+1/-1)
lib/lp/services/worlddata/interfaces/webservice.py (+0/-5)
Reviewer Review Type Date Requested Status
Andrey Fedoseev (community) Approve
Review via email: mp+427630@code.launchpad.net

Commit message

Split up remaining circular import workarounds

Description of the change

I removed an unnecessary bit of circular import avoidance in `lp.services.comments.interfaces.conversation`.

To post a comment you must log in.
Revision history for this message
Andrey Fedoseev (andrey-fedoseev) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/_schema_circular_imports.py b/lib/lp/_schema_circular_imports.py
2deleted file mode 100644
3index 9231cad..0000000
4--- a/lib/lp/_schema_circular_imports.py
5+++ /dev/null
6@@ -1,54 +0,0 @@
7-# Copyright 2009-2021 Canonical Ltd. This software is licensed under the
8-# GNU Affero General Public License version 3 (see the file LICENSE).
9-
10-"""Update the interface schema values due to circular imports.
11-
12-There are situations where there would normally be circular imports to define
13-the necessary schema values in some interface fields. To avoid this the
14-schema is initially set to `Interface`, but this needs to be updated once the
15-types are defined.
16-"""
17-
18-__all__ = []
19-
20-from lp.bugs.interfaces.bugtask import IBugTask
21-from lp.buildmaster.interfaces.builder import IBuilder
22-from lp.buildmaster.interfaces.buildfarmjob import IBuildFarmJob
23-from lp.buildmaster.interfaces.buildqueue import IBuildQueue
24-from lp.code.interfaces.gitrepository import IGitRepository
25-from lp.registry.interfaces.person import IPerson
26-from lp.services.auth.interfaces import IAccessToken
27-from lp.services.comments.interfaces.conversation import IComment
28-from lp.services.messages.interfaces.message import (
29- IIndexedMessage,
30- IMessage,
31- IUserToUserEmail,
32-)
33-from lp.services.messages.interfaces.messagerevision import IMessageRevision
34-from lp.services.webservice.apihelpers import (
35- patch_collection_property,
36- patch_reference_property,
37-)
38-
39-# IBuilder
40-patch_reference_property(IBuilder, "current_build", IBuildFarmJob)
41-
42-# IBuildFarmJob
43-patch_reference_property(IBuildFarmJob, "buildqueue_record", IBuildQueue)
44-
45-# IComment
46-patch_reference_property(IComment, "comment_author", IPerson)
47-
48-# IIndexedMessage
49-patch_reference_property(IIndexedMessage, "inside", IBugTask)
50-
51-# IMessage
52-patch_reference_property(IMessage, "owner", IPerson)
53-patch_collection_property(IMessage, "revisions", IMessageRevision)
54-
55-# IUserToUserEmail
56-patch_reference_property(IUserToUserEmail, "sender", IPerson)
57-patch_reference_property(IUserToUserEmail, "recipient", IPerson)
58-
59-# IAccessToken
60-patch_reference_property(IAccessToken, "git_repository", IGitRepository)
61diff --git a/lib/lp/buildmaster/interfaces/builder.py b/lib/lp/buildmaster/interfaces/builder.py
62index 09e548d..75cfcfd 100644
63--- a/lib/lp/buildmaster/interfaces/builder.py
64+++ b/lib/lp/buildmaster/interfaces/builder.py
65@@ -232,7 +232,9 @@ class IBuilderView(IHasBuildRecords, IHasOwner):
66 title=_("Current build"),
67 required=False,
68 readonly=True,
69- schema=Interface, # Really IBuildFarmJob.
70+ # Really IBuildFarmJob, patched in
71+ # lp.buildmaster.interfaces.webservice.
72+ schema=Interface,
73 description=_("The job currently running on this builder."),
74 ),
75 as_of="devel",
76diff --git a/lib/lp/buildmaster/interfaces/buildfarmjob.py b/lib/lp/buildmaster/interfaces/buildfarmjob.py
77index f4200bd..f08ae96 100644
78--- a/lib/lp/buildmaster/interfaces/buildfarmjob.py
79+++ b/lib/lp/buildmaster/interfaces/buildfarmjob.py
80@@ -184,8 +184,7 @@ class IBuildFarmJobView(Interface):
81 )
82
83 buildqueue_record = Reference(
84- # Really IBuildQueue, set in _schema_circular_imports to avoid
85- # circular import.
86+ # Really IBuildQueue, patched in lp.buildmaster.interfaces.webservice.
87 schema=Interface,
88 required=True,
89 title=_("Corresponding BuildQueue record"),
90diff --git a/lib/lp/buildmaster/interfaces/webservice.py b/lib/lp/buildmaster/interfaces/webservice.py
91index 87d2c10..bd5d08c 100644
92--- a/lib/lp/buildmaster/interfaces/webservice.py
93+++ b/lib/lp/buildmaster/interfaces/webservice.py
94@@ -25,4 +25,12 @@ from lp.buildmaster.interfaces.buildfarmjob import (
95 CannotBeRetried,
96 IBuildFarmJob,
97 )
98+from lp.buildmaster.interfaces.buildqueue import IBuildQueue
99 from lp.buildmaster.interfaces.processor import IProcessor, IProcessorSet
100+from lp.services.webservice.apihelpers import patch_reference_property
101+
102+# IBuilder
103+patch_reference_property(IBuilder, "current_build", IBuildFarmJob)
104+
105+# IBuildFarmJob
106+patch_reference_property(IBuildFarmJob, "buildqueue_record", IBuildQueue)
107diff --git a/lib/lp/configure.zcml b/lib/lp/configure.zcml
108index a646f98..b8467e3 100644
109--- a/lib/lp/configure.zcml
110+++ b/lib/lp/configure.zcml
111@@ -41,7 +41,6 @@
112
113 <include file="permissions.zcml" />
114
115- <webservice:register module="lp.patchwebservice" />
116 <authorizations module="lp.security" />
117
118 <!-- The default Zope 3 configuration of the SimpleComponentTraverser is
119diff --git a/lib/lp/patchwebservice.py b/lib/lp/patchwebservice.py
120deleted file mode 100644
121index 20c84fb..0000000
122--- a/lib/lp/patchwebservice.py
123+++ /dev/null
124@@ -1,16 +0,0 @@
125-# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
126-# GNU Affero General Public License version 3 (see the file LICENSE).
127-
128-"""All the interfaces that are exposed through the webservice.
129-
130-There is a declaration in ZCML somewhere that looks like:
131- <webservice:register module="lp.patchwebservice" />
132-
133-which tells `lazr.restful` that it should look for webservice exports here.
134-"""
135-
136-# XXX: JonathanLange 2010-11-09 bug=673083: Legacy work-around for circular
137-# import bugs. Break this up into a per-package thing.
138-from lp import _schema_circular_imports
139-
140-_schema_circular_imports
141diff --git a/lib/lp/services/auth/interfaces.py b/lib/lp/services/auth/interfaces.py
142index 471d458..07e7c77 100644
143--- a/lib/lp/services/auth/interfaces.py
144+++ b/lib/lp/services/auth/interfaces.py
145@@ -69,7 +69,7 @@ class IAccessToken(Interface):
146 git_repository = Reference(
147 title=_("Git repository"),
148 description=_("The Git repository for which the token was issued."),
149- # Really IGitRepository, patched in _schema_circular_imports.py.
150+ # Really IGitRepository, patched in lp.services.auth.webservice.
151 schema=Interface,
152 required=True,
153 readonly=True,
154diff --git a/lib/lp/services/auth/webservice.py b/lib/lp/services/auth/webservice.py
155index ceb378a..99103cc 100644
156--- a/lib/lp/services/auth/webservice.py
157+++ b/lib/lp/services/auth/webservice.py
158@@ -8,4 +8,9 @@ __all__ = [
159 "IAccessTokenTarget",
160 ]
161
162+from lp.code.interfaces.gitrepository import IGitRepository
163 from lp.services.auth.interfaces import IAccessToken, IAccessTokenTarget
164+from lp.services.webservice.apihelpers import patch_reference_property
165+
166+# IAccessToken
167+patch_reference_property(IAccessToken, "git_repository", IGitRepository)
168diff --git a/lib/lp/services/comments/interfaces/conversation.py b/lib/lp/services/comments/interfaces/conversation.py
169index 5bccf9a..24712fa 100644
170--- a/lib/lp/services/comments/interfaces/conversation.py
171+++ b/lib/lp/services/comments/interfaces/conversation.py
172@@ -14,6 +14,7 @@ from zope.interface import Interface
173 from zope.schema import Bool, Datetime, Int, Text, TextLine
174
175 from lp import _
176+from lp.registry.interfaces.person import IPerson
177
178
179 class IComment(Interface):
180@@ -59,10 +60,7 @@ class IComment(Interface):
181 )
182
183 comment_author = Reference(
184- # Really IPerson.
185- Interface,
186- title=_("The author of the comment."),
187- readonly=True,
188+ IPerson, title=_("The author of the comment."), readonly=True
189 )
190
191 comment_date = Datetime(title=_("Comment date."), readonly=True)
192diff --git a/lib/lp/services/identity/interfaces/webservice.py b/lib/lp/services/identity/interfaces/webservice.py
193index 966bf65..fc32bc2 100644
194--- a/lib/lp/services/identity/interfaces/webservice.py
195+++ b/lib/lp/services/identity/interfaces/webservice.py
196@@ -4,7 +4,7 @@
197 """All the interfaces that are exposed through the webservice.
198
199 There is a declaration in ZCML somewhere that looks like:
200- <webservice:register module="lp.patchwebservice" />
201+ <webservice:register module="lp.services.identity.interfaces.webservice" />
202
203 which tells `lazr.restful` that it should look for webservice exports here.
204 """
205diff --git a/lib/lp/services/messages/interfaces/message.py b/lib/lp/services/messages/interfaces/message.py
206index fc83ad3..354a84e 100644
207--- a/lib/lp/services/messages/interfaces/message.py
208+++ b/lib/lp/services/messages/interfaces/message.py
209@@ -77,7 +77,12 @@ class IMessageCommon(Interface):
210 )
211 owner = exported(
212 Reference(
213- title=_("Person"), schema=Interface, required=False, readonly=True
214+ title=_("Person"),
215+ # Really IPerson, patched in
216+ # lp.services.messages.interfaces.webservice.
217+ schema=Interface,
218+ required=False,
219+ readonly=True,
220 )
221 )
222
223@@ -87,7 +92,8 @@ class IMessageCommon(Interface):
224 description=_(
225 "Revision history of this message, sorted in ascending order."
226 ),
227- # Really IMessageRevision, patched in _schema_circular_imports.
228+ # Really IMessageRevision, patched in
229+ # lp.services.messages.interfaces.webservice.
230 value_type=Reference(schema=Interface),
231 required=False,
232 readonly=True,
233@@ -241,10 +247,10 @@ class IIndexedMessage(Interface):
234
235 inside = Reference(
236 title=_("Inside"),
237+ # Really IBugTask, patched in
238+ # lp.services.messages.interfaces.webservice.
239 schema=Interface,
240- description=_(
241- "The bug task which is " "the context for this message."
242- ),
243+ description=_("The bug task which is the context for this message."),
244 required=True,
245 readonly=True,
246 )
247@@ -294,6 +300,8 @@ class IUserToUserEmail(Interface):
248 """User to user direct email communications."""
249
250 sender = Object(
251+ # Really IPerson, patched in
252+ # lp.services.messages.interfaces.webservice.
253 schema=Interface,
254 title=_("The message sender"),
255 required=True,
256@@ -301,6 +309,8 @@ class IUserToUserEmail(Interface):
257 )
258
259 recipient = Object(
260+ # Really IPerson, patched in
261+ # lp.services.messages.interfaces.webservice.
262 schema=Interface,
263 title=_("The message recipient"),
264 required=True,
265diff --git a/lib/lp/services/messages/interfaces/webservice.py b/lib/lp/services/messages/interfaces/webservice.py
266index 2eb1a38..420658e 100644
267--- a/lib/lp/services/messages/interfaces/webservice.py
268+++ b/lib/lp/services/messages/interfaces/webservice.py
269@@ -4,7 +4,7 @@
270 """All the interfaces that are exposed through the webservice.
271
272 There is a declaration in ZCML somewhere that looks like:
273- <webservice:register module="lp.patchwebservice" />
274+ <webservice:register module="lp.services.messages.interfaces.webservice" />
275
276 which tells `lazr.restful` that it should look for webservice exports here.
277 """
278@@ -14,8 +14,26 @@ __all__ = [
279 "IMessageRevision",
280 ]
281
282-from lp import _schema_circular_imports
283-from lp.services.messages.interfaces.message import IMessage
284+from lp.bugs.interfaces.bugtask import IBugTask
285+from lp.registry.interfaces.person import IPerson
286+from lp.services.messages.interfaces.message import (
287+ IIndexedMessage,
288+ IMessage,
289+ IUserToUserEmail,
290+)
291 from lp.services.messages.interfaces.messagerevision import IMessageRevision
292+from lp.services.webservice.apihelpers import (
293+ patch_collection_property,
294+ patch_reference_property,
295+)
296
297-_schema_circular_imports
298+# IIndexedMessage
299+patch_reference_property(IIndexedMessage, "inside", IBugTask)
300+
301+# IMessage
302+patch_reference_property(IMessage, "owner", IPerson)
303+patch_collection_property(IMessage, "revisions", IMessageRevision)
304+
305+# IUserToUserEmail
306+patch_reference_property(IUserToUserEmail, "sender", IPerson)
307+patch_reference_property(IUserToUserEmail, "recipient", IPerson)
308diff --git a/lib/lp/services/temporaryblobstorage/webservice.py b/lib/lp/services/temporaryblobstorage/webservice.py
309index 5218c46..7f03a9f 100644
310--- a/lib/lp/services/temporaryblobstorage/webservice.py
311+++ b/lib/lp/services/temporaryblobstorage/webservice.py
312@@ -4,7 +4,7 @@
313 """All the interfaces that are exposed through the webservice.
314
315 There is a declaration in ZCML somewhere that looks like:
316- <webservice:register module="lp.patchwebservice" />
317+ <webservice:register module="lp.services.temporaryblobstorage.webservice" />
318
319 which tells `lazr.restful` that it should look for webservice exports here.
320 """
321diff --git a/lib/lp/services/webservice/webservice.py b/lib/lp/services/webservice/webservice.py
322index a798f99..74a18a0 100644
323--- a/lib/lp/services/webservice/webservice.py
324+++ b/lib/lp/services/webservice/webservice.py
325@@ -4,7 +4,7 @@
326 """All the interfaces that are exposed through the webservice.
327
328 There is a declaration in ZCML somewhere that looks like:
329- <webservice:register module="lp.patchwebservice" />
330+ <webservice:register module="lp.services.webservice.webservice" />
331
332 which tells `lazr.restful` that it should look for webservice exports here.
333 """
334diff --git a/lib/lp/services/worlddata/interfaces/webservice.py b/lib/lp/services/worlddata/interfaces/webservice.py
335index 1ff5d14..036d5c9 100644
336--- a/lib/lp/services/worlddata/interfaces/webservice.py
337+++ b/lib/lp/services/worlddata/interfaces/webservice.py
338@@ -16,10 +16,5 @@ __all__ = [
339 "ILanguageSet",
340 ]
341
342-# XXX: JonathanLange 2010-11-09 bug=673083: Legacy work-around for circular
343-# import bugs. Break this up into a per-package thing.
344-from lp import _schema_circular_imports
345 from lp.services.worlddata.interfaces.country import ICountry, ICountrySet
346 from lp.services.worlddata.interfaces.language import ILanguage, ILanguageSet
347-
348-_schema_circular_imports

Subscribers

People subscribed via source and target branches

to status/vote changes: