Skip to content

Commit

Permalink
Merge pull request #644 from JaGeo/main
Browse files Browse the repository at this point in the history
Add dynamic option to append_name
  • Loading branch information
utf authored Jul 18, 2024
2 parents dc5fe0f + 32972e7 commit 06a2b36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/jobflow/core/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -599,7 +599,7 @@ 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,
Expand Down
12 changes: 11 additions & 1 deletion src/jobflow/core/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -621,6 +623,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
Expand Down Expand Up @@ -889,7 +893,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.
Expand All @@ -899,12 +903,18 @@ 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],
Expand Down

0 comments on commit 06a2b36

Please sign in to comment.