コード例 #1
0
ファイル: find.py プロジェクト: tbenthompson/cppimport
def find_module_path(module_name, search_path=None):
    """
    Find the module path (pyd / so), while accounting for platform/arch naming
    :param module_name: The name of the module
    :param search_path: The path to search in. If None, searches system path.
    :return: The full path to the library or None if not found.
    """

    # Use importlib if python 3.4+, else imp
    if sys.version_info[0] > 3 or (sys.version_info[0] == 3 and sys.version_info[1] >= 4):

        from importlib.machinery import FileFinder, ExtensionFileLoader, EXTENSION_SUFFIXES
        file_finder = FileFinder(search_path, (ExtensionFileLoader, EXTENSION_SUFFIXES))

        # The search caches must be cleared to guaranteed find dynamically created modules
        file_finder.invalidate_caches()
        result = file_finder.find_spec(module_name)
        return None if not result else result.origin
    else:
        from imp import find_module  # Deprecated in 3.4
        try:
            result = find_module(module_name, [search_path])
        except ImportError:
            result = None

        return None if not result else result[1]
コード例 #2
0
def find_module_path(module_name, search_path=None):
    """
    Find the module path (pyd / so), while accounting for platform/arch naming
    :param module_name: The name of the module
    :param search_path: The path to search in. If None, searches system path.
    :return: The full path to the library or None if not found.
    """

    # Use importlib if python 3.4+, else imp
    if sys.version_info[0] > 3 or (sys.version_info[0] == 3
                                   and sys.version_info[1] >= 4):

        from importlib.machinery import FileFinder, ExtensionFileLoader, EXTENSION_SUFFIXES
        file_finder = FileFinder(search_path,
                                 (ExtensionFileLoader, EXTENSION_SUFFIXES))

        # The search caches must be cleared to guaranteed find dynamically created modules
        file_finder.invalidate_caches()
        result = file_finder.find_spec(module_name)
        return None if not result else result.origin
    else:
        from imp import find_module  # Deprecated in 3.4
        try:
            result = find_module(module_name, [search_path])
        except ImportError:
            result = None

        return None if not result else result[1]
コード例 #3
0
ファイル: __init__.py プロジェクト: ImAvinashSharma/sip-py
def load_module(name, path=None):
    finder = FileFinder(path, *_loader_details)
    spec = finder.find_spec(name)
    if not spec or not spec.loader:
        raise ImportError(f"no module named {name}")
    mod = module_from_spec(spec)
    spec.loader.exec_module(mod)
    return mod
コード例 #4
0
ファイル: FunWithLoaders.py プロジェクト: beantaxi/dev
def loadModule (path):
	folder = os.path.dirname(path)
	filename = os.path.basename(path)
	(moduleName, dot, extension) = filename.rpartition(filename)
	loaderArgs = (SourceFileLoader, [dot+extension])
	finder = FileFinder(folder, loaderArgs)
	spec = finder.find_spec(moduleName)
	module = importlib.util.module_from_spec(spec)
	loader = spec.loader
	module.moduleSpec = spec
	module.exec = lambda: loader.exec_module(module)
	return module
コード例 #5
0
ファイル: _helpers.py プロジェクト: Omer80/jitcode
 def find_and_load_module(modulename, folder=""):
     finder = FileFinder(folder, loader_details)
     spec = finder.find_spec(modulename)
     module = module_from_spec(spec)
     spec.loader.exec_module(module)
     return module
コード例 #6
0
ファイル: _helpers.py プロジェクト: Omer80/jitcode
 def find_and_load_module(modulename, folder=""):
     finder = FileFinder(folder, loader_details)
     spec = finder.find_spec(modulename)
     return spec.loader.load_module()
コード例 #7
0
ファイル: _helpers.py プロジェクト: Omer80/jitcode
 def get_module_path(modulename, folder=""):
     finder = FileFinder(folder, loader_details)
     return finder.find_spec(modulename).origin
コード例 #8
0
ファイル: _helpers.py プロジェクト: kiaderouiche/jitcode
		def find_and_load_module(modulename, folder=""):
			finder = FileFinder(folder, loader_details)
			spec = finder.find_spec(modulename)
			module = module_from_spec(spec)
			spec.loader.exec_module(module)
			return module
コード例 #9
0
ファイル: _helpers.py プロジェクト: kiaderouiche/jitcode
		def find_and_load_module(modulename, folder=""):
			finder = FileFinder(folder, loader_details)
			spec = finder.find_spec(modulename)
			return spec.loader.load_module()
コード例 #10
0
ファイル: _helpers.py プロジェクト: kiaderouiche/jitcode
	def get_module_path(modulename, folder=""):
		finder = FileFinder(folder, loader_details)
		return finder.find_spec(modulename).origin