← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging ~cjwatson/launchpad:inline-appsetup into launchpad:master.

Commit message:
Inline the relevant parts of zope.app.appsetup

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/407100

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.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:inline-appsetup into launchpad:master.
diff --git a/lib/lp/services/webapp/wsgi.py b/lib/lp/services/webapp/wsgi.py
index 8749a80..c097d5a 100644
--- a/lib/lp/services/webapp/wsgi.py
+++ b/lib/lp/services/webapp/wsgi.py
@@ -10,15 +10,32 @@ __all__ = [
 
 import logging
 
-from zope.app.appsetup import appsetup
 from zope.app.wsgi import WSGIPublisherApplication
+from zope.component.hooks import setHooks
+from zope.configuration import xmlconfig
+from zope.configuration.config import ConfigurationMachine
 from zope.event import notify
+from zope.interface import implementer
 from zope.processlifetime import DatabaseOpened
+from zope.security.interfaces import IParticipation
+from zope.security.management import (
+    endInteraction,
+    newInteraction,
+    system_user,
+    )
 
 from lp.services.config import config
 
 
+@implementer(IParticipation)
+class SystemConfigurationParticipation(object):
+
+    principal = system_user
+    interaction = None
+
+
 def get_wsgi_application():
+    # Loosely based on zope.app.appsetup.appsetup.
     features = []
     if config.launchpad.devmode:
         features.append("devmode")
@@ -26,7 +43,22 @@ def get_wsgi_application():
             "Developer mode is enabled: this is a security risk and should "
             "NOT be enabled on production servers. Developer mode can be "
             "turned off in launchpad-lazr.conf.")
-    appsetup.config("zcml/webapp.zcml", features=features)
+
+    # Set user to system_user, so we can do anything we want.
+    newInteraction(SystemConfigurationParticipation())
+
+    # Hook up custom component architecture calls.
+    setHooks()
+
+    # Load server-independent site config.
+    context = ConfigurationMachine()
+    xmlconfig.registerCommonDirectives(context)
+    for feature in features:
+        context.provideFeature(feature)
+    context = xmlconfig.file("zcml/webapp.zcml", context=context)
+
+    # Reset user.
+    endInteraction()
 
     # We don't use ZODB, but the webapp subscribes to IDatabaseOpened to
     # perform some post-configuration tasks, so emit that event manually.
diff --git a/requirements/launchpad.txt b/requirements/launchpad.txt
index e770039..0b1eefa 100644
--- a/requirements/launchpad.txt
+++ b/requirements/launchpad.txt
@@ -170,7 +170,6 @@ WSGIProxy2==0.4.6
 wsgiref==0.1.2
 z3c.pt==3.2.0
 z3c.ptcompat==2.2.0
-zope.app.appsetup==4.1.0
 zope.app.http==4.0.1
 zope.app.publication==4.3.1
 zope.app.publisher==4.2.0
diff --git a/setup.py b/setup.py
index 5c4f42d..a5f094a 100644
--- a/setup.py
+++ b/setup.py
@@ -248,7 +248,6 @@ setup(
         'Werkzeug',
         'WSGIProxy2',
         'z3c.ptcompat',
-        'zope.app.appsetup',
         'zope.app.http',
         'zope.app.publication',
         'zope.app.publisher',