diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-20 16:24:16 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-20 16:24:16 -0400 |
| commit | 9a52370b47c0fe73b4fb7d6f77aabe70a96f192d (patch) | |
| tree | d5c4c6b75ed9141ecd1a4aaf2815131601519ab3 | |
| parent | 42f0c88ac06775013ead9ac1e82f5684e386cb49 (diff) | |
| download | dotemacs-9a52370b47c0fe73b4fb7d6f77aabe70a96f192d.tar.gz dotemacs-9a52370b47c0fe73b4fb7d6f77aabe70a96f192d.zip | |
refactor(theme-studio): extract path_kind from the two face-coverage bucketers
bucket_from_source and bucket_of_source each re-derived the elpa/user/builtin/
other origin of a defface path. Lift that into one path_kind(path) classifier;
both functions now map its result to their own vocabulary. Verified byte-identical
bucket output over a representative path set before and after.
| -rw-r--r-- | scripts/theme-studio/face_coverage.py | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/scripts/theme-studio/face_coverage.py b/scripts/theme-studio/face_coverage.py index ba761230b..c6200e05c 100644 --- a/scripts/theme-studio/face_coverage.py +++ b/scripts/theme-studio/face_coverage.py @@ -115,22 +115,37 @@ def load_managed(): CORE_FILES = {'faces', 'frame'} +def path_kind(path): + """Classify a defface source PATH into a coarse origin kind. + Returns one of: 'none' (no path), 'elpa', 'user', 'builtin', 'other'. + Shared by bucket_from_source and bucket_of_source, which each map the kind + to their own vocabulary.""" + if not path: + return 'none' + if '/elpa/' in path: + return 'elpa' + if '/.emacs.d/modules' in path: + return 'user' + if path.startswith('/usr/share/emacs') or path.startswith('/usr/lib/emacs'): + return 'builtin' + return 'other' + + def bucket_from_source(path): """Derive a bucket name from a face's defface file, for faces that match no known family. elpa -> the package dir name (version stripped); built-in -> the source file basename; otherwise emacs-core (can't tell).""" - if not path: - return 'emacs-core' - if '/elpa/' in path: + kind = path_kind(path) + if kind == 'elpa': pkgdir = path.split('/elpa/', 1)[1].split('/', 1)[0] return re.sub(r'-[0-9].*$', '', pkgdir) or 'emacs-core' - if '/.emacs.d/modules' in path: + if kind == 'user': return 'user-config' - if path.startswith('/usr/share/emacs') or path.startswith('/usr/lib/emacs'): + if kind == 'builtin': base = os.path.basename(path) base = base[:-3] if base.endswith('.el') else base return 'emacs-core' if base in CORE_FILES else base - return 'emacs-core' + return 'emacs-core' # 'none' or 'other' def make_group_of(families, src): @@ -155,15 +170,8 @@ def make_group_of(families, src): def bucket_of_source(path): - if not path: - return 'unloaded' - if '/elpa/' in path: - return 'elpa' - if '/.emacs.d/modules' in path: - return 'user' - if path.startswith('/usr/share/emacs') or path.startswith('/usr/lib/emacs'): - return 'builtin' - return 'other' + return {'none': 'unloaded', 'elpa': 'elpa', 'user': 'user', + 'builtin': 'builtin', 'other': 'other'}[path_kind(path)] def classify(name, items, src, pkgfaces): |
