Skip to content

Commit 3bf3af3

Browse files
authored
Merge pull request #547 from piskoviste/fix/opendata-cms-old
Disable cms-old generator for opendata module
2 parents bfd9e6d + bbcd15e commit 3bf3af3

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

pisek/cms/dataset.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import datetime
2121
from typing import Callable, TypeVar, assert_never
2222

23+
from pisek.user_errors import NotSupported
2324
from pisek.cms.testcase import create_testcase
2425
from pisek.env.env import Env
2526
from pisek.config.task_config import TaskConfig
@@ -31,7 +32,7 @@
3132

3233
def check_key(name: str, value: T, condition: Callable[[T], bool]):
3334
if not condition(value):
34-
raise RuntimeError(f"Cannot import task with {name}={value}")
35+
raise NotSupported(f"Cannot import task with {name}={value}")
3536

3637

3738
def create_dataset(
@@ -112,7 +113,7 @@ def create_dataset(
112113
task_type = "Communication"
113114
task_params = (1, "stub" if config.cms.stubs else "alone", "std_io")
114115
else:
115-
raise RuntimeError(f"Cannot upload {config.task.task_type} task to CMS")
116+
assert_never(config.task.task_type)
116117

117118
dataset = Dataset(
118119
description=description,

pisek/opendata/lib.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515
import os
1616
import shutil
1717
import tempfile
18-
from typing import cast
1918

20-
from pisek.user_errors import InvalidArgument, InvalidOperation, TestingFailed
19+
from pisek.user_errors import (
20+
InvalidArgument,
21+
InvalidOperation,
22+
TestingFailed,
23+
NotSupported,
24+
)
2125
from pisek.utils.paths import (
2226
BUILD_DIR,
2327
TESTS_DIR,
@@ -28,6 +32,7 @@
2832
OpendataOutputPath,
2933
)
3034
from pisek.utils.pipeline_tools import run_pipeline
35+
from pisek.config.config_types import GenType
3136
from pisek.config.config_hierarchy import DEFAULT_CONFIG_FILENAME
3237
from pisek.config.task_config import load_config
3338
from pisek.config.config_tools import export_config
@@ -54,25 +59,33 @@ def __init__(
5459
config_filename: str = DEFAULT_CONFIG_FILENAME,
5560
) -> None:
5661
self._path = path
57-
self._env_args = ENV_ARGS | {
58-
"pisek_dir": pisek_dir,
59-
"config_filename": config_filename,
60-
}
62+
self._pisek_dir = pisek_dir or os.environ.get("PISEK_DIRECTORY")
63+
self._config_filename = config_filename
6164

6265
def test(self, strict: bool = True, disable_cache: bool = False) -> bool:
6366
try:
6467
run_pipeline(
6568
self._path,
6669
TaskPipeline,
70+
pisek_dir=self._pisek_dir,
71+
config_filename=self._config_filename,
6772
disable_cache=disable_cache,
6873
strict=strict,
69-
**self._env_args,
74+
**ENV_ARGS,
7075
)
7176
except TestingFailed:
7277
return False
7378
return True
7479

7580
def build(self, path: str) -> "BuiltTask":
81+
config = load_config(
82+
self._path, self._pisek_dir, self._config_filename, False, True
83+
)
84+
if config.tests.gen_type == GenType.cms_old:
85+
raise NotSupported(
86+
"For opendata tasks, the cms-old generator is not supported."
87+
)
88+
7689
if os.path.exists(path):
7790
if not os.path.isdir(path):
7891
raise InvalidArgument(f"{path} should be a directory")
@@ -83,9 +96,11 @@ def build(self, path: str) -> "BuiltTask":
8396
run_pipeline(
8497
self._path,
8598
TaskPipeline,
99+
pisek_dir=self._pisek_dir,
100+
config_filename=self._config_filename,
86101
target=TestingTarget.build,
87102
disable_cache=True,
88-
**self._env_args,
103+
**ENV_ARGS,
89104
)
90105

91106
COPIED_PATHS = [
@@ -106,9 +121,8 @@ def build(self, path: str) -> "BuiltTask":
106121

107122
export_config(
108123
self._path,
109-
cast(str | None, self._env_args["pisek_dir"])
110-
or os.environ.get("PISEK_DIRECTORY"),
111-
cast(str, self._env_args["config_filename"]),
124+
self._pisek_dir,
125+
self._config_filename,
112126
os.path.join(path, DEFAULT_CONFIG_FILENAME),
113127
)
114128

pisek/user_errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ class InvalidArgument(UserError):
3838

3939
class InvalidOperation(UserError):
4040
pass
41+
42+
43+
class NotSupported(UserError):
44+
pass

0 commit comments

Comments
 (0)