RoboHome / code /robohome /src /tools /release /scan_hardcoded_paths.py
RoboParty Release
Unify robohome source, assets and scenes delivery
3f15e9f
Raw History Blame Contribute Delete
3.98 kB
#!/usr/bin/env python3
"""Regenerate task 029 source path inventory and explicit exclusions.
Scans every .py/.sh/.json/.md, including hidden and ignored files. Reports remain
.txt so the inventory does not recursively scan its own quoted source lines.
Exit 1 means at least one actionable machine path remains.
"""
from __future__ import annotations
import ast
from collections import Counter
from pathlib import Path
import re
ROOT = Path(__file__).resolve().parents[2]
# Include paths embedded in compiler flags, and bare prefix guards.
MACHINE_PATH = re.compile(r'''(?:(?<![\w./:-])|(?<=-I)|(?<=-L))/(?:mnt|data|Users)/(?:[^\s"'`<>),;\]}]*)''')
SUFFIXES = {'.py', '.sh', '.json', '.md'}
SEALED_REVISIONS = {
'engine/REPAIR_V2_REVISION.json',
'engine/native_patches/bathroom_pair_parent/REPAIR_V2_REVISION.json',
'engine/native_patches/bathroom_parent/REPAIR_V2_REVISION.json',
'engine/native_patches/bedroom_contract_r17_parent/REPAIR_V2_REVISION.json',
'engine/native_patches/home_revision_parent/REPAIR_V2_REVISION.json',
'engine/native_patches/kitchen_parent/REPAIR_V2_REVISION.json',
'engine/native_patches/window_infill_parent/REPAIR_V2_REVISION.json',
'engine/parent_revisions/artifact_reuse_20261102/REPAIR_V2_REVISION.json',
}
def scan():
default_table = next(node for node in ast.parse((ROOT / 'rhg_paths.py').read_text()).body
if isinstance(node, ast.Assign) and any(
isinstance(target, ast.Name) and target.id == 'LEGACY_DEFAULTS'
for target in node.targets))
active, excluded = [], []
for path in sorted(ROOT.rglob('*')):
if path.suffix not in SUFFIXES or not path.is_file():
continue
text = path.read_text(encoding='utf-8', errors='replace')
relative = path.relative_to(ROOT).as_posix()
for number, line in enumerate(text.splitlines(), 1):
urls = [match.span() for match in re.finditer(r"""https?://[^\s"'`<>]+""", line)]
matches = [match.group() for match in MACHINE_PATH.finditer(line)
if not any(start <= match.start() < end for start, end in urls)]
if not matches:
continue
reason = None
if relative.startswith(('engine/supervisor_site/', 'engine/runtime_site/')):
reason = 'third-party vendor; untouched'
elif relative in SEALED_REVISIONS:
reason = 'immutable seal / historical sealed revision; user reseals separately'
elif relative == 'rhg_paths.py' and default_table.lineno <= number <= default_table.end_lineno:
reason = 'central internal defaults; enabled only by RHG_PATHS_LEGACY_DEFAULTS=1'
elif all(match in ('/mnt/', '/Users/') for match in matches):
reason = 'path-prefix detection guard, not a machine file location'
elif relative == 'test_relocate_paths.py' and all(
re.match(r'^/(?:mnt/zz/|data/a)', match) for match in matches):
reason = 'synthetic relocation-test input, not a real machine dependency'
record = f'{relative}:{number}:{line}'
if reason:
excluded.append((reason, record))
else:
active.append(record)
return active, excluded
def main():
active, excluded = scan()
output = Path(__file__).resolve().parent
(output / 'hardcoded_paths.txt').write_text(''.join(line + '\n' for line in active))
(output / 'hardcoded_paths_exclusions.txt').write_text(''.join(
f'[{reason}] {line}\n' for reason, line in excluded))
print(f'Actionable machine path lines: {len(active)}; excluded lines: {len(excluded)}')
for reason, count in sorted(Counter(reason for reason, _ in excluded).items()):
print(f' {count}: {reason}')
return int(bool(active))
if __name__ == '__main__':
raise SystemExit(main())