Source

cpython_sandbox / Lib / test / test_importlib / extension / util.py

Full commit
from importlib import machinery
import os
import sys

def _find_named_module(name):
    # Scans sys.path for a suitably name extension file
    for path in sys.path:
        for ext in machinery.EXTENSION_SUFFIXES:
            filename = name + ext
            filepath = os.path.join(path, filename)
            if os.path.exists(filepath):
                return path, ext, filename, filepath
    return (None,) * 4

class ExtensionModuleInfo:

    def __init__(self, name):
        self.name = name
        self.path, self.ext, self.filename, self.filepath = (
            _find_named_module(name))

# Default extension module for testing
NAME = '_testcapi'
_testcapi_info = ExtensionModuleInfo(NAME)
PATH = _testcapi_info.path
EXT = _testcapi_info.ext
FILENAME = _testcapi_info.filename
FILEPATH = _testcapi_info.filepath

# Other extension modules for testing
_testimportexec_info = ExtensionModuleInfo("_testimportexec")