( context: ResolutionContext, editedFiles: string[] )
| 1062 | * the module has: `from types import ModuleType` beside `mypy/types.py` never does. |
| 1063 | */ |
| 1064 | export function pythonScriptModuleScope( |
| 1065 | context: ResolutionContext, |
| 1066 | editedFiles: string[] |
| 1067 | ): { targetFiles: string[]; sourceDirs: string[]; moduleLeaves: string[] } { |
| 1068 | const index = pythonModuleIndex(context); |
| 1069 | const targetFiles: string[] = []; |
| 1070 | const moduleLeaves: string[] = []; |
| 1071 | for (const raw of editedFiles) { |
| 1072 | const file = raw.replace(/\\/g, '/'); |
| 1073 | if (!PYTHON_MODULE_FILE.test(file)) continue; |
| 1074 | const mod = file.replace(/(?:^|\/)__init__\.py$/, '').replace(/\.py$/, ''); |
| 1075 | for (let dir = parentDir(mod); dir; dir = parentDir(dir)) { |
| 1076 | const specifier = mod.slice(dir.length + 1).replace(/\//g, '.'); |
| 1077 | if (PYTHON_STDLIB_MODULES.has(specifier.split('.')[0]!)) continue; |
| 1078 | const importers = context.getNodesByName(specifier) |
| 1079 | .filter((n) => n.kind === 'import' && PYTHON_MODULE_FILE.test(n.filePath)) |
| 1080 | .map((n) => parentDir(n.filePath)); |
| 1081 | const reached = index.packageDirs.has(dir) |
| 1082 | ? importers.includes(dir) |
| 1083 | : !index.projectRoots.has(dir) && !index.localRoots.has(dir) && |
| 1084 | importers.some((d) => d.startsWith(`${dir}/`)); |
| 1085 | if (!reached) continue; |
| 1086 | targetFiles.push(file); |
| 1087 | moduleLeaves.push(mod.slice(mod.lastIndexOf('/') + 1)); |
| 1088 | break; |
| 1089 | } |
| 1090 | } |
| 1091 | return { targetFiles, sourceDirs: [], moduleLeaves }; |
| 1092 | } |
| 1093 | |
| 1094 | /** |
| 1095 | * The Python files that import one of the packages whose `__init__.py` is in |
no test coverage detected