Noir::ImportGraph::Python
Python flavour.
Python imports are dotted-module paths anchored at one of:
app_base_path— the project's source root (theappdirectory passed by the analyzer).- The current file's directory, for relative imports
(
from . import x,from .. import x).
The resolver walks the dotted path one segment at a time,
preferring directories (Python packages) over file siblings
(modules) until either a leaf .py is found or the path runs
out — matching the behaviour expected by the existing
Django / FastAPI / Tornado analyzers.
Lives under the shared Noir::ImportGraph umbrella so a future
Python analyzer migration off the legacy PythonParser (still
used by Flask) can reuse the same resolver. Until that
migration lands the JVM / JS / Python flavours all share the
top-level module but each operates on its own data shapes —
Python's hashes look different from the JVM ImportRef form
because Python returns import-name → file-path mappings rather
than a yield of files.
Class methods
Find every import and from … import … line in content
and resolve each name to a {filepath, package_type} tuple.
Returns an empty hash for files that import nothing
resolvable. The map is keyed on the IMPORTED-IN-LOCAL name —
from a.b import c as d keys d, not c.
app_base_path anchors the dotted path for absolute imports;
file_path's directory anchors relative imports. Pass
content when the caller already has the file in hand to
skip the second disk read.
Resolve a dotted Python identifier (a.b.c or
a.b.c, d.e as f) under package_path. Walks segment by
segment, preferring packages (directories) over modules
(.py files). Returns each resolvable name as {name, filepath, package_type} so the caller can keep the alias
mapping intact.