[Distutils] multiversioning __import__ and modules?

Garrett Cooper yanegomi at gmail.com
Fri Apr 17 09:28:09 CEST 2009


Hi guys,
    I realize this may not look like a distutils question, but it's
closely tied to distutils and setuptools.
    I did some exploring today and it appears that there isn't a
simple way to profile different versioned packages and bootstrap one
version as the master version without going through the trouble of
implementing a lot of what virtualenv does.
    What I thought might be a good idea (and I'm just tossing it out
to see what others might think), is to apply logic to __import__ that
is similar to setuptools.pkg_resources.require() when importing
packages. Here's the new API I was thinking of:

    __import__(name[, globals[, locals[, fromlist[,
level][,version=None][,requires=expr]]]]])¶

    expr can be anything of the form described under
<http://docs.python.org/distutils/setupscript.html#relationships-between-distributions-and-packages>:

    Here are some explicit examples using the new API:

    1. PackageA v2.0 requires PackageB v1.5:

    __import__('PackageA', version="2.0", requires="PackageB==1.5")

    2. PackageC v2.1 requires any PackageD version between v1.6 and
v1.8, minus v1.7 (buggy version):

    __import__('PackageC', version="2.1", requires="PackageD >=1.6,
!=1.7, <=1.8")

    3. PackageE v0.1.0 requires any PackageF version less than v0.1.10:

    __import__('PackageE', version="0.1.0", requires="PackageF<0.1.10")

    4. PackageG requires any version of PackageH:

    __import__('PackageG', requires="PackageH")

    Thoughts?
Thanks,
-Garrett


More information about the Distutils-SIG mailing list