Skip to content

Commit c683738

Browse files
committed
chore: Update to use Pydantic V2, and support task chunking
Signed-off-by: Mark Wiebe <[email protected]>
1 parent 8c14e35 commit c683738

File tree

9 files changed

+30
-32
lines changed

9 files changed

+30
-32
lines changed

hatch.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ lint = [
2121
]
2222

2323
[[envs.all.matrix]]
24-
python = ["3.9", "3.10", "3.11"]
24+
python = ["3.9", "3.10", "3.11", "3.12", "3.13"]
2525

2626
[envs.codebuild.scripts]
2727
build = "hatch build"

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ classifiers = [
2929
"Intended Audience :: End Users/Desktop"
3030
]
3131
dependencies = [
32-
"openjd-sessions == 0.9.*",
33-
"openjd-model == 0.5.*"
32+
"openjd-sessions == 0.10.*",
33+
"openjd-model == 0.6.*"
3434
]
3535

3636
[project.urls]

src/openjd/cli/_check/_check_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def do_check(args: Namespace) -> OpenJDCliResult:
2727

2828
# Raises: DecodeValidationError
2929
if TemplateSpecificationVersion.is_job_template(template_version):
30-
decode_job_template(template=template_object)
30+
decode_job_template(template=template_object, supported_extensions=["TASK_CHUNKING"])
3131
elif TemplateSpecificationVersion.is_environment_template(template_version):
3232
decode_environment_template(template=template_object)
3333
else:

src/openjd/cli/_common/_validation_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def read_job_template(template_file: Path) -> JobTemplate:
6262
template_object = read_template(template_file)
6363

6464
# Raises: DecodeValidationError
65-
template = decode_job_template(template=template_object)
65+
template = decode_job_template(template=template_object, supported_extensions=["TASK_CHUNKING"])
6666

6767
return template
6868

src/openjd/cli/_run/_run_command.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ def add_run_arguments(run_parser: ArgumentParser):
6969
dest="task_params",
7070
metavar="PARAM=VALUE",
7171
help=(
72-
"This argument instructs the command to run a single task in a Session with the given value for one of the task parameters "
73-
"defined for the Step. The option must be provided once for each task parameter defined for the Step, with each instance "
74-
"providing the value for a different task parameter. Mutually exclusive with --tasks and --maximum-tasks."
72+
"This argument instructs the command to run a single task or chunk of tasks in a Session with the given value for "
73+
"one of the task parameters defined for the Step. The option must be provided once for each task parameter defined "
74+
"for the Step, with each instance providing the value for a different task parameter. Mutually exclusive with "
75+
"--tasks and --maximum-tasks."
7576
),
7677
)
7778
group.add_argument(
@@ -81,9 +82,9 @@ def add_run_arguments(run_parser: ArgumentParser):
8182
dest="tasks",
8283
metavar='file://tasks.json OR file://tasks.yaml OR [{"Param": "Value1", ...}, {"Param": "Value2", ...}]',
8384
help=(
84-
"This argument instructs the command to run one or more tasks for the Step in a Session. The argument must be either "
85-
"the filename of a JSON or YAML file containing an array of maps from task parameter name to value; or an inlined "
86-
"JSON string of the same. Mutually exclusive with --task-param/-tp and --maximum-tasks."
85+
"This argument instructs the command to run one or more tasks/chunks of tasks for the Step in a Session. "
86+
"The argument must be either the filename of a JSON or YAML file containing an array of maps from task parameter "
87+
"name to value; or an inlined JSON string of the same. Mutually exclusive with --task-param/-tp and --maximum-tasks."
8788
),
8889
)
8990
group.add_argument(
@@ -206,10 +207,8 @@ def _process_task_params(arguments: list[str]) -> dict[str, str]:
206207
)
207208

208209
if error_list:
209-
error_msg = "Found the following errors collecting Task parameters:"
210-
for error in error_list:
211-
error_msg += f"\n- {error}"
212-
raise RuntimeError(error_msg)
210+
error_msgs = "".join(f"\n - {error}" for error in error_list)
211+
raise RuntimeError("Found the following errors collecting Task parameters:" + error_msgs)
213212

214213
return parameter_set
215214

@@ -278,8 +277,8 @@ def _validate_task_params(step: Step, task_params: list[dict[str, str]]) -> None
278277

279278
# Collect the names of all of the task parameters defined in the step.
280279
if step.parameterSpace is not None:
281-
parameter_space = StepParameterSpaceIterator(space=step.parameterSpace)
282-
task_parameter_names: set[str] = set(parameter_space.names)
280+
param_space_iter = StepParameterSpaceIterator(space=step.parameterSpace)
281+
task_parameter_names: set[str] = set(param_space_iter.names)
283282
else:
284283
task_parameter_names = set[str]()
285284

@@ -298,7 +297,6 @@ def _validate_task_params(step: Step, task_params: list[dict[str, str]]) -> None
298297
error_list.append(
299298
f"Task {i} is missing values for parameters: {', '.join(sorted(missing_names))}"
300299
)
301-
302300
if error_list:
303301
error_msg = "Errors defining task parameter values:\n - "
304302
error_msg += "\n - ".join(error_list)

src/openjd/cli/_schema/_schema_command.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ def do_get_schema(args: Namespace) -> OpenJDCliResult:
5959
schema_doc: dict = {}
6060

6161
try:
62-
# The `schema` attribute will have to be updated if/when Pydantic
63-
# is updated to v2.
64-
# (AFAIK it can be replaced with `model_json_schema()`.)
65-
schema_doc = Template.schema()
62+
schema_doc = Template.model_json_schema()
6663
_process_regex(schema_doc)
6764
except Exception as e:
6865
return OpenJDCliResult(status="error", message=f"ERROR generating schema: {str(e)}")

test/openjd/cli/test_common.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from openjd.cli._common._job_from_template import job_from_template
2727
from openjd.model import (
2828
DecodeValidationError,
29-
decode_template,
29+
decode_job_template,
3030
)
3131

3232

@@ -364,11 +364,13 @@ def test_job_from_template_success(
364364
Test that `job_from_template` creates a Job with the provided parameters.
365365
"""
366366
template_dir, current_working_dir = template_dir_and_cwd
367-
template = decode_template(template=template_dict)
367+
template = decode_job_template(template=template_dict)
368368

369369
result = job_from_template(template, mock_params, template_dir, current_working_dir)
370370
assert result.name == expected_job_name
371-
assert result.steps == template.steps
371+
assert [step.model_dump(exclude_none=True) for step in result.steps] == [
372+
step.model_dump(exclude_none=True) for step in template.steps
373+
]
372374
if result.parameters:
373375
assert len(result.parameters) == len(mock_params)
374376

@@ -410,7 +412,7 @@ def test_job_from_template_error(
410412
"""
411413
template_dir, current_working_dir = template_dir_and_cwd
412414

413-
template = decode_template(template=template_dict)
415+
template = decode_job_template(template=template_dict)
414416

415417
with pytest.raises(RuntimeError) as rte:
416418
job_from_template(template, mock_params, template_dir, current_working_dir)

test/openjd/cli/test_schema_command.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from openjd.cli._schema._schema_command import do_get_schema, _process_regex
44
from openjd.model import TemplateSpecificationVersion
5-
from pydantic.v1 import BaseModel
5+
import openjd.model.v2023_09
66

77
from argparse import Namespace
88
import json
@@ -129,9 +129,10 @@ def test_do_get_schema_error(capsys: pytest.CaptureFixture):
129129
"""
130130

131131
with (
132-
patch.object(BaseModel, "schema", side_effect=RuntimeError("Test error")),
132+
patch.object(openjd.model.v2023_09, "JobTemplate") as job_template_class,
133133
pytest.raises(SystemExit),
134134
):
135+
job_template_class.model_json_schema.side_effect = RuntimeError("Test error")
135136
do_get_schema(
136137
Namespace(
137138
version=TemplateSpecificationVersion.JOBTEMPLATE_v2023_09.value,

test/openjd/cli/test_summary_command.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
ParameterValue,
2222
ParameterValueType,
2323
create_job,
24-
decode_template,
24+
decode_job_template,
2525
)
2626

2727

@@ -236,7 +236,7 @@ def test_get_output_step_summary_success(
236236
"""
237237
Test that `output_summary_result` returns an object with the expected values when called with a Step.
238238
"""
239-
template = decode_template(template=template_dict)
239+
template = decode_job_template(template=template_dict)
240240
job = create_job(job_template=template, job_parameter_values=mock_job_params)
241241

242242
response = output_summary_result(job, step_name)
@@ -256,7 +256,7 @@ def test_output_step_summary_result_error():
256256
Test that `output_summary_result` throws an error if a non-existent Step name is provided.
257257
(function only has one error state)
258258
"""
259-
template = decode_template(template=MOCK_TEMPLATE)
259+
template = decode_job_template(template=MOCK_TEMPLATE)
260260
job = create_job(job_template=template, job_parameter_values={})
261261

262262
response = output_summary_result(job, "no step")
@@ -452,7 +452,7 @@ def test_output_job_summary_result_success(
452452
"""
453453
Test that `output_summary_result` returns an object with the expected values when called on a Job.
454454
"""
455-
template = decode_template(template=template_dict)
455+
template = decode_job_template(template=template_dict)
456456
job = create_job(job_template=template, job_parameter_values=mock_params)
457457

458458
response = output_summary_result(job)

0 commit comments

Comments
 (0)