[Web-SIG] more comments on Paste Deploy

Ian Bicking ianb at colorstudy.com
Thu Mar 8 00:35:35 CET 2007

Jeff Shell wrote:
> But in theory, since Zope 3 has `zope.app.wsgi`, I could serve from...
> anything? I guess that since I don't think about serving via Twisted
> any more than I thought about serving via ZServer, I could put
> CherryPy, mod_wsgi, whatever else underneath, right?

In theory you can set up Zope 3 using something like:

   paste.app_factory = some_function_yet_to_be_written

I thought zope.paste did this, but it's a little wonky now that I look 
at it.  It seems to basically read INSTANCE_HOME and create a single 
Zope WSGI app, and then kind of minimally plug into it.  That function 
would more ideally look like:

   from zope.app.wsgi import getWSGIApplication

   def make_zope_app(global_conf, instance_home=None, configfile=None):
       if configfile is None:
           configfile = global_conf.get('configfile')
       if configfile is None:
           if instance_home is None:
               instance_home = global_conf.get('instance_home')
           if not instance_home:
               raise ValueError(
                   'You must give a configfile or instance_home value')
           configfile = os.path.join(instance_home, 'etc', 'zope.conf')
       app = getWSGIApplication(configfile)
       return app

Then in Zope's setup.py:

     main = zope.some_module:make_zope_app

Then you'd configure it like:

   use = egg:Zope
   # Same directory as the config file:
   instance_home = %(here)s
   # instead of "use", and if you didn't set up the entry point:
   paste.app_factory = zope.some_module.make_zope_app

And you'd set up a server like:

   # CherryPy doesn't natively provide this entry point...
   use = egg:PasteScript#cherrypy
   # or...
   #use = egg:Paste#http, egg:Flup#scgi, etc
   host =
   port = 8080

Put both those sections in one file (say, deploy.ini) and then do:

   $ paster serve deploy.ini

And it'll start up.  Additionally, instead of plugging that app directly 
into a server, you could wrap it with different kinds of middleware, 
which is where it starts looking a bit more interesting.  For instance, 
for Paste's interactive debugger:

   use = egg:Zope ...
   filter-with = egg:Paste#evalerror

Though that probably won't quite work, because we don't all agree on a 
way to indicate to the app that it shouldn't catch unexpected errors 
(Zope uses environ['wsgi.handleErrors']); which is incidentally what 
this proposed spec would help us agree on: 

Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org

More information about the Web-SIG mailing list