Move a PEP 3147/488 pyc file to its legacy pyc location. :param source: The file system path to the source file. The source file does not need to exist, however the PEP 3147/488 pyc file must exist or allow_compile must be set. :param allow_compile: If True, uses py_compile
(source, allow_compile=False)
| 57 | |
| 58 | |
| 59 | def make_legacy_pyc(source, allow_compile=False): |
| 60 | """Move a PEP 3147/488 pyc file to its legacy pyc location. |
| 61 | |
| 62 | :param source: The file system path to the source file. The source file |
| 63 | does not need to exist, however the PEP 3147/488 pyc file must exist or |
| 64 | allow_compile must be set. |
| 65 | :param allow_compile: If True, uses py_compile to create a .pyc if it does |
| 66 | not exist. This should be passed as True if cache_tag may be None. |
| 67 | :return: The file system path to the legacy pyc file. |
| 68 | """ |
| 69 | assert source.endswith('.py') |
| 70 | legacy_pyc = source + 'c' |
| 71 | try: |
| 72 | pyc_file = importlib.util.cache_from_source(source) |
| 73 | shutil.move(pyc_file, legacy_pyc) |
| 74 | except FileNotFoundError, NotImplementedError: |
| 75 | if not allow_compile: |
| 76 | raise |
| 77 | py_compile.compile(source, legacy_pyc, doraise=True) |
| 78 | return legacy_pyc |
| 79 | |
| 80 | |
| 81 | def import_module(name, deprecated=False, *, required_on=()): |
searching dependent graphs…