[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: coming back to packaging multiple versions of libraries



On Jan 04, 2011, at 07:30 AM, Robert Collins wrote:

>It really does look like having better upstream facilities would make
>this a no-brainer for us; what I'd like to achieve though is something
>that /works/ for the existing python platform - for 2.7 which will be
>around a good long time, and then we'll have plenty of data to discuss
>with upstream.

Let's assume you can work out the distro-specific issues (e.g. how to name the
packages so that you can install wadllib1 and wadllib2 side-by side).  What
should work in Python would be to use .pth files.

http://docs.python.org/library/site.html

For example, let's say you have the following directory layout:

.../wadllib1/
    wadllib/
        __init__.py
        ...
.../waddlib2/
    wadllib/
        __init__.py
        ...

You can now install a wadllib.pth file that has the directory the version you
want to use by default, e.g.

.../wadllib.pth contains:
wadllib2

If wadllib.pth lives in the system site directory (or use site directory, but
let's ignore that), then when you 'import wadllib' you'd get version 2.

If wadllib.pth does not live in the site directory, then you have to
explicitly:

import site
site.addsitedir('/path/to/pth/files/')

to get Python to read and process the pth.  Also note that Debian/Ubuntu's
site.py has been modified from upstream, e.g. to add the dist-packages
directory.

If you wanted something more dynamic, you could exploit a trick in .pth
processing where any line that starts with 'import' gets executed.  Zope
packages exploit this; for example, when you have python-zope.interface
installed, see /usr/share/pyshared/zope.interface-3.6.1-nspkg.pth

Totally bogus strawman:

.../wadllib.pth contains:
import os, sys; p=os.environ.get('WADLLIBDIR'); (p not in sys.path) and sys.path.append(p)

You could now do:

WADLLIB=/path/to/version/you/want python -c 'import wadllib'

I'm sure you can come up with a much better mechanism to decide how to
dynamically locate the version you want.  The important things to remember are
that only lines that start with 'import' are executed, and you have to
obviously have your selection criteria set before Python reads your .pth file,
which in the case of those in the system site directory is at Python start up
time (unless you use python -S).

I hope that helps.  It's the best I could come up with that works with current
Python.  You still have to figure out the Debian packaging issues.

-Barry

Attachment: signature.asc
Description: PGP signature


Reply to: