Skip to content

Commit 7bb154d

Browse files
committed
fix: deduplicate PyYAML warnings and use self.registry in reconciliation
- Emit PyYAML-missing warning once per function call in bash/PS1 instead of per-preset to avoid spamming stderr - Use self.registry.list_by_priority() in reconciliation methods instead of constructing new PresetRegistry instances to avoid redundant I/O and potential consistency issues
1 parent 38382cb commit 7bb154d

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

scripts/bash/common.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ except Exception:
415415
sys.exit(1)
416416
" 2>/dev/null); then
417417
if [ -n "$sorted_presets" ]; then
418+
local yaml_warned=false
418419
while IFS= read -r preset_id; do
419420
# Read strategy and file path from preset manifest
420421
local strategy="replace"
@@ -449,9 +450,9 @@ except Exception:
449450
IFS=$'\t' read -r strategy manifest_file <<< "$result"
450451
strategy=$(printf '%s' "$strategy" | tr '[:upper:]' '[:lower:]')
451452
fi
452-
# Warn only when PyYAML is explicitly missing
453-
if grep -q 'yaml_missing' "$py_stderr" 2>/dev/null; then
454-
echo "Warning: PyYAML not available; composition strategies in $manifest may be ignored" >&2
453+
if [ "$yaml_warned" = false ] && grep -q 'yaml_missing' "$py_stderr" 2>/dev/null; then
454+
echo "Warning: PyYAML not available; composition strategies may be ignored" >&2
455+
yaml_warned=true
455456
fi
456457
rm -f "$py_stderr"
457458
fi

scripts/powershell/common.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ function Resolve-TemplateContent {
424424
}
425425
}
426426
}
427+
$yamlWarned = $false
427428
foreach ($presetId in $sortedPresets) {
428429
# Read strategy and file path from preset manifest
429430
$strategy = 'replace'
@@ -458,9 +459,9 @@ except Exception:
458459
$strategy = $parts[0].ToLowerInvariant()
459460
if ($parts.Count -gt 1 -and $parts[1]) { $manifestFilePath = $parts[1] }
460461
}
461-
# Warn only when PyYAML is explicitly missing
462-
if ((Test-Path $pyStderrFile) -and (Get-Content $pyStderrFile -Raw -ErrorAction SilentlyContinue) -match 'yaml_missing') {
463-
Write-Warning "PyYAML not available; composition strategies in $manifest may be ignored"
462+
if (-not $yamlWarned -and (Test-Path $pyStderrFile) -and (Get-Content $pyStderrFile -Raw -ErrorAction SilentlyContinue) -match 'yaml_missing') {
463+
Write-Warning "PyYAML not available; composition strategies may be ignored"
464+
$yamlWarned = $true
464465
}
465466
Remove-Item $pyStderrFile -Force -ErrorAction SilentlyContinue
466467
} catch {

src/specify_cli/presets.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ def _reconcile_composed_commands(self, command_names: List[str]) -> None:
706706

707707
# Cache registry and manifests outside the loop to avoid
708708
# repeated filesystem reads for each command name.
709-
presets_by_priority = list(PresetRegistry(self.presets_dir).list_by_priority()) if self.presets_dir.exists() else []
709+
presets_by_priority = list(self.registry.list_by_priority())
710710

711711
for cmd_name in command_names:
712712
layers = resolver.collect_all_layers(cmd_name, "command")
@@ -956,9 +956,7 @@ def _reconcile_skills(self, command_names: List[str]) -> None:
956956
skills_dir = self._get_skills_dir()
957957

958958
# Cache registry once to avoid repeated filesystem reads
959-
presets_by_priority = list(
960-
PresetRegistry(self.presets_dir).list_by_priority()
961-
) if self.presets_dir.exists() else []
959+
presets_by_priority = list(self.registry.list_by_priority())
962960

963961
# Group command names by winning preset to batch _register_skills calls
964962
# while only registering skills for the specific commands being reconciled.

0 commit comments

Comments
 (0)