Ejemplo n.º 1
0
    def find_spec(self, fullname, target=None):
        """Create a ModuleSpec for the specified module.

        Returns None if the module cannot be found.
        """
        module_info = _get_module_info(self, fullname)
        if module_info is not None:
            return _bootstrap.spec_from_loader(fullname,
                                               self,
                                               is_package=module_info)
        else:
            # Not a module or regular package. See if this is a directory, and
            # therefore possibly a portion of a namespace package.

            # We're only interested in the last path component of fullname
            # earlier components are recorded in self.prefix.
            modpath = _get_module_path(self, fullname)
            if _is_dir(self, modpath):
                # This is possibly a portion of a namespace
                # package. Return the string representing its path,
                # without a trailing separator.
                path = f'{self.archive}{path_sep}{modpath}'
                spec = _bootstrap.ModuleSpec(name=fullname,
                                             loader=None,
                                             is_package=True)
                spec.submodule_search_locations.append(path)
                return spec
            else:
                return None
Ejemplo n.º 2
0
 def find_spec(cls, fullname, path=None, target=None):
     path = fullname.replace(".", "/")
     for zname, z in cls._packages.items():
         mi, fullpath = _get_module_info(z, path)
         if mi is not None:
             return _bootstrap.spec_from_loader(
                 fullname, cls, origin=f"zip:{zname}/{fullpath}", is_package=mi
             )
     return None