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

Function pythonScriptModuleScope

src/resolution/import-resolver.ts:1082–1110  ·  view source on GitHub ↗
(
  context: ResolutionContext,
  editedFiles: string[]
)

Source from the content-addressed store, hash-verified

1080 * the module has: `from types import ModuleType` beside `mypy/types.py` never does.
1081 */
1082export function pythonScriptModuleScope(
1083 context: ResolutionContext,
1084 editedFiles: string[]
1085): { targetFiles: string[]; sourceDirs: string[]; moduleLeaves: string[] } {
1086 const index = pythonModuleIndex(context);
1087 const targetFiles: string[] = [];
1088 const moduleLeaves: string[] = [];
1089 for (const raw of editedFiles) {
1090 const file = raw.replace(/\\/g, '/');
1091 if (!PYTHON_MODULE_FILE.test(file)) continue;
1092 const mod = file.replace(/(?:^|\/)__init__\.py$/, '').replace(/\.py$/, '');
1093 for (let dir = parentDir(mod); dir; dir = parentDir(dir)) {
1094 const specifier = mod.slice(dir.length + 1).replace(/\//g, '.');
1095 if (PYTHON_STDLIB_MODULES.has(specifier.split('.')[0]!)) continue;
1096 const importers = context.getNodesByName(specifier)
1097 .filter((n) => n.kind === 'import' && PYTHON_MODULE_FILE.test(n.filePath))
1098 .map((n) => parentDir(n.filePath));
1099 const reached = index.packageDirs.has(dir)
1100 ? importers.includes(dir)
1101 : !index.projectRoots.has(dir) && !index.localRoots.has(dir) &&
1102 importers.some((d) => d.startsWith(`${dir}/`));
1103 if (!reached) continue;
1104 targetFiles.push(file);
1105 moduleLeaves.push(mod.slice(mod.lastIndexOf('/') + 1));
1106 break;
1107 }
1108 }
1109 return { targetFiles, sourceDirs: [], moduleLeaves };
1110}
1111
1112/**
1113 * The Python files that import one of the packages whose `__init__.py` is in

Callers 1

Calls 6

pythonModuleIndexFunction · 0.85
hasMethod · 0.80
mapMethod · 0.80
pushMethod · 0.80
parentDirFunction · 0.70
getNodesByNameMethod · 0.65

Tested by

no test coverage detected