def load_module(self, fullname):
        """Load the module fullname using cached path."""
        if fullname in self._cache:
            if fullname in sys.modules:
                return sys.modules[fullname]
            pathname, desc = self._cache[fullname]
            #print "__LOADING ",fullname,pathname

            ignore, ext = os.path.splitext(pathname)
            target_path = [os.path.dirname(pathname)]

            subname = fullname.split(".")[-1]

            if os.path.isfile(pathname):
                # (If we're loading a PY_SOURCE file, the interpreter will
                # automatically check for a compiled (.py[c|o]) file.)

                if ext == '.so':
                    file, filename, stuff = imp.find_module(
                        subname, target_path)
                    mod = imp.load_module(fullname, file, pathname, desc)
                else:
                    file, filename, stuff = mpiimporter.find_module(
                        subname, target_path)
                    mod = mpiimporter.load_module(fullname, file, pathname,
                                                  desc)

                if file:
                    file.close()
            # Not a file, so it's a package directory
            else:
                file, filename, stuff = mpiimporter.find_module(
                    subname, target_path)
                mod = mpiimporter.load_module(fullname, file, pathname, desc)

            mod.__loader__ = self  # for introspection
            return mod
        raise ImportError("This shouldn't happen!")
Beispiel #2
0
    def load_module(self,fullname):
        """Load the module fullname using cached path."""
        if fullname in self._cache:
            if fullname in sys.modules:
                return sys.modules[fullname]
            pathname,desc = self._cache[fullname]
            #print "__LOADING ",fullname,pathname


            ignore, ext = os.path.splitext(pathname)
            target_path = [os.path.dirname(pathname)]
            
            subname = fullname.split(".")[-1]

            if os.path.isfile(pathname):
                # (If we're loading a PY_SOURCE file, the interpreter will
                # automatically check for a compiled (.py[c|o]) file.)


                if ext == '.so':
                    file, filename, stuff = imp.find_module(subname, target_path)
                    mod = imp.load_module(fullname,file,pathname,desc)
                else:
                    file, filename, stuff = mpiimporter.find_module(subname, target_path)
                    mod = mpiimporter.load_module(fullname,file,pathname,desc)

                if file:
                    file.close()
            # Not a file, so it's a package directory
            else:
                file, filename, stuff = mpiimporter.find_module(subname, target_path)
                mod = mpiimporter.load_module(fullname,file,pathname,desc)

            mod.__loader__ = self  # for introspection
            return mod
        raise ImportError("This shouldn't happen!")
Beispiel #3
0
    def find_module(self, fullname, path=None):
        rank = MPI.COMM_WORLD.Get_rank()
        #        print "[%d] find_module %s %s" % (rank, fullname, path)

        subname = fullname.split(".")[-1]
        if subname != fullname and path is None:
            return None
        try:
            file, filename, stuff = mpiimporter.find_module(subname, path)
        except ImportError:
            #            print ImportError
            return None

        #        print "[%d] find_module found: %s %s" % (rank, file, filename)

        ignore, ext = os.path.splitext(filename)

        if ext == '.so':
            file, filename, stuff = imp.find_module(subname, path)
            return ImpLoader(file, filename, stuff)
        
        return Loader(file, filename, stuff)