Example #1
0
    def load_module(self, fullname):
        rank = MPI.COMM_WORLD.Get_rank()
        #        print "[%d] load_module: %s %s %s %s" % (rank, fullname, self.file, self.filename, self.stuff)
        mod = mpiimporter.load_module(fullname, self.file, self.filename, self.stuff)
        if self.file:
            self.file.close()
        mod.__loader__ = self  # for introspection

                               #        print "[%d] load_module loaded: %s" % (rank, mod)
        return mod
Example #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!")
Example #3
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!")