From cfd0c4e259219924eda0adb4acf8631235f1a51c Mon Sep 17 00:00:00 2001 From: Nikita Karetnikov Date: Tue, 28 May 2024 11:25:17 +0200 Subject: [PATCH] Try wrapping paths in single quotes --- argo_jupyter_scheduler/utils.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/argo_jupyter_scheduler/utils.py b/argo_jupyter_scheduler/utils.py index 9c6a414..71af6ed 100644 --- a/argo_jupyter_scheduler/utils.py +++ b/argo_jupyter_scheduler/utils.py @@ -211,14 +211,19 @@ def gen_papermill_command_input( logger.info(f"html_path: {html_path}") logger.info(f"papermill_status_path: {papermill_status_path}") + # Within a single-quoted string, wraps the string in single quotes + def sq(s): + return rf"'\''{s}'\''" + + # These commands are executed within a single-quoted string below papermill = ( - f"( papermill -k {kernel_name} {input_path} {output_path} ; " - f"ec=$? ; echo $ec > {papermill_status_path} ; exit $ec )" + f"( papermill -k {sq(kernel_name)} {sq(input_path)} {sq(output_path)} ; " + f"ec=$? ; echo $ec > {sq(papermill_status_path)} ; exit $ec )" ) - jupyter = f"jupyter nbconvert --to html {output_path} --output {html_path}" + jupyter = f"jupyter nbconvert --to html {sq(output_path)} --output {sq(html_path)}" # It's important that inner quotes are single quotes to prevent shell expansion - return f"conda run -p {conda_env_path} /bin/sh -c '{{ {papermill} && {jupyter} ; }} >> {log_path} 2>&1'" + return f"conda run -p '{conda_env_path}' /bin/sh -c '{{ {papermill} && {jupyter} ; }} >> {sq(log_path)} 2>&1'" def sanitize_label(s: str):