From cd69caccdd0633af0986aa477b08c34f43d97553 Mon Sep 17 00:00:00 2001 From: JaGeo Date: Thu, 11 Jul 2024 06:46:26 +0200 Subject: [PATCH 1/2] add dynmic option for append_name --- src/jobflow/core/flow.py | 5 +++-- src/jobflow/core/job.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/jobflow/core/flow.py b/src/jobflow/core/flow.py index 3a8edb0d..96b6476f 100644 --- a/src/jobflow/core/flow.py +++ b/src/jobflow/core/flow.py @@ -582,7 +582,7 @@ def update_maker_kwargs( dict_mod=dict_mod, ) - def append_name(self, append_str: str, prepend: bool = False): + def append_name(self, append_str: str, prepend: bool = False, dynamic: bool = True): """ Append a string to the name of the flow and all jobs contained in it. @@ -599,7 +599,8 @@ def append_name(self, append_str: str, prepend: bool = False): self.name += append_str for job in self: - job.append_name(append_str, prepend=prepend) + job.append_name(append_str, prepend=prepend, dynamic=dynamic) + def update_metadata( self, diff --git a/src/jobflow/core/job.py b/src/jobflow/core/job.py index 0aaab450..bc4809e7 100644 --- a/src/jobflow/core/job.py +++ b/src/jobflow/core/job.py @@ -328,6 +328,7 @@ def __init__( hosts: list[str] = None, metadata_updates: list[dict[str, Any]] = None, config_updates: list[dict[str, Any]] = None, + name_updates: list[dict[str, Any]] = None, **kwargs, ): from copy import deepcopy @@ -352,6 +353,7 @@ def __init__( self.config = config self.hosts = hosts or [] self.metadata_updates = metadata_updates or [] + self.name_updates = name_updates or [] self.config_updates = config_updates or [] self._kwargs = kwargs @@ -364,6 +366,7 @@ def __init__( else: self.name = getattr(function, "__qualname__", function.__name__) + self.output = OutputReference(self.uuid, output_schema=self.output_schema) # check to see if job or flow is included in the job args @@ -621,6 +624,8 @@ def run(self, store: jobflow.JobStore, job_dir: Path = None) -> Response: new_jobs.update_metadata(**metadata_update, dynamic=True) for config_update in self.config_updates: new_jobs.update_config(**config_update, dynamic=True) + for name_update in self.name_updates: + new_jobs.append_name(**name_update, dynamic=True) if self.config.response_manager_config: passed_config = self.config.response_manager_config @@ -889,7 +894,7 @@ def update_maker_kwargs( dict_mod=dict_mod, ) - def append_name(self, append_str: str, prepend: bool = False): + def append_name(self, append_str: str, prepend: bool = False, dynamic: bool = True): """ Append a string to the name of the job. @@ -899,12 +904,17 @@ def append_name(self, append_str: str, prepend: bool = False): A string to append. prepend Prepend the name rather than appending it. + dynamic + The updates will be propagated to Jobs/Flows dynamically generated at + runtime. """ if prepend: self.name = append_str + self.name else: self.name += append_str + if dynamic: + self.name_updates.append({"append_str": append_str, "prepend": prepend}) def update_metadata( self, update: dict[str, Any], From 32972e746fea0fb9499f20e58573463de6a5d0f0 Mon Sep 17 00:00:00 2001 From: JaGeo Date: Thu, 11 Jul 2024 06:54:12 +0200 Subject: [PATCH 2/2] fix linting --- src/jobflow/core/flow.py | 1 - src/jobflow/core/job.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/jobflow/core/flow.py b/src/jobflow/core/flow.py index 96b6476f..b2f47183 100644 --- a/src/jobflow/core/flow.py +++ b/src/jobflow/core/flow.py @@ -601,7 +601,6 @@ def append_name(self, append_str: str, prepend: bool = False, dynamic: bool = Tr for job in self: job.append_name(append_str, prepend=prepend, dynamic=dynamic) - def update_metadata( self, update: dict[str, Any], diff --git a/src/jobflow/core/job.py b/src/jobflow/core/job.py index bc4809e7..ffab0a72 100644 --- a/src/jobflow/core/job.py +++ b/src/jobflow/core/job.py @@ -366,7 +366,6 @@ def __init__( else: self.name = getattr(function, "__qualname__", function.__name__) - self.output = OutputReference(self.uuid, output_schema=self.output_schema) # check to see if job or flow is included in the job args @@ -915,6 +914,7 @@ def append_name(self, append_str: str, prepend: bool = False, dynamic: bool = Tr if dynamic: self.name_updates.append({"append_str": append_str, "prepend": prepend}) + def update_metadata( self, update: dict[str, Any],