Build a solution for a problem directory. If *solution_name* is given, looks for that file inside *problem_dir*. ``.json`` files are loaded directly; ``.py`` files are wrapped as a custom solution. Falls back to the definition's reference code when the file does not exist or *solut
(
definition: dict, problem_dir: Path, solution_name: str | None = None
)
| 115 | |
| 116 | |
| 117 | def build_solution_for_problem( |
| 118 | definition: dict, problem_dir: Path, solution_name: str | None = None |
| 119 | ) -> dict: |
| 120 | """Build a solution for a problem directory. |
| 121 | |
| 122 | If *solution_name* is given, looks for that file inside *problem_dir*. |
| 123 | ``.json`` files are loaded directly; ``.py`` files are wrapped as a custom |
| 124 | solution. Falls back to the definition's reference code when the file does |
| 125 | not exist or *solution_name* is ``None``. |
| 126 | """ |
| 127 | if solution_name is not None: |
| 128 | solution_file = problem_dir / solution_name |
| 129 | if solution_file.exists(): |
| 130 | if solution_file.suffix == ".json": |
| 131 | print(f" Using solution in {solution_file}...") |
| 132 | return json.loads(solution_file.read_text()) |
| 133 | print(f" Building solution from {solution_file}...") |
| 134 | return build_custom_solution(definition, solution_file) |
| 135 | print(" Building solution from Definition.reference...") |
| 136 | return build_reference_solution(definition) |
| 137 | |
| 138 | |
| 139 | def build_custom_solution(definition: dict, solution_py: Path) -> dict: |
no test coverage detected