From f763b6ce3ce2f644c24ab39a56d1040eaa462f73 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Sun, 10 Jul 2011 15:47:32 -0400 Subject: [PATCH] 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". --- doc/tools/apigen.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/tools/apigen.py b/doc/tools/apigen.py index 5c86db8f..58a82fda 100644 --- a/doc/tools/apigen.py +++ b/doc/tools/apigen.py @@ -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')