Created
September 15, 2025 10:43
-
-
Save leontrolski/b552750e0a4f0292d8af213f597cb481 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ast | |
| from pathlib import Path | |
| depends_on = set[tuple[str, str]]() | |
| for p in (Path()).glob("*.py"): | |
| x = p.stem | |
| for node in ast.parse(p.read_text()).body: | |
| match node: | |
| case ast.ImportFrom(module=str(module), names=names): | |
| out = set[str]() | |
| split = module.split(".") | |
| for i, [part, next_part] in enumerate(zip(split, split[1:] + [None])): | |
| for match in ["queries", "data"]: | |
| prefix = ".".join(split[: i + 1]) | |
| if part == match: | |
| if next_part is None: | |
| for alias in names: | |
| depends_on.add((x, f"{prefix}.{alias.name}")) | |
| else: | |
| depends_on.add((x, f"{prefix}.{next_part}")) | |
| for x, y in sorted(depends_on): | |
| print(x, y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment