Pylons/Pyramid hybrid?

23 views
Skip to first unread message

Wyatt Baldwin

unread,
Feb 16, 2011, 3:09:55 PM2/16/11
to pylons-...@googlegroups.com
I would like to move from Pylons 1.0 to Pyramid, but I'm not going to be able manage a wholesale port any time soon. So, I'm wondering if it would be practical to start using some parts of Pyramid within an existing Pylons project.

In particular, one of the problems I'm having with Pylons is with configuration extensibility. I've got something working, but it feels clunky and is somewhat confusing. I haven't looked too closely at Pyramid, but it seems like its config system makes gathering & merging config from various locations a bit simpler.

Has anyone done anything like this? Would any of the devs be able to advise on whether this an idea worth pursuing?

Chris McDonough

unread,
Feb 16, 2011, 3:34:23 PM2/16/11
to pylons-...@googlegroups.com

One idea is to use a Pyramid "NotFound
view" (http://docs.pylonsproject.org/projects/pyramid/1.0/narr/hooks.html#changing-the-not-found-view) which delegates to the existing Pylons application, and port piecemeal. Unfortunately we don't have any current example of doing such a thing, but it would involve something like this during Pyramid configuration:

class LegacyView(object):
def __init__(self, app):
self.app = app # app is the legacy Pylons app

def __call__(self, request):
return request.get_response(self.app)

if __name__ == '__main__':
pylonsapp = ... obtain pylons WSGI application object ...
legacy_view = LegacyView(pylonsapp)
config = Configurator()
config.add_view(context=NotFound, view=legacy_view)
... rest of config ...

At that point, whenever Pyramid cannot service a request because the URL
doesn't match anything, it will invoke the Pylons application as a
fallback, which will return things normally.

At that point you can start moving logic incrementally into Pyramid from
the Pylons application until you've ported everything.

- C


Wyatt Baldwin

unread,
Feb 16, 2011, 9:18:51 PM2/16/11
to pylons-...@googlegroups.com
Thanks for that. I added it to my project almost verbatim, and it works as advertised. I'll report back when I get further into the port.
Reply all
Reply to author
Forward
0 new messages