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)
| 337 | |
| 338 | |
| 339 | def _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 | |
| 358 | def _get_cached(filename): |
searching dependent graphs…