Fix import in apigen.py, which fails when other scikits are present.

__import__ can get confused about which scikits path to import when multiple scikits are present on a system.

Note that `root_module` is no longer an attribute of `ApiDocWriter` (it wasn't being used anywhere), and it now points to "scikits.image" instead of "scikits".
This commit is contained in:
Tony S Yu
2011-07-10 15:47:32 -04:00
committed by Pieter Holtzhausen
parent 964de3d14a
commit f763b6ce3c
+10 -4
View File
@@ -92,15 +92,21 @@ class ApiDocWriter(object):
'''
# It's also possible to imagine caching the module parsing here
self._package_name = package_name
self.root_module = __import__(package_name)
self.root_path = self.root_module.__path__[-1]
self.root_path = os.path.join(self.root_path,
os.path.sep.join(package_name.split('.')[1:]))
root_module = self._import(package_name)
self.root_path = root_module.__path__[-1]
self.written_modules = None
package_name = property(get_package_name, set_package_name, None,
'get/set package_name')
def _import(self, name):
''' Import namespace package '''
mod = __import__(name)
components = name.split('.')
for comp in components[1:]:
mod = getattr(mod, comp)
return mod
def _get_object_name(self, line):
''' Get second token in line
>>> docwriter = ApiDocWriter('sphinx')