* The root a declared import path names, and the folder whose code it * answers. `written` is relative to `service`, the folder of the config, and * may climb out of it (`../code` in `tests/pytest.ini`) but not out of the * repo; an absolute path, a home folder or a variable names nothing the ind
(service: string, written: string)
| 1031 | * application's `requests`. Null for a path that names no folder of the repo. |
| 1032 | */ |
| 1033 | function pythonImportRootAt(service: string, written: string): { root: string; reach: string } | null { |
| 1034 | const rel = written.trim().replace(/\\/g, '/'); |
| 1035 | if (!rel || rel.startsWith('/') || rel.startsWith('~') || /^[A-Za-z]:/.test(rel) || rel.includes('$')) return null; |
| 1036 | const joined = path.posix.normalize(joinRel(service, rel)).replace(/\/+$/, ''); |
| 1037 | if (joined === '..' || joined.startsWith('../')) return null; |
| 1038 | const root = joined === '.' ? '' : joined; |
| 1039 | let reach = service; |
| 1040 | if (isWithin(root, service)) { |
| 1041 | const below = service ? root.slice(service.length + 1) : root; |
| 1042 | let at = service; |
| 1043 | for (const segment of below.split('/')) { |
| 1044 | if (!segment) break; |
| 1045 | at = joinRel(at, segment); |
| 1046 | if (PYTHON_NON_PROJECT_DIRS.has(segment)) { |
| 1047 | reach = at; |
| 1048 | break; |
| 1049 | } |
| 1050 | } |
| 1051 | } |
| 1052 | return { root, reach }; |
| 1053 | } |
| 1054 | |
| 1055 | /** |
| 1056 | * `[table]` sections of a TOML / INI file, with the body under each. A TOML |
no test coverage detected