Skip to content

Commit

Permalink
Returning to custom function for dictioanry to string conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
bhilbert4 committed Jul 28, 2023
1 parent 4adc585 commit 5fdcec1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
1 change: 0 additions & 1 deletion jwql/shared_tasks/run_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def run_pipe(input_file, short_name, work_directory, instrument, outputs, max_co
# Set any steps the user specifically asks to skip
for step, step_dict in step_args.items():
if 'skip' in step_dict:
print(f'SKIP the {step}!!')
if step_dict['skip']:
steps[step] = False

Expand Down
35 changes: 33 additions & 2 deletions jwql/shared_tasks/shared_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,41 @@ def after_setup_celery_logger(logger, **kwargs):
def collect_after_task(**kwargs):
gc.collect()

def convert_step_args_to_string(args_dict):
"""Convert the nested dictionary containing pipeline step parameter keyword/value pairs
to a string so that it can be passed via command line
Parameters
----------
args_dict : dict
Nested dictionary. Top level keys are pipeline step names. Values are dictionaries containing
keyword value pairs for that step.
Returns
-------
args_str : str
String representation of ``args_dict``
"""
args_str="'{"

for i, step in enumerate(args_dict):
args_str += f'"{step}":'
args_str += '{'
for j, (param, val) in enumerate(args_dict[step].items()):
args_str += f'"{param}":"{val}"'
if j < len(args_dict[step])-1:
args_str += ', '
args_str += "}"
if i < len(args_dict)-1:
args_str += ','
args_str += "}'"
return args_str


def run_subprocess(name, cmd, outputs, cal_dir, ins, in_file, short_name, res_file, cores, step_args):
# Convert step_args dictionary to a string so that it can be passed via command line
step_args_str = json.loads(step_args)
# Convert step_args dictionary to a string so that it can be passed via command line.
# For some reason, json.dumps() doesn't seem to work correctly, so we use a custom function.
step_args_str = convert_step_args_to_string(step_args)

command = "{} {} {} '{}' {} {} {} {} --step_args {}"
command = command.format(name, cmd, outputs, cal_dir, ins, in_file, short_name, cores, step_args_str)
Expand Down

0 comments on commit 5fdcec1

Please sign in to comment.