On Jul 28, 2006, at 3:12 AM, Alex Greif wrote:

> my web application still uses Pylons 0.8. After upgrading to 0.9, do I
> have to convert my project in some way, of is 0.9 fully backwards
> compatible?

There is a high degree of backwards compatibility, and some projects  
will run without any change under 0.9. Things to note that will cause  
breakage (this will be in the docs soon):

* The 'm' object is gone in 0.9. There is a pseudo-m object still  
around when in legacy mode (0.8 apps will trigger this by default). The  
pseudo-m object does the most common things people have been using 'm'  
for in their controller: m.subexec, m.comp, m.scomp, m.abort,  
m.send_redirect, m.write and m.out. If you're doing something with 'm'  
in your controller that isn't one of those, you'll need to use the  
appropriate 0.9 way of doing it.

Other big steps (copied from a prior thread message):

New Call-Cycle
-----------------------

This is the most significant change in 0.9. The request-cycle is  
substantially simpler. In 0.8, controllers were called inside of Myghty  
using a custom Myghty resolver class that used Routes.

In 0.9, the request is handled in a WSGI call, the URL is looked up  
with Routes, and the controller is called. It is then expected that a  
Response object or a plain WSGI body is returned from the controller.  
(I'll have a pretty diagram showing the simpler request cycle soon)

There are no assumptions about what template language is used, just  
that either a Response object is returned, or WSGI content (an  
iterable) comes back. To make it easy to render templates and return  
the response object, there's some convenience functions for templating:
http://pylonshq.com/docs/0.9/module-pylons.templating.html

So a template render in an index action looks like:
def index(self):
     return render_response('/my/template.myt')


Legacy Mode
--------------------

To ensure that 0.8 apps work with as little modification (none at all  
in most cases), Pylons 0.9 has a legacy mode. It's activated when your  
initialize the main WSGI app in your middleware.py file with:
app = pylons.wsgiapp.make_app(config)

In new 0.9 projects, the lines that initializes the main WSGI app is:
     app = pylons.wsgiapp.PylonsApp(config)

Legacy mode add's two minor changes to the request cycle which can be  
seen on line 79 and 103:
http://pylonshq.com/project/pylonshq/browser/Pylons/trunk/pylons/ 
wsgiapp.py

103 sets up a 'm' object that acts like the Myghty object in 0.8, and  
it creates a Response object in a thread-local to buffer the content  
the m object writes out. Line 79 then pulls that Response object when  
the controller fails to return anything. That's pretty much all it  
takes to have 0.8 legacy compatibility.


Upgrading a 0.8 App
-----------------------------

There's two ways you can go about upgrading your app to 0.9. Out of the  
box, 99% of your 0.8 app should *just work* under 0.9.

1) Stick with 'legacy' mode and slowly convert your actions to return  
Response objects. This will first require you to update  
yourprojb/lib/base.py, so that it imports the additional names you  
need, and your BaseController needs to return the Controller call  
instead of just calling it. This in your BaseController, this line:
Controller.__call__(self, action, **params)

Should be:
return Controller.__call__(self, **params)

And make sure to add the following imports in base.py as well:
from pylons import Controller, c, g, h, cache, request, response,  
session
from pylons.decorators import jsonify, rest, validate
from pylons.templating import render, render_fragment, render_response,  
\
     render_response_fragment

You can then slowly convert your actions to return response or return  
render_response calls.

2) Update your project templates to 0.9, and immediately remove all  
references to the 'm' object. This step could also be done after Step 1  
for a more graceful switch-over. Updating your templates can be done by  
running paster over your app:
paster create --template=pylons yourproj

It will prompt you to overwrite, replace, diff, or backup any existing  
files that have changed in Pylons 0.9. I'd suggest having them backed  
up, then copying in your changes as needed to the new files.

You'll then need to go through and replace m.subexec calls with return  
render_response('/template....') calls.


Most of this information will be refined and put up in the new 0.9 docs  
section that we're working on.



> Or is the best way to create a new project with 0.9 and port everything
> manually from the old 0.8 version?

Hopefully the above helps. If there's sections that need clarification,  
let me know so we can address them.

HTH,
Ben


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss
-~----------~----~----~----~------~----~------~--~---

Reply via email to