Skip to content

Commit

Permalink
Merge pull request #49 from sterrettJD/fix_profile
Browse files Browse the repository at this point in the history
remove input requirements from setup_profile
  • Loading branch information
sterrettJD authored Dec 6, 2023
2 parents e0cf894 + 5e39940 commit 1a6620c
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/profile_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ 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)
cookiecutter("gh:Snakemake-Profiles/slurm", output_dir=output_dir, no_input=True)


def check_profile_named_slurm(output_dir):
Expand Down Expand Up @@ -55,6 +50,32 @@ 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(config_contents):
return config_contents.replace("use-conda: \"False\"",
"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()

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):
config_path = os.path.join(output_dir, "slurm", "config.yaml")

Expand Down Expand Up @@ -100,6 +121,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)
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
Expand Down
58 changes: 58 additions & 0 deletions tests/test_profile_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1a6620c

Please sign in to comment.