Skip to content

Instantly share code, notes, and snippets.

@leontrolski
Created September 15, 2025 10:43
Show Gist options
  • Select an option

  • Save leontrolski/b552750e0a4f0292d8af213f597cb481 to your computer and use it in GitHub Desktop.

Select an option

Save leontrolski/b552750e0a4f0292d8af213f597cb481 to your computer and use it in GitHub Desktop.
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