← Files Uni Lecture TutorARCHIVED FILE
skills/automatic-lecture-learning/scripts/ult_dependency_guard.py
1.91 KB · Nov 30, 2026 · 18:13 UTC
"""Offline, fail-closed version policy. No package install, network, or content access."""
from importlib.metadata import PackageNotFoundError, version
from pathlib import Path
import re
LOCK = Path(__file__).resolve().parents[1] / 'requirements-lock.txt'
class DependencyUnavailable(ImportError):
"""Optional validation helpers must not import an unapproved dependency set."""
def pins():
result = {}
for line in LOCK.read_text(encoding='utf-8').splitlines():
line = line.strip()
if not line or line.startswith('#'):
continue
match = re.fullmatch(r'([a-z0-9-]+)==([0-9]+(?:\.[0-9]+)+)', line)
if not match or match[1] in result:
raise DependencyUnavailable('Invalid dependency lock; local verification unavailable')
result[match[1]] = match[2]
if set(result) != {'jsonschema','attrs','referencing','rpds-py','jsonschema-specifications'}:
raise DependencyUnavailable('Incomplete dependency lock; local verification unavailable')
return result
def require_approved_dependencies():
"""Check metadata before importing jsonschema/referencing; not artifact attestation."""
try:
expected = pins()
except (OSError, UnicodeError) as exc:
raise DependencyUnavailable('Dependency lock unreadable; local verification unavailable') from exc
mismatches = []
for name, approved in expected.items():
try:
actual = version(name)
except PackageNotFoundError:
actual = 'missing'
if actual != approved:
mismatches.append(f'{name}: expected {approved}, found {actual}')
if mismatches:
raise DependencyUnavailable('Local verification unavailable; unapproved dependency set. '
+ '; '.join(mismatches)
+ '. Do not install during study. Use the documented unverified fallback.')
return expected
SHA-256: dad02d1b5747c21526260eabde58e24372887a9d55b27145107e7b8b9ab79dcc