RoboHome / code /robohome /tools /verify_source.py
wentywenty's picture
Verify RoboHome source completeness and document portable workflows
75e20e2 verified
Raw History Blame
3.5 kB
#!/usr/bin/env python3
"""Check source completeness, signatures and optional host dependencies."""
import argparse
import hashlib
import importlib
import json
from pathlib import Path
import re
import sys
sys.dont_write_bytecode = True
ROOT = Path(__file__).resolve().parents[1]
SOURCE = ROOT / 'src'
sys.path.insert(0, str(SOURCE))
def check(dependencies=False):
failures = []
manifest = json.loads((ROOT / 'source-manifest.json').read_text())
for row in manifest['files']:
path = ROOT / row['path']
if not path.is_file() or hashlib.sha256(path.read_bytes()).hexdigest() != row['sha256']:
failures.append('Missing or changed source: ' + row['path'])
evidence = json.loads((ROOT / 'docs/source-completeness.json').read_text())
for relative in evidence['source_modules'] + evidence['required_small_archives']:
if not (SOURCE / relative).is_file():
failures.append('Required source or fixture missing: ' + relative)
modules = list(SOURCE.rglob('*.py'))
for path in modules:
try:
compile(path.read_bytes(), str(path.relative_to(ROOT)), 'exec')
except (SyntaxError, UnicodeError) as exc:
failures.append(str(exc))
for path in [ROOT / 'README.md', *sorted((ROOT / 'docs').glob('*.md'))]:
text = path.read_text()
if re.search(r'/(?:mnt|data|home|Users)/', text):
failures.append('Machine path in public documentation: ' + str(path.relative_to(ROOT)))
for link in re.findall(r'\]\(([^)]+)\)', text):
target = link.split('#', 1)[0]
if target and '://' not in target and not (path.parent / target).exists():
failures.append('Broken documentation link: ' + link)
from generation_dependencies import validate_generation_dependencies
try:
package = validate_generation_dependencies(SOURCE / 'engine')
except (ValueError, FileNotFoundError) as exc:
failures.append(str(exc))
package = {}
sys.path.insert(0, str(SOURCE / 'tools/release'))
from check_source_integrity import check as check_engine
engine = check_engine(SOURCE)
failures.extend('Engine signature mismatch: ' + row.get('path', row.get('reason', 'unknown'))
for row in engine['mismatches'])
missing_packages = []
if dependencies:
for name in ('numpy', 'scipy', 'shapely', 'manifold3d', 'PIL', 'trimesh', 'rtree', 'yaml'):
try:
importlib.import_module(name)
except ImportError:
missing_packages.append(name)
if missing_packages:
failures.append('Install requirements.txt; missing packages: ' + ', '.join(missing_packages))
return {'passed': not failures, 'manifest_files': len(manifest['files']),
'python_modules': len(modules),
'upstream_modules_present': len(evidence['source_modules']),
'dynamic_dependencies': package.get('checked_count', 0),
'engine_inventory': engine['inventory_files'],
'engine_implementations': engine['revision_files'],
'failures': failures}
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--dependencies', action='store_true', help='also import host dependencies')
args = parser.parse_args()
result = check(args.dependencies)
print(json.dumps(result, indent=2))
raise SystemExit(0 if result['passed'] else 1)