from pathlib import Path import hashlib import json import subprocess root = Path(__file__).resolve().parent target = Path('E:/pipe-ner-server').resolve() assert str(target).lower().replace('\\', '/') == 'e:/pipe-ner-server' manifest = json.loads((root / 'manifest.json').read_text(encoding='utf-8')) for entry in manifest: path = target / entry['path'] digest = hashlib.sha256(path.read_bytes()).hexdigest() if path.exists() else None if digest != entry['beforeSha256']: raise SystemExit('Concurrent modification; patch not applied: ' + entry['path']) staged = root / entry['path'] if hashlib.sha256(staged.read_bytes()).hexdigest() != entry['afterSha256']: raise SystemExit('Staged file changed; rebuild manifest: ' + entry['path']) patch = str(root / 'point-status-eight-buckets.patch') # Inherit stdio; no named-pipe output capture under Windows sandbox. subprocess.run(['git', 'apply', '--check', '--whitespace=error', patch], cwd=target, check=True) subprocess.run(['git', 'apply', '--whitespace=error', patch], cwd=target, check=True) for entry in manifest: final = (target / entry['path']).read_bytes().replace(b'\r\n', b'\n') expected = (root / entry['path']).read_bytes().replace(b'\r\n', b'\n') assert final == expected, entry['path'] print('Applied and verified ' + str(len(manifest)) + ' backend files; no build/debug/test commands executed.')