1. Ronny Pfannschmidt
  2. pylib-hacks

Commits

holger krekel  committed cc45fac

upgrade apipkg.py

  • Participants
  • Parent commits 1e85d46
  • Branches trunk

Comments (0)

Files changed (2)

File CHANGELOG

View file
 Changes between 1.3.4 and 2.0.0dev0
 ==================================================
 
-- py.test was moved to its own "pytest" package
-- command line tools moved to "pytools" package
-- pylib now only has some cross-platform utilities
+- py.test was moved to a separate "pytest" package. What remains is
+  a stub hook which will proxy ``import py.test`` to ``pytest``.
+- all command line tools ("py.cleanup/lookup/countloc/..." moved 
+  to "pytools" package)
 - removed the old deprecated "py.magic" namespace
+- use apipkg-1.1
 
 Changes between 1.3.3 and 1.3.4
 ==================================================

File py/apipkg.py

View file
 import sys
 from types import ModuleType
 
-__version__ = "1.0b7"
+__version__ = "1.1"
 
-def initpkg(pkgname, exportdefs):
+def initpkg(pkgname, exportdefs, attr=dict()):
     """ initialize given package from the export definitions. """
     oldmod = sys.modules[pkgname]
     d = {}
     if f:
         f = os.path.abspath(f)
     d['__file__'] = f
-    d['__version__'] = getattr(oldmod, '__version__', '0')
+    if hasattr(oldmod, '__version__'):
+        d['__version__'] = oldmod.__version__
     if hasattr(oldmod, '__loader__'):
         d['__loader__'] = oldmod.__loader__
     if hasattr(oldmod, '__path__'):
         d['__path__'] = [os.path.abspath(p) for p in oldmod.__path__]
+    if hasattr(oldmod, '__doc__'):
+        d['__doc__'] = oldmod.__doc__
+    d.update(attr)
     oldmod.__dict__.update(d)
     mod = ApiModule(pkgname, exportdefs, implprefix=pkgname, attr=d)
     sys.modules[pkgname]  = mod
 
 def importobj(modpath, attrname):
     module = __import__(modpath, None, None, ['__doc__'])
-    if attrname:
-        return getattr(module, attrname)
-    return module
+    if not attrname:
+        return module
+
+    retval = module
+    names = attrname.split(".")
+    for x in names:
+        retval = getattr(retval, x)
+    return retval
 
 class ApiModule(ModuleType):
     def __init__(self, name, importspec, implprefix=None, attr=None):