()
| 90 | |
| 91 | |
| 92 | def main() -> None: |
| 93 | sync_dir = SRC / "_sync" |
| 94 | if sync_dir.exists(): |
| 95 | shutil.rmtree(sync_dir) |
| 96 | |
| 97 | async_files = discover_async_files() |
| 98 | |
| 99 | with tempfile.TemporaryDirectory() as tmpdir: |
| 100 | tmp = Path(tmpdir) |
| 101 | # Stage preprocessed copies under tmp/_async/ so unasync sees a clean |
| 102 | # tree without the marker blocks. Mirror directory layout. |
| 103 | staged: list[str] = [] |
| 104 | for relpath in async_files: |
| 105 | src = SRC / relpath |
| 106 | dst = tmp / relpath |
| 107 | dst.parent.mkdir(parents=True, exist_ok=True) |
| 108 | dst.write_text(REMOVE_BLOCK.sub("", src.read_text())) |
| 109 | staged.append(str(dst)) |
| 110 | |
| 111 | rule = unasync.Rule( |
| 112 | fromdir=str(tmp / "_async") + "/", |
| 113 | todir=str(SRC / "_sync") + "/", |
| 114 | additional_replacements=REPLACEMENTS, |
| 115 | ) |
| 116 | unasync.unasync_files(staged, [rule]) |
| 117 | |
| 118 | # Prepend the "do not edit" header to every generated file. unasync |
| 119 | # writes its output verbatim, so the header has to be added after the |
| 120 | # fact rather than as part of the rule. |
| 121 | for path in sync_dir.rglob("*.py"): |
| 122 | path.write_text(GENERATED_HEADER + path.read_text()) |
| 123 | |
| 124 | print(f"✓ generated {sync_dir.relative_to(ROOT)} from _async/") |
| 125 | |
| 126 | |
| 127 | if __name__ == "__main__": |
no test coverage detected