Stem used as the node-ID prefix for a file and its symbols. The full path (extension dropped) is preserved as path segments; ``make_id`` later collapses the separators to underscores. Using every segment — not just the immediate parent dir (#1504) — means same-named files in different
(path: Path)
| 37 | |
| 38 | |
| 39 | def _file_stem(path: Path) -> str: |
| 40 | """Stem used as the node-ID prefix for a file and its symbols. |
| 41 | |
| 42 | The full path (extension dropped) is preserved as path segments; ``make_id`` |
| 43 | later collapses the separators to underscores. Using every segment — not just |
| 44 | the immediate parent dir (#1504) — means same-named files in different |
| 45 | directories get distinct IDs instead of colliding into one |
| 46 | last-writer-wins node: |
| 47 | |
| 48 | docs/v1/api/README.md -> docs/v1/api/README -> docs_v1_api_readme |
| 49 | docs/v2/api/README.md -> docs/v2/api/README -> docs_v2_api_readme |
| 50 | |
| 51 | Top-level files keep a bare stem (``setup.py`` -> ``setup``). When passed an |
| 52 | absolute path the whole path is encoded; the extract() id-remap post-pass |
| 53 | re-derives the canonical repo-relative form from ``source_file`` so the on-disk |
| 54 | location can't leak into the persisted IDs (#502). |
| 55 | |
| 56 | Returns "" for a path with no name (``Path('.')`` — a source_file that equals |
| 57 | the scan root, so it has no per-file stem). Guarding here keeps |
| 58 | ``path.with_suffix("")`` from raising ``ValueError: '.' has an empty name`` and |
| 59 | protects every caller, not just ``_semantic_id_remap`` (#1618).""" |
| 60 | if not path.name: |
| 61 | return "" |
| 62 | return path.with_suffix("").as_posix() |
| 63 | |
| 64 | |
| 65 | def _read_text(node, source: bytes) -> str: |
no outgoing calls