From 11d0b644ea5acef0d2b475f5ed9ad07b59efc35b Mon Sep 17 00:00:00 2001 From: John Sterrett Date: Wed, 6 Dec 2023 07:54:51 -0700 Subject: [PATCH 1/5] set no input for cookiecutter --- src/profile_setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/profile_setup.py b/src/profile_setup.py index c1ac340..2141cfc 100644 --- a/src/profile_setup.py +++ b/src/profile_setup.py @@ -23,7 +23,7 @@ def get_cookiecutter_slurm_profile(output_dir): print("****You MUST answer `True` to `use_conda`.****") print("****Please leave `profile_name` as `slurm`.**** \n") - cookiecutter("gh:Snakemake-Profiles/slurm", output_dir=output_dir) + cookiecutter("gh:Snakemake-Profiles/slurm", output_dir=output_dir, no_input=True) def check_profile_named_slurm(output_dir): From ab2410edc6244bff9e8072a6e46a41953818593a Mon Sep 17 00:00:00 2001 From: John Sterrett Date: Wed, 6 Dec 2023 08:21:50 -0700 Subject: [PATCH 2/5] update use conda to true --- src/profile_setup.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/profile_setup.py b/src/profile_setup.py index 2141cfc..3e1295f 100644 --- a/src/profile_setup.py +++ b/src/profile_setup.py @@ -55,6 +55,23 @@ def check_profile_named_slurm(output_dir): """) +def write_new_config(filepath, new_contents): + with open(filepath, 'w') as file: + file.write(new_contents) + + +def set_use_conda_true(output_dir): + config_path = os.path.join(output_dir, "slurm", "config.yaml") + + with open(config_path, 'r') as file: + content = file.read() + + new = content.replace("use-conda: \"False\"", + "use-conda: \"True\"") + + write_new_config(config_path, new) + + def check_use_conda_slurm(output_dir): config_path = os.path.join(output_dir, "slurm", "config.yaml") @@ -100,6 +117,7 @@ def main(): # Check that parameters that need to be set a certain way are set that way check_profile_named_slurm(output_dir=args.output_dir) + set_use_conda_true(output_dir=args.output_dir) check_use_conda_slurm(output_dir=args.output_dir) # Setup for cluster that doesn't have hyperthreading enabled From 225478194617961e7794e3a1eba7494045adaa30 Mon Sep 17 00:00:00 2001 From: John Sterrett Date: Wed, 6 Dec 2023 08:26:26 -0700 Subject: [PATCH 3/5] refactor update homi req configs --- src/profile_setup.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/profile_setup.py b/src/profile_setup.py index 3e1295f..b45cec1 100644 --- a/src/profile_setup.py +++ b/src/profile_setup.py @@ -18,11 +18,6 @@ def get_args(): def get_cookiecutter_slurm_profile(output_dir): - print("Provide the following inputs to setup your cluster profile.\n") - print("All default options can be used, EXCEPT:") - print("****You MUST answer `True` to `use_conda`.****") - print("****Please leave `profile_name` as `slurm`.**** \n") - cookiecutter("gh:Snakemake-Profiles/slurm", output_dir=output_dir, no_input=True) @@ -60,16 +55,21 @@ def write_new_config(filepath, new_contents): file.write(new_contents) -def set_use_conda_true(output_dir): - config_path = os.path.join(output_dir, "slurm", "config.yaml") +def set_use_conda_true(config_contents): + return config_contents.replace("use-conda: \"False\"", + "use-conda: \"True\"") + +def update_HoMi_reqs_in_config(output_dir): + config_path = os.path.join(output_dir, "slurm", "config.yaml") with open(config_path, 'r') as file: content = file.read() - new = content.replace("use-conda: \"False\"", - "use-conda: \"True\"") - - write_new_config(config_path, new) + new_contents = set_use_conda_true(content) + + + write_new_config(config_path, new_contents) + def check_use_conda_slurm(output_dir): @@ -117,7 +117,7 @@ def main(): # Check that parameters that need to be set a certain way are set that way check_profile_named_slurm(output_dir=args.output_dir) - set_use_conda_true(output_dir=args.output_dir) + update_HoMi_reqs_in_config(output_dir=args.output_dir) check_use_conda_slurm(output_dir=args.output_dir) # Setup for cluster that doesn't have hyperthreading enabled From 3df8b3f67a0da0f5594501b1ac26fbdae74dd1c5 Mon Sep 17 00:00:00 2001 From: John Sterrett Date: Wed, 6 Dec 2023 08:29:08 -0700 Subject: [PATCH 4/5] add set print shell true --- src/profile_setup.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/profile_setup.py b/src/profile_setup.py index b45cec1..a7a4842 100644 --- a/src/profile_setup.py +++ b/src/profile_setup.py @@ -60,16 +60,20 @@ def set_use_conda_true(config_contents): "use-conda: \"True\"") +def set_print_shell_true(config_contents): + return config_contents.replace("printshellcmds: \"False\"", + "printshellcmds: \"True\"") + + def update_HoMi_reqs_in_config(output_dir): config_path = os.path.join(output_dir, "slurm", "config.yaml") with open(config_path, 'r') as file: content = file.read() - new_contents = set_use_conda_true(content) - - - write_new_config(config_path, new_contents) + with_conda = set_use_conda_true(content) + with_conda_and_shell = set_print_shell_true(with_conda) + write_new_config(config_path, with_conda_and_shell) def check_use_conda_slurm(output_dir): From 5e3994026bf8ba40696b576f34f9b6baa9e052c5 Mon Sep 17 00:00:00 2001 From: John Sterrett Date: Wed, 6 Dec 2023 08:38:38 -0700 Subject: [PATCH 5/5] add tests for new helper funcs --- tests/test_profile_setup.py | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/test_profile_setup.py b/tests/test_profile_setup.py index 95a3cef..b1b701d 100644 --- a/tests/test_profile_setup.py +++ b/tests/test_profile_setup.py @@ -47,3 +47,61 @@ def test_ntasks_mod(tmpdir): # check it's been updated assert "options[\"ntasks\"] = job_properties[\"threads\"]" in content assert "options[\"cpus-per-task\"] = job_properties[\"threads\"]" not in content + + +def test_replace_conda(): + content = """ + latency-wait: "5" + use-conda: "False" + use-singularity: "False" + """ + + expected = """ + latency-wait: "5" + use-conda: "True" + use-singularity: "False" + """ + + updated = ps.set_use_conda_true(content) + assert updated == expected + + +def test_replace_printshellcmds(): + content = """ + latency-wait: "5" + use-conda: "True" + printshellcmds: "False" + """ + + expected = """ + latency-wait: "5" + use-conda: "True" + printshellcmds: "True" + """ + + updated = ps.set_print_shell_true(content) + assert updated == expected + + +def test_update_config(tmpdir): + cookiecutter("gh:Snakemake-Profiles/slurm", + output_dir=tmpdir, + no_input=True) + + slurm_config_path = os.path.join(tmpdir, "slurm", "config.yaml") + with open(slurm_config_path, 'r') as file: + content = file.read() + + # check it's there by default + assert "use-conda: \"False\"" in content + assert "printshellcmds: \"False\"" in content + + # This function should replace the cpus-per-task with ntasks + ps.update_HoMi_reqs_in_config(tmpdir) + + with open(slurm_config_path, 'r') as file: + content = file.read() + + # check it's been updated + assert "use-conda: \"True\"" in content + assert "printshellcmds: \"True\"" in content \ No newline at end of file