File size: 679 Bytes
00c7586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import hashlib
import json
import sys
from .config import VENDOR

def initialize():
    manifest = json.loads((VENDOR / 'MANIFEST.json').read_text())
    for relative, expected in manifest.items():
        path = VENDOR / relative
        if not path.resolve().is_relative_to(VENDOR.resolve()):
            raise RuntimeError('Invalid runtime manifest path')
        if hashlib.sha256(path.read_bytes()).hexdigest() != expected:
            raise RuntimeError(f'Production code changed: {relative}')
    for path in [VENDOR, VENDOR / 'support', VENDOR / 'production_adapter']:
        sys.path.insert(0, str(path))
    import adapter
    return adapter
production = initialize()