* The import names that can denote the module at `modulePath`: its trailing * dotted paths (`models`, `shop.models`), each also behind one dot or more * (`.models`, `..shop.models`), and the dots alone (`.`, `..`), which name a * package by where the importer sits.
(modulePath: string)
| 824 | * package by where the importer sits. |
| 825 | */ |
| 826 | function pythonImportNamesFor(modulePath: string): string[] { |
| 827 | const segments = modulePath.split('/'); |
| 828 | const absolute = segments.map((_, i) => segments.slice(i).join('.')); |
| 829 | const names = new Set<string>(absolute); |
| 830 | for (let dots = 1; dots <= MAX_RELATIVE_DOTS; dots++) { |
| 831 | const prefix = '.'.repeat(dots); |
| 832 | names.add(prefix); |
| 833 | for (const name of absolute) names.add(prefix + name); |
| 834 | } |
| 835 | return [...names]; |
| 836 | } |