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)
| 348 | |
| 349 | |
| 350 | def _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 | |
| 369 | def _get_cached(filename): |