Here's the information the Pylons developers and core users at the
time used to migrate their applications to Pyramid.
https://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/pylons/index.html
(Pyramid Cookbook, section "Pyramid for Pylons Users", written by me)
That was in 2012. I migrated my applications later when work resources
allowed, in 2017 and 2020. It was so long ago I'm afraid I don't
remember what Pylons code looks like, or what Genshi was like. We also
made the migration under Python 2, and some of the older tools were
never ported to Python 3.
I'd use the guide as background information to understand Pyramid, and
how certain Pylons features relate to their closest Pyramid
counterparts. I wouldn't use the specific tools mentioned (akhet,
pyramid_sqla) because they were never used much and may no longer
work. If your application uses webhelpers, it has been replaced by
webhelpers2, which has its own migration guide.
Some developer tried to mimic the Pylons application structure as
closely as possible in Pyramid; e.g., using a class for a group of
controllers, but the first real applications to be ported found it
better to switch to the native Pyramid paradigm rather than trying to
recreate a Pylons-like structure, so later conversions also followed
that approach (including mine). So I'd try to rethink your
application's functionality in a native Pyramid paradigm, rather than
trying to replicate a Pylons-like structure. When you can identify
more specific problems (e.g., how to migrate something in a Pylons
controller, or a specific route feature or temilating feature), then
we may be able to help more with those.
Pylons controllers were classes that grouped several view methods
together. I would port each view separately, as either a function or
class (your choice). If you go the class way, you can have a base
class for common functionality. The simplest base class is:
```
class View:
def ___init__(self, request):
self.request = request
```
If you go the function way, you'd put common functionality in utility functions.
There is a Genshi template adapter for Pyramid, 'pyramid_genshi'. I
don't know of anybody who has used it, or whether it still works. Most
Pylons developers migrated to Mako. Jinja2 and Chameleon get some use.
There's no way to reuse existing routes, globals, and application
setup, because those are the things that changed the most in Pyramid.
Pylons had a number of "magic" globals that you imported, and the
value was local to the current request. So you didn't have to pass
those around between functions; you could just import them in each
one. Pylons applications used these extensively, but they proved to be
fragile and to break easily. So most applications migrating to Pyramid
switched to explicit argument passing to eliminate the magic. That's a
large part of why you can't just use globals and setup code in Pyramid
the same way as in Python, and why WebHelpers2 had to restructure or
drop many helpers that WebHelpers had. Pyramid does have a few
"threadlocals" under the hood, but it's not recommended to use those
directly. Most of what in Pylons you'd import a magic global for, in
Pyramid you'd use the 'request' object.
The 'request' object is implicitly passed to templates in case it's
needed for this. E.g., Pyramid's 'request.route_path()' replaces
Pylons' magic 'url()' function. (It wasn't really a function, but
that's how it was used.) You can call that in the tempate, or
precalcuate the URLs in the views and pass them as template variables.
I've grown to prefer the latter, so that if an exception occurs, it
occurs in static Python code in your repository rather than in a
generated Python template module.
I'd follow one of the Pyramid tutorials to create a basic application,
and then try to add one view or feature from your application at a
time.
> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
pylons-discus...@googlegroups.com.
> To view this discussion visit
https://groups.google.com/d/msgid/pylons-discuss/5e27e69c-f7b6-47ed-917a-8c66d0537c4dn%40googlegroups.com.
--
Mike Orr <
slugg...@gmail.com>