* Find the file node for a Python dotted module path `a.b.c` — a module file * ending in `a/b/c.py`, or a package `a/b/c/__init__.py` (suffix-matched, so a * package rooted under `src/` etc. still resolves). Returns null for * stdlib/external modules (no matching repo file node), so `import os` c
( mod: string, context: ResolutionContext, excludeFilePath: string )
| 1764 | * (where `c` is a submodule) resolution. |
| 1765 | */ |
| 1766 | function findPythonModuleFile( |
| 1767 | mod: string, |
| 1768 | context: ResolutionContext, |
| 1769 | excludeFilePath: string |
| 1770 | ): Node | null { |
| 1771 | if (!mod || mod.startsWith('.')) return null; // relative imports handled elsewhere |
| 1772 | const rel = mod.replace(/\./g, '/'); |
| 1773 | const lastSeg = mod.split('.').pop()!; |
| 1774 | const endsWith = (p: string, want: string): boolean => p === want || p.endsWith('/' + want); |
| 1775 | const moduleFile = context |
| 1776 | .getNodesByName(`${lastSeg}.py`) |
| 1777 | .find((n) => n.kind === 'file' && n.filePath !== excludeFilePath && endsWith(n.filePath, `${rel}.py`)); |
| 1778 | if (moduleFile) return moduleFile; |
| 1779 | const pkgFile = context |
| 1780 | .getNodesByName('__init__.py') |
| 1781 | .find((n) => n.kind === 'file' && n.filePath !== excludeFilePath && endsWith(n.filePath, `${rel}/__init__.py`)); |
| 1782 | return pkgFile ?? null; |
| 1783 | } |
| 1784 | |
| 1785 | /** |
| 1786 | * Resolve a Python ABSOLUTE dotted module import (`import a.b.c`) to its file — |
no test coverage detected