MCPcopy Index your code
hub / github.com/RustPython/RustPython / _get_sourcefile

Function _get_sourcefile

Lib/importlib/_bootstrap_external.py:350–366  ·  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

348
349
350def _get_sourcefile(bytecode_path):
351 """Convert a bytecode file path to a source path (if possible).
352
353 This function exists purely for backwards-compatibility for
354 PyImport_ExecCodeModuleWithFilenames() in the C API.
355
356 """
357 if len(bytecode_path) == 0:
358 return None
359 rest, _, extension = bytecode_path.rpartition('.')
360 if not rest or extension.lower()[-3:-1] != 'py':
361 return bytecode_path
362 try:
363 source_path = source_from_cache(bytecode_path)
364 except (NotImplementedError, ValueError):
365 source_path = bytecode_path[:-1]
366 return source_path if _path_isfile(source_path) else bytecode_path
367
368
369def _get_cached(filename):

Callers 3

test_get_sourcefileMethod · 0.90

Calls 5

lenFunction · 0.85
source_from_cacheFunction · 0.70
_path_isfileFunction · 0.70
rpartitionMethod · 0.45
lowerMethod · 0.45

Tested by 3

test_get_sourcefileMethod · 0.72