Beispiel #1
0
 def _modules_from_buffer(self, buffer):
     finder = ModuleFinder(excludes=self.excludes)
     bufdir = os.path.dirname(buffer.name)
     sys.path.insert(0, bufdir)
     try:
         finder.load_module('__main__', buffer, '__main__.py', ('', 'r', 1))
     finally:
         sys.path.remove(bufdir)
     self.badmodules.update(finder.badmodules.keys())
     stdlib = sysconfig.get_python_lib(standard_lib=True)
     stdlib_local = sysconfig.get_python_lib(standard_lib=True,
                                             prefix='/usr/local')
     dist_packages = sysconfig.get_python_lib()
     stdlib_user_local = sysconfig.get_python_lib(
         standard_lib=True, prefix=f'{os.path.expanduser("~")}/.local')
     for module in finder.modules.values():
         if module.__file__ is None:
             continue
         elif module.__file__.startswith(stdlib):
             continue
         elif module.__file__.startswith(stdlib_local):
             continue
         elif module.__file__.startswith(dist_packages):
             continue
         elif module.__file__.startswith(stdlib_user_local):
             continue
         elif module.__file__ == buffer.name:
             continue
         elif module.__file__ == '__main__.py':
             continue
         elif module.__file__ in self.modules:
             continue
         self.modules.add(module.__file__)
         yield module
	def load_module( self, fqname, fp, pathname, file_info ):
		if pathname:
			if not isinstance( pathname, Path ):
				pathname = Path( pathname )

			if pathname.hasExtension( 'cmd' ):
				line = fp.readline().strip()
				suffix, mode, type = file_info[0], file_info[1], imp.PY_SOURCE  #pretend the cmd script is a py file
				assert '@setlocal' in line and '& python' in line, "Doesn't seem to be a python cmd script!"

		return ModuleFinder.load_module( self, fqname, fp, pathname, file_info )
    def load_module(self, fqname, fp, pathname, fileInfo):

        _, _, iFileType = fileInfo

        m = ModuleFinder.load_module(self, fqname, fp, pathname, fileInfo)

        if iFileType in self.moduleTypes:
            p = os.path.normpath(m.__file__).replace("\\", "/")
            if not osp.normcase(p).startswith(osp.normcase(SYS_EXEC_PREFIX)):
                m.__file__ = p
                self.loadedModules.append(m)

        return m
    def load_module(self, fqname, fp, pathname, fileInfo):

        _, _, iFileType = fileInfo

        m = ModuleFinder.load_module(self, fqname, fp, pathname, fileInfo)

        if iFileType in self.moduleTypes:
            p = os.path.normpath(m.__file__).replace("\\", "/")
            if not osp.normcase(p).startswith(osp.normcase(SYS_EXEC_PREFIX)):
                m.__file__ = p
                self.loadedModules.append(m)

        return m