Пример #1
0
 def _sub_modules(self):
     """
     Lists modules in the directory of this module (if this module is a
     package).
     """
     path = self._module.path
     names = []
     if path is not None and path.endswith(os.path.sep + '__init__.py'):
         mods = pkgutil.iter_modules([os.path.dirname(path)])
         for module_loader, name, is_pkg in mods:
             name = helpers.FakeName(name)
             # It's obviously a relative import to the current module.
             imp = helpers.FakeImport(name, self, level=1)
             name.parent = imp
             names.append(name)
     return names
    def _sub_modules_dict(self):
        """
        Lists modules in the directory of this module (if this module is a
        package).
        """
        path = self._module.path
        names = {}
        if path is not None and path.endswith(os.path.sep + '__init__.py'):
            mods = pkgutil.iter_modules([os.path.dirname(path)])
            for module_loader, name, is_pkg in mods:
                fake_n = helpers.FakeName(name)
                # It's obviously a relative import to the current module.
                imp = helpers.FakeImport(fake_n, self, level=1)
                fake_n.parent = imp
                names[name] = [fake_n]

        # TODO add something like this in the future, its cleaner than the
        #   import hacks.
        # ``os.path`` is a hardcoded exception, because it's a
        # ``sys.modules`` modification.
        #if str(self.name) == 'os':
        #    names.append(helpers.FakeName('path', parent=self))

        return names
Пример #3
0
 def _generate_name(self, name):
     # Create a pseudo import to be able to follow them.
     name = helpers.FakeName(name)
     imp = helpers.FakeImport(name, parent=self.module)
     name.parent = imp
     return name