refactor: move fixed_paths to shell_launchers

This commit is contained in:
Abdessamad Derraz committed 2026-11-23 23:07:32 +01:00
1 parent 7b0a5d5d4a
commit 13f92eaf4a
3 files changed
+30 -27

No files matched your search

+27
View File
@@ -10,6 +10,7 @@ gone, so a rewrite upstream stops the scrape instead of publishing nothing.
from __future__ import annotations
import posixpath
import re
from collections.abc import Callable, Iterable
from dataclasses import dataclass, field
@@ -667,6 +668,32 @@ def settings(text: str, separator: str = "=") -> list[Setting]:
return found
@dataclass(frozen=True)
class FixedPaths:
"""Keys of a config that name a file under one directory."""
keys: tuple[tuple[str, str], ...]
names: tuple[str, ...]
search_dir: str
def fixed_paths(
found: list[Setting], keys: list[tuple[str, str]], path: str
) -> tuple[FixedPaths, set[int]]:
"""The values of keys, as names relative to the directory they share."""
by_key = {(s.section, s.key): s for s in found}
missing = [k for k in keys if k not in by_key]
if missing:
raise LauncherPatternMissing(path, f"key {missing[0][1]}")
values = [by_key[k].value for k in keys if by_key[k].value]
lines = {by_key[k].line for k in keys}
if not values:
return FixedPaths(tuple(keys), (), ""), lines
folder = posixpath.commonpath([posixpath.dirname(v) for v in values])
names = tuple(posixpath.relpath(v, folder) for v in values)
return FixedPaths(tuple(keys), names, folder), lines
def describe_keys(file: str, keys: tuple[tuple[str, str], ...]) -> str:
"""file [section] key, key [other] key, sections named where they change."""
described, section = file, None