On 11/16/2011 12:53 AM, Toshio Kuratomi wrote:
Yep. It's not too hard to package parallel installable versions.
Getting
software to use it is the hard part. You can use setuptools to set python
to find the correct versions (which is the recommendations in the guidelines
I believe). The drawback is that setuptools is stupid about things
sometimes so you might get errors that you have problems figuring out
unless you have experience with it (I can help with that if you need it).
You can also manually set python's path (Either PYTHONPATH as an environment
variable or sys.path inside of python itself) to find the correct module
directory. The setuptools way looks something like this:
# The next section is not needed in most cases but in some cases, like using
# mod_wsgi to load a wsgi script this may be necessary
try:
from __main__ import __requires__
except ImportError:
__main__.__requires__ == []
__requires__ = __main__.__requires__
else:
if isinstance(basestring, __requires__):
__requires__ = [__requires__]
# This is where you add the parallel installable version
__requires__.append('SQLAlchemy >= 0.6')
# This is where you import pkg_resources. pkg_resources sets up the proper
# python paths when you import it for the first time. Unless you look at
# funny. Or talk bad about its mother
import pkg_resources
# This next one probably isn't necessary since we used __requires__ above
# Note that the pkg_resources docs only talk about the call talked about
# next but it's entirely inadequate for the job.
pkg_resources.require('SQLAlchemy >= 0.6')
import sqlalchemy
# Should print 0.6.?
print sqlalchemy.__version__
This is the way it looks modifying sys.path yourself. Note that you have to
change it when the python-sqlalchemy package is updated if you do it this
way and you use the easy_install recipe from the guidelines to install the
compat sqlalchemy package::
import sys
sys.path.insert(0,
'/usr/lib64/python2.7/site-packages/SQLAlchemy-0.7.1-py2.7.egg')
import sqlalchemy
print sqlalchemy.__version__
For the record I needed to dig a little deeper into pkg_resources
to get it to use the egg I wanted, rather than the system default.
I've attached the notes on this that I'm including with python-sqlalchemy0.7.
I will merge to
https://fedoraproject.org/wiki/Packaging:Python_Eggs#Multiple_Versions
if it proves robust.
cheers,
Pádraig.