refactor: deduplicate yaml import pattern via require_yaml()

This commit is contained in:
Abdessamad Derraz
2026-03-29 17:07:27 +02:00
parent 3c7fc26354
commit b4c5d77e4b
8 changed files with 28 additions and 44 deletions
+11
View File
@@ -21,6 +21,17 @@ except ImportError:
yaml = None
def require_yaml():
"""Import and return yaml, exiting if PyYAML is not installed."""
try:
import yaml as _yaml
return _yaml
except ImportError:
import sys
print("Error: PyYAML required (pip install pyyaml)", file=sys.stderr)
sys.exit(1)
def compute_hashes(filepath: str | Path) -> dict[str, str]:
"""Compute SHA1, MD5, SHA256, CRC32, Adler32 for a file."""
sha1 = hashlib.sha1()