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

Function _get_sourcefile

Lib/importlib/_bootstrap_external.py:339–355  ·  view source on GitHub ↗

Convert a bytecode file path to a source path (if possible). This function exists purely for backwards-compatibility for PyImport_ExecCodeModuleWithFilenames() in the C API.

(bytecode_path)

Source from the content-addressed store, hash-verified

337
338
339def _get_sourcefile(bytecode_path):
340 """Convert a bytecode file path to a source path (if possible).
341
342 This function exists purely for backwards-compatibility for
343 PyImport_ExecCodeModuleWithFilenames() in the C API.
344
345 """
346 if len(bytecode_path) == 0:
347 return None
348 rest, _, extension = bytecode_path.rpartition('.')
349 if not rest or extension.lower()[-3:-1] != 'py':
350 return bytecode_path
351 try:
352 source_path = source_from_cache(bytecode_path)
353 except (NotImplementedError, ValueError):
354 source_path = bytecode_path[:-1]
355 return source_path if _path_isfile(source_path) else bytecode_path
356
357
358def _get_cached(filename):

Callers 3

test_get_sourcefileMethod · 0.90

Calls 4

source_from_cacheFunction · 0.85
_path_isfileFunction · 0.85
rpartitionMethod · 0.45
lowerMethod · 0.45

Tested by 3

test_get_sourcefileMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…