Skip to content

Commit

Permalink
vdk-core: Rename NoOpStepDataJob to InitialisedJobInput(vmware#791)
Browse files Browse the repository at this point in the history
- Implemented as a contextmanager to reduce API surface area

Signed-off-by: David Laing <[email protected]>
  • Loading branch information
mrdavidlaing committed Apr 11, 2022
1 parent a89934c commit f01eaf6
Showing 1 changed file with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,22 @@ def initialize_job(self, context: JobContext):
context.step_builder.add_step(step)


class NoOpStepDataJob:
class InitialisedJobInput:
"""
DataJob that exposes methods to enable running each phase of the DataJob lifecycle
independently and get access to an initialised IJobInput object after the run_and_return_job_input() step
Sample usage:
datajob_directory = Path(abspath(file_relative_path(__file__, '../')))
datajob = NoOpStepDataJob(datajob_directory)
try:
datajob.initialize_job()
vdk_job_input = datajob.run_and_return_job_input()
... use vdk_job_input object to interact with SuperCollider
finally:
datajob.finalize_job()
A contextmanager that executes all the necessary "setup" logic needed to return an initialised IJobInput
Sample usage::
datajob_directory = Path(abspath(file_relative_path(__file__, '../')))
with InitialisedJobInput(datajob_directory) as vdk_job_input:
#... use vdk_job_input object to interact with SuperCollider
"""

def __init__(
self,
data_job_directory: pathlib.Path | None,
name: str | None = None,
job_args: dict | None = None,
):
if data_job_directory is None and name is None:
raise ValueError(
Expand All @@ -70,6 +65,9 @@ def __init__(
)
self._name = data_job_directory.name if name is None else name
self._data_job_directory = data_job_directory
if job_args is None:
job_args = {}
self._job_args = job_args

plugin_registry = PluginRegistry()
plugin_registry.add_hook_specs(InternalHookSpecs)
Expand All @@ -94,10 +92,7 @@ def __init__(

self._job_context = None

def initialize_job(self, args: dict = None):
if args is None:
args = {}

def __enter__(self) -> IJobInput:
self._core_context.plugin_registry.load_plugin_with_hooks_impl(
NoOpStepDataJobHookImplPlugin(), NoOpStepDataJobHookImplPlugin.__name__
)
Expand All @@ -108,16 +103,15 @@ def initialize_job(self, args: dict = None):
name=self._name,
job_directory=self._data_job_directory,
core_context=self._core_context,
job_args=JobArguments(args),
job_args=JobArguments(self._job_args),
templates=TemplatesImpl(
job_name=self._name, core_context=self._core_context
),
)
# We need to call both the initialize_job and run_job hooks to get a full initialized JobInput
self._plugin_hook.initialize_job(context=self._job_context)

def run_and_return_job_input(self) -> IJobInput:
self._plugin_hook.run_job(context=self._job_context)
return self._job_context.job_input

def finalize_job(self):
def __exit__(self, exc_type, exc_value, exc_traceback):
self._plugin_hook.finalize_job(context=self._job_context)

0 comments on commit f01eaf6

Please sign in to comment.