Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update dependencies on openjd packages #42

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
50 changes: 18 additions & 32 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=ParameterValueType(param.type.value), value=param.value)
for name, param in job.parameters.items()
}
else:
job_parameters = dict[str, ParameterValue]()

# 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 @@ -168,28 +170,23 @@ def initialize(
for dep in dependencies:
if not dep.parameterSpace:
self._action_queue.put(
RunTaskAction(session=self._inner_session, step=dep, parameters=[])
RunTaskAction(
session=self._inner_session,
step=dep,
parameters=dict[str, ParameterValue](),
)
)
else:
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 +217,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