MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / pythonModuleUnder

Function pythonModuleUnder

src/resolution/import-resolver.ts:1098–1107  ·  view source on GitHub ↗

* The module file for the dotted path `relPath` (slash-joined) under `root`, * walking it the way the import system does: every prefix must be a package * — regular, or a namespace directory — so a prefix that is a plain module * (`pkg/sub.py` with no `pkg/sub/__init__.py`) ends the walk, and *

(root: string, relPath: string, index: PythonModuleIndex)

Source from the content-addressed store, hash-verified

1096 * `pkg.sub.x` does not exist even if `pkg/sub/x.py` does.
1097 */
1098function pythonModuleUnder(root: string, relPath: string, index: PythonModuleIndex): string | null {
1099 const parts = relPath.split('/');
1100 let base = root;
1101 for (let i = 0; i < parts.length - 1; i++) {
1102 base = joinRel(base, parts[i]!);
1103 if (index.files.has(joinRel(base, '__init__.py'))) continue;
1104 if (index.files.has(`${base}.py`) || !index.dirs.has(base)) return null;
1105 }
1106 return pythonModuleAt(joinRel(root, relPath), index);
1107}
1108
1109/** How `root` provides the top-level name `head`: concretely, as a namespace portion, or not at all. */
1110function pythonHeadKind(root: string, head: string, index: PythonModuleIndex): 'concrete' | 'namespace' | null {

Callers 2

resolvePythonModuleFunction · 0.85
pythonModuleOfScriptFunction · 0.85

Calls 3

joinRelFunction · 0.85
pythonModuleAtFunction · 0.85
hasMethod · 0.80

Tested by

no test coverage detected