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.
To use version 0.7.3 of python SqlAlchemy it is nescesary to explicitly load it so as not to get the system version of SQLAlchemy. The prefered method is to auto adjust the import path as follows (which needs a Requires: added for python-setuptools): >>> import __main__; __main__.__requires__ = __requires__ = [] >>> __requires__.append('SQLAlchemy >= 0.6.3') >>> import pkg_resources; pkg_resources.require(__requires__) >>> import webob Note __requires__ may already be initialised, so if you need to update it, you can do something like: >>> try: >>> from __main__ import __requires__ >>> except ImportError: >>> import __main__ >>> __main__.__requires__ = [] >>> __requires__ = __main__.__requires__ >>> else: >>> if isinstance(basestring, __requires__): >>> __requires__ = [__requires__] Note also, that if something has already loaded pkg_resources, then any changes to __requires__ are ignored. This is the case for modules loaded by sphinx-build for example. To fix that, one can run a locally modified version of sphinx-build, or instead delve a bit deeper into pkg_resources to force it to load the parallel installed egg, like: >>> import sys >>> import pkg_resources >>> >>> # If there is a conflicting non egg module, >>> # i.e. an older standard system module installed, >>> # then replace it with this requirement >>> def replace_dist(requirement): >>> try: >>> return pkg_resources.require(requirement) >>> except pkg_resources.VersionConflict: >>> e = sys.exc_info()[1] >>> dist=e.args[0] >>> req=e.args[1] >>> if dist.key == req.key and not dist.location.endswith('.egg'): >>> del pkg_resources.working_set.by_key[dist.key] >>> # We assume there is no need to adjust sys.path >>> # and the associated pkg_resources.working_set.entries >>> return pkg_resources.require(requirement) >>> >>> print replace_dist("SQLALchemy >= 0.6.3") One can also resort to manually modifying sys.path with a hardcoded path like: >>> import sys >>> sys.path.insert(0, '/usr/lib64/python2.6/site-packages/SQLAlchemy-0.7.3-py2.6.egg')
_______________________________________________ cloud mailing list cloud@xxxxxxxxxxxxxxxxxxxxxxx https://admin.fedoraproject.org/mailman/listinfo/cloud