mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 11:46:35 +00:00
refactor(lint): read the AI model vars through the cache in the quant check
test_local_model_quant_pinned opened group_vars/all/16_ai.yml twice per run,
once with yaml.safe_load for the entries and once with read_text to find an
alias line, so the file was parsed again for a check that several other lints
already read it for. test_no_uncached_file_reads rejects that, and it rejected
this module: restoring the previous version fails
test_modules_in_scope_use_cached_read_text, and the current one passes it.
load_yaml and read_text from utils.cache memoise by absolute path. The
'or {}' guard goes with the raw loader rather than being dropped silently:
load_yaml returns a mapping or raises TypeError on any other root, so .get
cannot meet None, and a malformed file now fails at this lint instead of
reading as an empty model list that the check would pass over.
d7bd200da1 on feature/store-i18n applies the same idiom to five other modules.
The two do not overlap: that branch cannot carry this file, which 499f8a4445
created here, so the sweep there and this commit together leave one pattern
rather than two.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
c4ea94c778
commit
e5430ad4ca
1 file changed
+4
-7
@@ -29,9 +29,9 @@ from __future__ import annotations
|
||||
import unittest
|
||||
from typing import ClassVar
|
||||
|
||||
import yaml
|
||||
|
||||
from utils.annotations.suppress import is_suppressed_at
|
||||
from utils.cache.files import read_text
|
||||
from utils.cache.yaml import load_yaml
|
||||
|
||||
from . import PROJECT_ROOT
|
||||
|
||||
@@ -41,15 +41,12 @@ _KEY = "AI_LOCAL_MODELS"
|
||||
|
||||
|
||||
def _entries() -> list[dict]:
|
||||
data = yaml.safe_load(_VARS_FILE.read_text(encoding="utf-8")) or {}
|
||||
declared = data.get(_KEY)
|
||||
declared = load_yaml(_VARS_FILE).get(_KEY)
|
||||
return [entry for entry in (declared or []) if isinstance(entry, dict)]
|
||||
|
||||
|
||||
def _line_of(alias: str) -> int:
|
||||
for number, line in enumerate(
|
||||
_VARS_FILE.read_text(encoding="utf-8").splitlines(), 1
|
||||
):
|
||||
for number, line in enumerate(read_text(str(_VARS_FILE)).splitlines(), 1):
|
||||
if f"alias: {alias}" in line:
|
||||
return number
|
||||
return 0
|
||||
|
||||
Reference in new issue
Block a user