MCPcopy Index your code
hub / github.com/python/cpython / _find_incompatible_extension_module

Function _find_incompatible_extension_module

Lib/traceback.py:1906–1932  ·  view source on GitHub ↗
(module_name)

Source from the content-addressed store, hash-verified

1904
1905
1906def _find_incompatible_extension_module(module_name):
1907 import importlib.machinery
1908 import importlib.resources.readers
1909
1910 if not module_name or not importlib.machinery.EXTENSION_SUFFIXES:
1911 return
1912
1913 # We assume the last extension is untagged (eg. .so, .pyd)!
1914 # tests.test_traceback.MiscTest.test_find_incompatible_extension_modules
1915 # tests that assumption.
1916 untagged_suffix = importlib.machinery.EXTENSION_SUFFIXES[-1]
1917 # On Windows the debug tag is part of the module file stem, instead of the
1918 # extension (eg. foo_d.pyd), so let's remove it and just look for .pyd.
1919 if os.name == 'nt':
1920 untagged_suffix = untagged_suffix.removeprefix('_d')
1921
1922 parent, _, child = module_name.rpartition('.')
1923 if parent:
1924 traversable = importlib.resources.files(parent)
1925 else:
1926 traversable = importlib.resources.readers.MultiplexedPath(
1927 *map(pathlib.Path, filter(os.path.isdir, sys.path))
1928 )
1929
1930 for entry in traversable.iterdir():
1931 if entry.name.startswith(child + '.') and entry.name.endswith(untagged_suffix):
1932 return entry.name

Callers 1

__init__Method · 0.85

Calls 7

iterdirMethod · 0.95
filterFunction · 0.70
removeprefixMethod · 0.45
rpartitionMethod · 0.45
filesMethod · 0.45
startswithMethod · 0.45
endswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…