Skip to content

Commit

Permalink
chore: update dependencies on openjd packages
Browse files Browse the repository at this point in the history
Summary:
Newer versions of the openjd-model and openjd-sessions packages have been
released. The changes include some quality-of-life improvements to template
input validation, so we want to update the cli to have these changes.

This updates the cli dependencies and makes the required changes.

Signed-off-by: Daniel Neilson <[email protected]>
  • Loading branch information
ddneilson committed Feb 12, 2024
1 parent 975863a commit fbcb12e
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 56 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ classifiers = [
"Intended Audience :: End Users/Desktop"
]
dependencies = [
"openjd-sessions == 0.3.*",
"openjd-model == 0.2.*"
"openjd-sessions == 0.4.*",
"openjd-model == 0.3.*"
]

[project.scripts]
Expand Down
8 changes: 4 additions & 4 deletions src/openjd/cli/_check/_check_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from argparse import Namespace
from openjd.model import (
DecodeValidationError,
SchemaVersion,
TemplateSpecificationVersion,
decode_job_template,
decode_environment_template,
)
Expand All @@ -23,12 +23,12 @@ def do_check(args: Namespace) -> OpenJDCliResult:
document_version = template_object["specificationVersion"]

# Raises: ValueError
template_version = SchemaVersion(document_version)
template_version = TemplateSpecificationVersion(document_version)

# Raises: DecodeValidationError
if SchemaVersion.is_job_template(template_version):
if TemplateSpecificationVersion.is_job_template(template_version):
decode_job_template(template=template_object)
elif SchemaVersion.is_environment_template(template_version):
elif TemplateSpecificationVersion.is_environment_template(template_version):
decode_environment_template(template=template_object)
else:
return OpenJDCliResult(
Expand Down
11 changes: 6 additions & 5 deletions src/openjd/cli/_run/_local_session/_actions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

from openjd.model import Step
from openjd.model import Step, TaskParameterSet
from openjd.model.v2023_09 import Environment
from openjd.sessions import Parameter, Session
from openjd.sessions import Session


class SessionAction:
Expand All @@ -21,9 +21,9 @@ def run(self):

class RunTaskAction(SessionAction):
_step: Step
_parameters: list[Parameter]
_parameters: TaskParameterSet

def __init__(self, session: Session, step: Step, parameters: list[Parameter]):
def __init__(self, session: Session, step: Step, parameters: TaskParameterSet):
super(RunTaskAction, self).__init__(session)
self._step = step
self._parameters = parameters
Expand All @@ -34,7 +34,8 @@ def run(self):
)

def __str__(self):
return f"Run Step '{self._step.name}' with Task parameters '{[parameter.value for parameter in self._parameters]}'"
parameters = {name: parameter.value for name, parameter in self._parameters.items()}
return f"Run Step '{self._step.name}' with Task parameters '{str(parameters)}'"


class EnterEnvironmentAction(SessionAction):
Expand Down
44 changes: 13 additions & 31 deletions src/openjd/cli/_run/_local_session/_session_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from openjd.model import (
EnvironmentTemplate,
Job,
JobParameterValues,
ParameterValue,
ParameterValueType,
Step,
Expand All @@ -23,7 +24,6 @@
LOG,
ActionState,
ActionStatus,
Parameter,
Session,
SessionState,
PathMappingRule,
Expand Down Expand Up @@ -70,17 +70,19 @@ def __init__(
self._path_mapping_rules = path_mapping_rules
self._environments = environments

# Evaluate Job parameters, if applicable
# Create an inner Session
job_parameters: JobParameterValues
if job.parameters:
parameters_as_list = [
Parameter(type=ParameterValueType(param.type.name), name=name, value=param.value)
for (name, param) in job.parameters.items()
]
job_parameters = {
name: ParameterValue(type=param.type, value=param.value)
for name, param in job.parameters.items()
}
else:
job_parameters = dict[str, JobParameterValues]()

# Create an inner Session
self._inner_session = Session(
session_id=self.session_id,
job_parameter_values=parameters_as_list if job.parameters else [],
job_parameter_values=job_parameters,
path_mapping_rules=self._path_mapping_rules,
callback=self._action_callback,
)
Expand Down Expand Up @@ -174,22 +176,13 @@ def initialize(
for parameter_set in StepParameterSpaceIterator(space=dep.parameterSpace):
self._action_queue.put(
RunTaskAction(
session=self._inner_session,
step=dep,
parameters=[
Parameter(
type=param.type,
name=name,
value=param.value,
)
for name, param in parameter_set.items()
],
session=self._inner_session, step=dep, parameters=parameter_set
)
)

# The Step specified by the user is the only one that needs to use custom Task parameters, if given
if not step.parameterSpace:
self._action_queue.put(RunTaskAction(self._inner_session, step=step, parameters=[]))
self._action_queue.put(RunTaskAction(self._inner_session, step=step, parameters=dict()))

else:
if not task_parameter_values:
Expand Down Expand Up @@ -220,18 +213,7 @@ def initialize(

for param_set in parameter_sets:
self._action_queue.put(
RunTaskAction(
self._inner_session,
step=step,
parameters=[
Parameter(
type=param.type,
name=name,
value=param.value,
)
for name, param in param_set.items()
],
)
RunTaskAction(self._inner_session, step=step, parameters=param_set)
)

# Finally, enqueue ExitEnvironment Actions in reverse order to EnterEnvironment
Expand Down
1 change: 0 additions & 1 deletion src/openjd/cli/_run/_run_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ def do_run(args: Namespace) -> OpenJDCliResult:
elif args.tasks:
task_params = _process_tasks(args.tasks)

print(step_map[args.step])
_validate_task_params(step_map[args.step], task_params)

except RuntimeError as rte:
Expand Down
13 changes: 7 additions & 6 deletions src/openjd/cli/_schema/_schema_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
from typing import Union

from .._common import OpenJDCliResult, print_cli_result
from openjd.model import SchemaVersion, JobTemplate, EnvironmentTemplate
from openjd.model import EnvironmentTemplate, JobTemplate, TemplateSpecificationVersion


def add_schema_arguments(schema_parser: ArgumentParser) -> None:
allowed_values = [
v.value
for v in SchemaVersion
if SchemaVersion.is_job_template(v) or SchemaVersion.is_environment_template(v)
for v in TemplateSpecificationVersion
if TemplateSpecificationVersion.is_job_template(v)
or TemplateSpecificationVersion.is_environment_template(v)
]
schema_parser.add_argument(
"--version",
action="store",
type=SchemaVersion,
type=TemplateSpecificationVersion,
required=True,
help=f"The specification version to return a JSON schema document for. Allowed values: {', '.join(allowed_values)}",
)
Expand Down Expand Up @@ -46,9 +47,9 @@ def do_get_schema(args: Namespace) -> OpenJDCliResult:
"""

Template: Union[type[JobTemplate], type[EnvironmentTemplate]]
if args.version == SchemaVersion.v2023_09:
if args.version == TemplateSpecificationVersion.JOBTEMPLATE_v2023_09:
from openjd.model.v2023_09 import JobTemplate as Template
elif args.version == SchemaVersion.ENVIRONMENT_v2023_09:
elif args.version == TemplateSpecificationVersion.ENVIRONMENT_v2023_09:
from openjd.model.v2023_09 import EnvironmentTemplate as Template
else:
return OpenJDCliResult(
Expand Down
21 changes: 17 additions & 4 deletions test/openjd/cli/test_schema_command.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

from openjd.cli._schema._schema_command import do_get_schema, _process_regex
from openjd.model import SchemaVersion
from openjd.model import TemplateSpecificationVersion
from pydantic import BaseModel

from argparse import Namespace
Expand Down Expand Up @@ -64,7 +64,12 @@ def test_do_get_schema_success(capsys: pytest.CaptureFixture):
with patch(
"openjd.cli._schema._schema_command._process_regex", new=Mock(side_effect=_process_regex)
) as patched_process_regex:
do_get_schema(Namespace(version=SchemaVersion.v2023_09, output="human-readable"))
do_get_schema(
Namespace(
version=TemplateSpecificationVersion.JOBTEMPLATE_v2023_09.value,
output="human-readable",
)
)
patched_process_regex.assert_called()

model_output = capsys.readouterr().out
Expand All @@ -87,7 +92,10 @@ def test_do_get_schema_success_environment(capsys: pytest.CaptureFixture):
"openjd.cli._schema._schema_command._process_regex", new=Mock(side_effect=_process_regex)
) as patched_process_regex:
do_get_schema(
Namespace(version=SchemaVersion.ENVIRONMENT_v2023_09, output="human-readable")
Namespace(
version=TemplateSpecificationVersion.ENVIRONMENT_v2023_09.value,
output="human-readable",
)
)
patched_process_regex.assert_called()

Expand Down Expand Up @@ -124,7 +132,12 @@ def test_do_get_schema_error(capsys: pytest.CaptureFixture):
patch.object(BaseModel, "schema", side_effect=RuntimeError("Test error")),
pytest.raises(SystemExit),
):
do_get_schema(Namespace(version=SchemaVersion.v2023_09, output="human-readable"))
do_get_schema(
Namespace(
version=TemplateSpecificationVersion.JOBTEMPLATE_v2023_09.value,
output="human-readable",
)
)
output = capsys.readouterr().out

assert "Test error" in output
6 changes: 3 additions & 3 deletions test/openjd/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sys

from openjd import __main__
from openjd.model import SchemaVersion
from openjd.model import TemplateSpecificationVersion


@patch("openjd.cli._check.do_check")
Expand Down Expand Up @@ -167,10 +167,10 @@ def test_cli_schema_success(mock_schema: Mock):
"""

mock_schema.assert_not_called()
# "UNDEFINED" should always be a valid SchemaVersion option, even though the unpatched
# "UNDEFINED" should always be a valid TemplateSpecificationVersion option, even though the unpatched
# `do_get_schema` function throws an error on receiving it
with patch.object(
sys, "argv", new=(["openjd", "schema", "--version", SchemaVersion.UNDEFINED])
sys, "argv", new=(["openjd", "schema", "--version", TemplateSpecificationVersion.UNDEFINED])
):
__main__.main()
mock_schema.assert_called_once()
Expand Down

0 comments on commit fbcb12e

Please sign in to comment.