()
| 69 | |
| 70 | |
| 71 | def main() -> int: |
| 72 | if (opt := parse_cmdline()).container: |
| 73 | return run_in_container(opt.container) |
| 74 | |
| 75 | logging.basicConfig(level=opt.log_level, format="%(levelname)s %(message)s") |
| 76 | |
| 77 | if (current_ver := ".".join(map(str, sys.version_info[:2]))) != PYVER: |
| 78 | logger.warning( |
| 79 | "Expecting output generated by Python %s; you are running %s instead.", |
| 80 | PYVER, |
| 81 | current_ver, |
| 82 | ) |
| 83 | logger.warning( |
| 84 | "You might get spurious changes that will be rejected by the CI linter." |
| 85 | ) |
| 86 | logger.warning( |
| 87 | "(use %s {--docker | --podman} to run it with Python %s in a container)", |
| 88 | sys.argv[0], |
| 89 | PYVER, |
| 90 | ) |
| 91 | |
| 92 | if not opt.all: |
| 93 | inputs, outputs = [], [] |
| 94 | for fpin in opt.inputs: |
| 95 | fpout = fpin.parent / fpin.name.replace("_async", "") |
| 96 | if fpout.stat().st_mtime >= fpin.stat().st_mtime: |
| 97 | logger.debug("not converting %s as %s is up to date", fpin, fpout) |
| 98 | continue |
| 99 | inputs.append(fpin) |
| 100 | outputs.append(fpout) |
| 101 | if not outputs: |
| 102 | logger.info("all output files are up to date, nothing to do") |
| 103 | return 0 |
| 104 | |
| 105 | else: |
| 106 | inputs = opt.inputs |
| 107 | outputs = [fpin.parent / fpin.name.replace("_async", "") for fpin in inputs] |
| 108 | |
| 109 | if opt.jobs == 1: |
| 110 | logger.debug("multi-processing disabled") |
| 111 | for fpin, fpout in zip(inputs, outputs): |
| 112 | convert(fpin, fpout) |
| 113 | else: |
| 114 | with ProcessPoolExecutor(max_workers=opt.jobs) as executor: |
| 115 | executor.map(convert, inputs, outputs) |
| 116 | |
| 117 | if opt.check: |
| 118 | return check([str(o) for o in outputs]) |
| 119 | |
| 120 | return 0 |
| 121 | |
| 122 | |
| 123 | def convert(fpin: Path, fpout: Path) -> None: |
no test coverage detected