* The module only a script's own `sys.path[0]` provides, which no root does: * `from test import TestCase` in `modules/vs/tests/with_a.py`, with the runner * `modules/vs/test.py` above it, or `from pysim import HashTable` in * `tools/an/pysim_test.py`, beside `tools/an/pysim.py` in a folder that
( specifier: string, relPath: string, fromFile: string, importerDir: string, index: PythonModuleIndex, context: ResolutionContext )
| 1227 | * it is no root, so it is passed over. |
| 1228 | */ |
| 1229 | function pythonModuleOfScript( |
| 1230 | specifier: string, |
| 1231 | relPath: string, |
| 1232 | fromFile: string, |
| 1233 | importerDir: string, |
| 1234 | index: PythonModuleIndex, |
| 1235 | context: ResolutionContext |
| 1236 | ): string | null { |
| 1237 | if (PYTHON_STDLIB_MODULES.has(specifier.split('.')[0]!)) return null; |
| 1238 | const taken = importsFrom(context.getImportMappings(fromFile, 'python'), specifier) |
| 1239 | .filter((imp) => !imp.isNamespace) |
| 1240 | .map((imp) => imp.exportedName); |
| 1241 | if (taken.length === 0) return null; |
| 1242 | for (let dir = importerDir; dir; dir = parentDir(dir)) { |
| 1243 | if (dir !== importerDir && index.packageDirs.has(dir)) continue; |
| 1244 | const file = pythonModuleUnder(dir, relPath, index); |
| 1245 | if (!file || importsFrom(context.getImportMappings(file, 'python'), specifier).length > 0) continue; |
| 1246 | const defined = new Set(context.getNodesInFile(file).filter(isPythonModuleLevelDef).map((n) => n.name)); |
| 1247 | if (taken.every((name) => defined.has(name))) return file; |
| 1248 | } |
| 1249 | return null; |
| 1250 | } |
| 1251 | |
| 1252 | /** |
| 1253 | * A digest of the Python root set — each root with its tier and reach. A |
no test coverage detected