Merge ~cjwatson/launchpad:inline-appsetup into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 3e55bab17c634d3052ef243e2265323ffff87b5c
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:inline-appsetup
Merge into: launchpad:master
Diff against target: 86 lines (+34/-4)
3 files modified
lib/lp/services/webapp/wsgi.py (+34/-2)
requirements/launchpad.txt (+0/-1)
setup.py (+0/-1)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+407100@code.launchpad.net

Commit message

Inline the relevant parts of zope.app.appsetup

Description of the change

zope.app.appsetup has relatively heavy dependencies (e.g. ZODB), and we don't need most of it. It's nearly as easy to do the small amount of it that we do need directly.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/services/webapp/wsgi.py b/lib/lp/services/webapp/wsgi.py
2index 8749a80..c097d5a 100644
3--- a/lib/lp/services/webapp/wsgi.py
4+++ b/lib/lp/services/webapp/wsgi.py
5@@ -10,15 +10,32 @@ __all__ = [
6
7 import logging
8
9-from zope.app.appsetup import appsetup
10 from zope.app.wsgi import WSGIPublisherApplication
11+from zope.component.hooks import setHooks
12+from zope.configuration import xmlconfig
13+from zope.configuration.config import ConfigurationMachine
14 from zope.event import notify
15+from zope.interface import implementer
16 from zope.processlifetime import DatabaseOpened
17+from zope.security.interfaces import IParticipation
18+from zope.security.management import (
19+ endInteraction,
20+ newInteraction,
21+ system_user,
22+ )
23
24 from lp.services.config import config
25
26
27+@implementer(IParticipation)
28+class SystemConfigurationParticipation(object):
29+
30+ principal = system_user
31+ interaction = None
32+
33+
34 def get_wsgi_application():
35+ # Loosely based on zope.app.appsetup.appsetup.
36 features = []
37 if config.launchpad.devmode:
38 features.append("devmode")
39@@ -26,7 +43,22 @@ def get_wsgi_application():
40 "Developer mode is enabled: this is a security risk and should "
41 "NOT be enabled on production servers. Developer mode can be "
42 "turned off in launchpad-lazr.conf.")
43- appsetup.config("zcml/webapp.zcml", features=features)
44+
45+ # Set user to system_user, so we can do anything we want.
46+ newInteraction(SystemConfigurationParticipation())
47+
48+ # Hook up custom component architecture calls.
49+ setHooks()
50+
51+ # Load server-independent site config.
52+ context = ConfigurationMachine()
53+ xmlconfig.registerCommonDirectives(context)
54+ for feature in features:
55+ context.provideFeature(feature)
56+ context = xmlconfig.file("zcml/webapp.zcml", context=context)
57+
58+ # Reset user.
59+ endInteraction()
60
61 # We don't use ZODB, but the webapp subscribes to IDatabaseOpened to
62 # perform some post-configuration tasks, so emit that event manually.
63diff --git a/requirements/launchpad.txt b/requirements/launchpad.txt
64index e770039..0b1eefa 100644
65--- a/requirements/launchpad.txt
66+++ b/requirements/launchpad.txt
67@@ -170,7 +170,6 @@ WSGIProxy2==0.4.6
68 wsgiref==0.1.2
69 z3c.pt==3.2.0
70 z3c.ptcompat==2.2.0
71-zope.app.appsetup==4.1.0
72 zope.app.http==4.0.1
73 zope.app.publication==4.3.1
74 zope.app.publisher==4.2.0
75diff --git a/setup.py b/setup.py
76index 5c4f42d..a5f094a 100644
77--- a/setup.py
78+++ b/setup.py
79@@ -248,7 +248,6 @@ setup(
80 'Werkzeug',
81 'WSGIProxy2',
82 'z3c.ptcompat',
83- 'zope.app.appsetup',
84 'zope.app.http',
85 'zope.app.publication',
86 'zope.app.publisher',

Subscribers

People subscribed via source and target branches

to status/vote changes: