multiversioning __import__ and modules?
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-dist...>: 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
On Fri, Apr 17, 2009 at 12:28 AM, Garrett Cooper <yanegomi@gmail.com> wrote:
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-dist...>:
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
Sorry... I lost track of my original bright idea until now. What I meant was something more along the lines of: __import__(name[, globals[, locals[, fromlist[,level][,version=None]]]]])¶ The modified examples: 1. Importer requires PackageA v1.5: __import__('PackageA', version="==1.5") 2. Importer requires any version of PackageB between v1.6 and v1.8, minus v1.7 (buggy version): __import__('PackageB', version=">=1.6, !=1.7, <=1.8") 3. Importer requires any PackageC version less than v0.1.10: __import__('PackageC', version="<0.1.10") 4. Importer requires any version of PackageD: __import__('PackageD') Thanks, -Garrett
participants (1)
-
Garrett Cooper