* 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)
| 939 | * package by where the importer sits. |
| 940 | */ |
| 941 | function pythonImportNamesFor(modulePath: string): string[] { |
| 942 | const segments = modulePath.split('/'); |
| 943 | const absolute = segments.map((_, i) => segments.slice(i).join('.')); |
| 944 | const names = new Set<string>(absolute); |
| 945 | for (let dots = 1; dots <= MAX_RELATIVE_DOTS; dots++) { |
| 946 | const prefix = '.'.repeat(dots); |
| 947 | names.add(prefix); |
| 948 | for (const name of absolute) names.add(prefix + name); |
| 949 | } |
| 950 | return [...names]; |
| 951 | } |