From b75dbc7befceac1b29321e576a489e6cf3c30de0 Mon Sep 17 00:00:00 2001 From: Imogen Date: Mon, 9 Oct 2023 17:52:26 +0200 Subject: [PATCH 1/4] remove erroneous problem existence check --- algobattle/match.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/algobattle/match.py b/algobattle/match.py index ebbc28e9..5d8aad10 100644 --- a/algobattle/match.py +++ b/algobattle/match.py @@ -624,15 +624,6 @@ class AlgobattleConfig(BaseModel): model_config = ConfigDict(revalidate_instances="always") - @model_validator(mode="after") - def check_problem_defined(self) -> Self: - """Validates that the specified problem is either installed or dynamically specified.""" - prob = self.match.problem - if not self.problem.location.is_file() and prob not in Problem.available(): - raise ValueError(f"The specified problem {prob} cannot be found") - else: - return self - @cached_property def loaded_problem(self) -> Problem: """The problem this config uses.""" From d689f659c520bda1951a11b03537aeffddc899ba Mon Sep 17 00:00:00 2001 From: Imogen Date: Mon, 9 Oct 2023 18:02:58 +0200 Subject: [PATCH 2/4] import problems into an empty cache --- algobattle/problem.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/algobattle/problem.py b/algobattle/problem.py index 51264568..4b340e03 100644 --- a/algobattle/problem.py +++ b/algobattle/problem.py @@ -332,12 +332,15 @@ def score( def load_file(cls, name: str, file: Path) -> Self: """Loads the problem from the specified file.""" existing_problems = cls._problems.copy() - import_file_as_module(file, "__algobattle_problem__") - new_problems = {n: p for n, p in cls._problems.items() if n not in existing_problems} - if name not in new_problems: - raise ValueError(f"The {name} problem is not defined in {file}") - else: - return cls._problems[name] + cls._problems = {} + try: + import_file_as_module(file, "__algobattle_problem__") + if name not in cls._problems: + raise ValueError(f"The {name} problem is not defined in {file}") + else: + return cls._problems[name] + finally: + cls._problems = existing_problems @classmethod def load(cls, name: str, file: Path | None = None) -> Self: From 7178c3dfd8a1c2142bfe4a657f9b5d364b161ee7 Mon Sep 17 00:00:00 2001 From: Imogen Date: Mon, 9 Oct 2023 18:07:37 +0200 Subject: [PATCH 3/4] properly relativize problem location before importing --- algobattle/cli.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/algobattle/cli.py b/algobattle/cli.py index 6bf0f180..cf20da51 100644 --- a/algobattle/cli.py +++ b/algobattle/cli.py @@ -350,6 +350,8 @@ def init( gitignore += f"{res_path.relative_to(target)}/\n" target.joinpath(".gitignore").write_text(gitignore) + if not parsed_config.problem.location.is_absolute(): + parsed_config.problem.location = target / parsed_config.problem.location problem_obj = parsed_config.loaded_problem if schemas: instance: type[Instance] = problem_obj.instance_cls From 8ee192d95aa9e2c21721550d9d7e3b177e248677 Mon Sep 17 00:00:00 2001 From: Imogen Date: Mon, 9 Oct 2023 18:49:55 +0200 Subject: [PATCH 4/4] bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 69c46919..800b58df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "pdm.backend" [project] name = "algobattle-base" -version = "4.0.0" +version = "4.0.1" description = "The Algobattle lab course package." readme = "README.md" requires-python = ">=3.11"