Download package/tools/test_render_portability.py from shutzang/DROID-Sim: direct link, hf CLI and curl.
- Browser
- Download file 2.85 kB
-
https://huggingface.co/datasets/shutzang/DROID-Sim/resolve/main/package/tools/test_render_portability.py
- Command line
-
hf download hf://datasets/shutzang/DROID-Sim/package/tools/test_render_portability.py
-
curl -L -o test_render_portability.py https://huggingface.co/datasets/shutzang/DROID-Sim/resolve/main/package/tools/test_render_portability.py
2.85 kB
| """Render an isolated four-file scene while denying reads of original sources. | |
| Uses temporary hardlinks (or copies across devices) under replay. Never changes | |
| source files. Python audit hooks reject reads from the original dataset and old | |
| transition directory, including backups. This is a runtime dependency test, not | |
| a clean-machine installation or sandbox/security guarantee. | |
| """ | |
| import argparse | |
| import json | |
| import os | |
| from pathlib import Path | |
| import shutil | |
| import sys | |
| import tempfile | |
| def main(): | |
| p = argparse.ArgumentParser(description=__doc__) | |
| p.add_argument('--scene', type=Path, required=True) | |
| p.add_argument('--output-dir', type=Path, required=True) | |
| p.add_argument('--device', default='cuda:2') | |
| p.add_argument('--deny-root', type=Path, action='append', default=[]) | |
| args = p.parse_args() | |
| original = args.scene.resolve() | |
| c = json.loads((original / 'render/scene.json').read_text()) | |
| args.output_dir.mkdir(parents=True, exist_ok=True) | |
| blocked = [original.parent, *[p.resolve() for p in args.deny_root]] | |
| with tempfile.TemporaryDirectory(prefix='isolated_scene_', dir=args.output_dir) as tmp: | |
| isolated = Path(tmp) | |
| inputs = ['render/scene.json', *[c[k] for k in ('foreground', 'background', 'target_image')]] | |
| for name in inputs: | |
| src = (original / name).resolve() | |
| assert src.is_relative_to(original) | |
| dst = isolated / name | |
| dst.parent.mkdir(parents=True, exist_ok=True) | |
| try: | |
| os.link(src, dst) | |
| except OSError: | |
| shutil.copy2(src, dst) | |
| def reject_sources(event, values): | |
| if event != 'open' or not isinstance(values[0], (str, bytes, os.PathLike)): | |
| return | |
| try: | |
| path = Path(os.fsdecode(values[0])).resolve() | |
| except (OSError, ValueError): | |
| return | |
| if any(path.is_relative_to(root) for root in blocked): | |
| raise PermissionError(f'Portability test prohibited source read: {path}') | |
| sys.addaudithook(reject_sources) | |
| # Install guard before importing renderer and its dependency graph. | |
| from render_scene import render | |
| from package_trajectories import write_json | |
| result = render(isolated, args.output_dir / 'render', args.device, width=320, use_cache=False) | |
| result.update(status='passed', isolated_inputs=inputs, denied_source_roots=list(map(str, blocked)), | |
| input_count=len(inputs), original_assets_modified=False, | |
| note='Python-level read audit plus minimal scene runtime test; external binary syscalls are not a security sandbox.') | |
| write_json(args.output_dir / 'portability.json', result) | |
| print(json.dumps(result), flush=True) | |
| if __name__ == '__main__': | |
| main() | |