( context: ResolutionContext, editedFiles: string[] )
| 1326 | * the module has: `from types import ModuleType` beside `mypy/types.py` never does. |
| 1327 | */ |
| 1328 | export function pythonScriptModuleScope( |
| 1329 | context: ResolutionContext, |
| 1330 | editedFiles: string[] |
| 1331 | ): { targetFiles: string[]; sourceDirs: string[]; moduleLeaves: string[] } { |
| 1332 | const index = pythonModuleIndex(context); |
| 1333 | const targetFiles: string[] = []; |
| 1334 | const moduleLeaves: string[] = []; |
| 1335 | for (const raw of editedFiles) { |
| 1336 | const file = raw.replace(/\\/g, '/'); |
| 1337 | if (!PYTHON_MODULE_FILE.test(file)) continue; |
| 1338 | const mod = file.replace(/(?:^|\/)__init__\.py$/, '').replace(/\.py$/, ''); |
| 1339 | for (let dir = parentDir(mod); dir; dir = parentDir(dir)) { |
| 1340 | const specifier = mod.slice(dir.length + 1).replace(/\//g, '.'); |
| 1341 | if (PYTHON_STDLIB_MODULES.has(specifier.split('.')[0]!)) continue; |
| 1342 | const importers = context.getNodesByName(specifier) |
| 1343 | .filter((n) => n.kind === 'import' && PYTHON_MODULE_FILE.test(n.filePath)) |
| 1344 | .map((n) => parentDir(n.filePath)); |
| 1345 | const reached = index.packageDirs.has(dir) |
| 1346 | ? importers.includes(dir) |
| 1347 | : !index.projectRoots.has(dir) && !index.localRoots.has(dir) && |
| 1348 | importers.some((d) => d.startsWith(`${dir}/`)); |
| 1349 | if (!reached) continue; |
| 1350 | targetFiles.push(file); |
| 1351 | moduleLeaves.push(mod.slice(mod.lastIndexOf('/') + 1)); |
| 1352 | break; |
| 1353 | } |
| 1354 | } |
| 1355 | return { targetFiles, sourceDirs: [], moduleLeaves }; |
| 1356 | } |
| 1357 | |
| 1358 | /** |
| 1359 | * The Python files that import one of the packages whose `__init__.py` is in |
no test coverage detected