1 new changeset in apipkg: http://bitbucket.org/hpk42/apipkg/changeset/e7ffdd53c2bb/ changeset: r54:e7ffdd53c2bb user: hpk date: 2011-01-13 20:05:42 summary: small internal refinement to AliasModules - only useful when directly calling AliasModule(...) for now. affected #: 3 files (405 bytes)
--- a/apipkg.py Sat Nov 13 08:42:39 2010 +0100 +++ b/apipkg.py Thu Jan 13 20:05:42 2011 +0100 @@ -9,7 +9,7 @@ import sys from types import ModuleType -__version__ = '1.2.dev5' +__version__ = '1.2.dev6' def initpkg(pkgname, exportdefs, attr=dict()): """ initialize given package from the export definitions. """ @@ -136,18 +136,24 @@ __dict__ = property(__dict__) -def AliasModule(modname, modpath): +def AliasModule(modname, modpath, attrname=None): mod = [] def getmod(): if not mod: - mod.append(importobj(modpath, None)) + x = importobj(modpath, None) + if attrname is not None: + x = getattr(x, attrname) + mod.append(x) return mod[0] class AliasModule(ModuleType): def __repr__(self): - return '<AliasModule %r for %r>' % (modname, modpath) + x = modpath + if attrname: + x += "." + attrname + return '<AliasModule %r for %r>' % (modname, x) def __getattribute__(self, name): return getattr(getmod(), name) --- a/setup.py Sat Nov 13 08:42:39 2010 +0100 +++ b/setup.py Thu Jan 13 20:05:42 2011 +0100 @@ -19,7 +19,7 @@ description= 'apipkg: namespace control and lazy-import mechanism', long_description = open('README.txt').read(), - version='1.2.dev5', + version='1.2.dev6', url='http://bitbucket.org/hpk42/apipkg', license='MIT License', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], --- a/test_apipkg.py Sat Nov 13 08:42:39 2010 +0100 +++ b/test_apipkg.py Thu Jan 13 20:05:42 2011 +0100 @@ -402,6 +402,12 @@ import extra_attributes assert extra_attributes.foo == 'bar' +def test_aliasmodule_aliases_an_attribute(): + am = apipkg.AliasModule("mymod", "pprint", 'PrettyPrinter') + r = repr(am) + assert "<AliasModule 'mymod' for 'pprint.PrettyPrinter'>" == r + assert am.format + def test_aliasmodule_repr(): am = apipkg.AliasModule("mymod", "sys") r = repr(am) Repository URL: https://bitbucket.org/hpk42/apipkg/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. _______________________________________________ py-svn mailing list py-svn@codespeak.net http://codespeak.net/mailman/listinfo/py-svn