Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /randovania_randovania /randovania /cli /commands /validate.py
| from __future__ import annotations | |
| import asyncio | |
| import time | |
| from pathlib import Path | |
| from typing import TYPE_CHECKING | |
| from randovania.cli import cli_lib | |
| from randovania.cli.cli_lib import add_debug_argument | |
| from randovania.layout.layout_description import LayoutDescription | |
| from randovania.resolver import debug, resolver | |
| if TYPE_CHECKING: | |
| from argparse import ArgumentParser, Namespace, _SubParsersAction | |
| def validate_command_logic(args: Namespace) -> int: | |
| debug.set_level(args.debug) | |
| description = LayoutDescription.from_file(args.layout_file) | |
| output_file = None | |
| write_to: Path | None = args.write_to | |
| if write_to is not None: | |
| output_file = write_to.open("w", encoding="utf-8") | |
| def write_to_log(s: str) -> None: | |
| output_file.write(s + "\n") | |
| debug.print_function = write_to_log | |
| total_times = [] | |
| final_state_by_resolve = None | |
| for _ in range(args.repeat): | |
| before = time.perf_counter() | |
| final_state_by_resolve = asyncio.run( | |
| resolver.resolve( | |
| [ | |
| (preset.configuration, patches) | |
| for preset, patches in zip(description.all_presets, description.all_patches, strict=True) | |
| ], | |
| record_paths=debug.debug_level() > 0, | |
| ) | |
| ) | |
| after = time.perf_counter() | |
| total_times.append(after - before) | |
| print( | |
| "Took {:.3f} seconds. Game is {}.".format( | |
| total_times[-1], "possible" if final_state_by_resolve is not None else "impossible" | |
| ) | |
| ) | |
| if args.repeat > 1: | |
| cli_lib.print_report_multiple_times(total_times) | |
| if args.repeat < 1: | |
| raise ValueError("Expected at least 1 repeat") | |
| if output_file is not None: | |
| output_file.close() | |
| return 0 if final_state_by_resolve is not None else 1 | |
| def add_validate_command(sub_parsers: _SubParsersAction) -> None: | |
| parser: ArgumentParser = sub_parsers.add_parser("validate", help="Validate a rdvgame file.") | |
| add_debug_argument(parser) | |
| parser.add_argument( | |
| "--no-world-graph", | |
| default=True, | |
| dest="use_world_graph", | |
| action="store_false", | |
| help="Don't use WorldGraph for generator/resolver.", | |
| ) | |
| parser.add_argument("--repeat", default=1, type=int, help="Validate multiple times. Used for benchmarking.") | |
| parser.add_argument("layout_file", type=Path, help="The rdvgame file to validate.") | |
| parser.add_argument("--write-to", type=Path, help="Write debug output to") | |
| parser.set_defaults(func=validate_command_logic) | |
Xet Storage Details
- Size:
- 2.61 kB
- Xet hash:
- 116a818086d5f19bd4c9bb84931aba75aa623bdec7810320fafb729780f5926f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.