diff --git a/src/ccbr_tools/peek.py b/src/ccbr_tools/peek.py index 46fade0..212bf31 100755 --- a/src/ccbr_tools/peek.py +++ b/src/ccbr_tools/peek.py @@ -79,7 +79,7 @@ def pprint(headlist, data, linelength, fn): def peek(filename, buffer, delim="\t"): - pargs() + # pargs() # Getting contents of first line try: diff --git a/src/ccbr_tools/pipeline/hpc.py b/src/ccbr_tools/pipeline/hpc.py index a2651e9..835f37c 100755 --- a/src/ccbr_tools/pipeline/hpc.py +++ b/src/ccbr_tools/pipeline/hpc.py @@ -71,7 +71,7 @@ class Biowulf(Cluster): GROUP = "CCBR_Pipeliner" PIPELINES_HOME = pathlib.Path("/data/CCBR_Pipeliner/Pipelines") TOOLS_HOME = pathlib.Path("/data/CCBR_Pipeliner/Tools") - CONDA_ACTIVATE = '. "/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh" && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311' + CONDA_ACTIVATE = ". '/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh' && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311" def __init__(self): super().__init__() @@ -102,7 +102,7 @@ class FRCE(Cluster): GROUP = "nci-frederick-ccbr-pipelines" PIPELINES_HOME = pathlib.Path("/mnt/projects/CCBR-Pipelines/pipelines") TOOLS_HOME = pathlib.Path("/mnt/projects/CCBR-Pipelines/tools") - CONDA_ACTIVATE = '. "/mnt/projects/CCBR-Pipelines/resources/miniconda3/etc/profile.d/conda.sh" && conda activate py311' + CONDA_ACTIVATE = ". '/mnt/projects/CCBR-Pipelines/resources/miniconda3/etc/profile.d/conda.sh' && conda activate py311" def __init__(self): super().__init__() diff --git a/src/ccbr_tools/pipeline/nextflow.py b/src/ccbr_tools/pipeline/nextflow.py index 9dcef1f..8675780 100755 --- a/src/ccbr_tools/pipeline/nextflow.py +++ b/src/ccbr_tools/pipeline/nextflow.py @@ -90,7 +90,9 @@ def run( if "-preview" not in args_dict.keys(): if hpc: hpc_modules = hpc.modules["nxf"] - preview_command = f'bash -c "module load {hpc_modules} && {hpc.env_vars} && {nextflow_command} -preview"' + preview_command = ( + f'bash -c "module load {hpc_modules} && {nextflow_command} -preview"' + ) else: preview_command = nextflow_command + " -preview" msg_box("Pipeline Preview", errmsg=preview_command) diff --git a/src/ccbr_tools/send_email.py b/src/ccbr_tools/send_email.py index 4bee28d..f797de8 100644 --- a/src/ccbr_tools/send_email.py +++ b/src/ccbr_tools/send_email.py @@ -49,5 +49,6 @@ def send_email_msg( ) if debug: return msg - with smtplib.SMTP("localhost") as server: - server.send_message(msg) + else: + with smtplib.SMTP("localhost") as server: + server.send_message(msg) diff --git a/src/ccbr_tools/shell.py b/src/ccbr_tools/shell.py index b15822e..5ad8fd6 100755 --- a/src/ccbr_tools/shell.py +++ b/src/ccbr_tools/shell.py @@ -28,7 +28,7 @@ def shell_run(command_str, capture_output=True, check=True, shell=True, text=Tru '/bin/sh: invalid_command: command not found\n' """ out = subprocess.run( - command_str, capture_output=capture_output, shell=shell, text=text, check=check + command_str, capture_output=capture_output, check=check, shell=shell, text=text ) if capture_output: return_val = concat_newline(out.stdout, out.stderr) diff --git a/tests/data/templates/submit_slurm.sh b/tests/data/templates/submit_slurm.sh new file mode 100644 index 0000000..dc9e55f --- /dev/null +++ b/tests/data/templates/submit_slurm.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +#SBATCH --cpus-per-task=1 +#SBATCH --mem=1g +#SBATCH --time=1-00:00:00 +#SBATCH --parsable +#SBATCH -J "CCBR_nxf" +#SBATCH --mail-type=BEGIN,END,FAIL +#SBATCH --output "log/slurm_%j.log" +#SBATCH --error "log/slurm_%j.log" + +module load nextflow + +export SINGULARITY_CACHEDIR=/gpfs/gsfs10/users/CCBR_Pipeliner/Tools/ccbr_tools/tools-dev-sovacool/.singularity +if ! command -v spooker 2>&1 >/dev/null; then export PATH="$PATH:/data/CCBR_Pipeliner/Tools/ccbr_tools/v0.2/bin/"; fi + +nextflow run main.nf -stub diff --git a/tests/test_cli.py b/tests/test_cli.py index f58ec2c..a3171ba 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2,15 +2,23 @@ import os import pathlib +import pytest import tempfile +is_ci = ( + os.environ.get("CI", "false") == "true" +) # Set CI to false if not in a CI environment + def test_version_flag(): - assert shell_run("ccbr_tools -v").startswith("ccbr_tools, version ") + version = shell_run("ccbr_tools --version") + assert version.startswith("ccbr_tools, version ") +@pytest.mark.skipif(is_ci, reason="Skip on CI") def test_version_cmd(): - assert shell_run("ccbr_tools version --debug").startswith("VERSION file path") + version = shell_run("ccbr_tools version --debug") + assert version.startswith("VERSION file path") def test_help(): @@ -52,6 +60,7 @@ def test_help_peek(): assert "USAGE: peek [buffer]" in shell_run("peek -h") +@pytest.mark.skipif(is_ci, reason="Skip on CI") def test_send_email(): assert "" == shell_run("ccbr_tools send-email -d") @@ -79,7 +88,7 @@ def test_install(): output = shell_run("ccbr_tools install champagne v0.3.0 --hpc biowulf", check=False) assert ( output - == """. "/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh" && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311 + == """. '/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh' && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311 pip install git+https://github.com/CCBR/CHAMPAGNE.git@v0.3.0 -t /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0 chmod -R a+rX /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0 chown -R :CCBR_Pipeliner /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0 diff --git a/tests/test_nextflow.py b/tests/test_nextflow.py index bddfc6b..1a7389a 100644 --- a/tests/test_nextflow.py +++ b/tests/test_nextflow.py @@ -3,7 +3,7 @@ import tempfile from ccbr_tools.pipeline.nextflow import run, init -from ccbr_tools.pipeline.hpc import Biowulf, FRCE +from ccbr_tools.pipeline.hpc import Biowulf, FRCE, get_hpc from ccbr_tools.shell import exec_in_context diff --git a/tests/test_pipeline_hpc.py b/tests/test_pipeline_hpc.py index d2a34a8..3c4ee42 100644 --- a/tests/test_pipeline_hpc.py +++ b/tests/test_pipeline_hpc.py @@ -12,7 +12,7 @@ def test_hpc_biowulf(): "({'name': 'biowulf'" ), hpc.CONDA_ACTIVATE - == '. "/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh" && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311', + == ". '/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh' && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311", ] ) @@ -26,7 +26,7 @@ def test_hpc_frce(): "/mnt/projects/CCBR-Pipelines/bin" in hpc.env_vars, hpc.singularity_sif_dir == "/mnt/projects/CCBR-Pipelines/SIFs", hpc.CONDA_ACTIVATE - == '. "/mnt/projects/CCBR-Pipelines/resources/miniconda3/etc/profile.d/conda.sh" && conda activate py311', + == ". '/mnt/projects/CCBR-Pipelines/resources/miniconda3/etc/profile.d/conda.sh' && conda activate py311", ] ) diff --git a/tests/test_software.py b/tests/test_software.py index 6077fb1..b758d7c 100644 --- a/tests/test_software.py +++ b/tests/test_software.py @@ -44,7 +44,7 @@ def test_install(): ) assert ( result - == """. "/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh" && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311 + == """. '/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh' && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311 pip install git+https://github.com/CCBR/CHAMPAGNE.git@v0.3.0 -t /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0 chmod -R a+rX /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0 chown -R :CCBR_Pipeliner /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0 @@ -67,7 +67,7 @@ def test_install_dev(): ) assert ( result - == """. "/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh" && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311 + == """. '/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh' && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311 pip install git+https://github.com/CCBR/CHAMPAGNE.git@main -t /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0-dev chmod -R a+rX /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0-dev chown -R :CCBR_Pipeliner /data/CCBR_Pipeliner/Pipelines/CHAMPAGNE/.v0.3.0-dev @@ -86,7 +86,7 @@ def test_custom(): ) assert ( result - == """. "/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh" && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311 + == """. '/data/CCBR_Pipeliner/db/PipeDB/Conda/etc/profile.d/conda.sh' && conda activate /data/CCBR_Pipeliner/db/PipeDB/Conda/envs/py311 pip install git+https://github.com/CCBR/cooltool.git@v1.0.0 -t /data/CCBR_Pipeliner/Tools/cooltool/.v1.0.0 chmod -R a+rX /data/CCBR_Pipeliner/Tools/cooltool/.v1.0.0 chown -R :CCBR_Pipeliner /data/CCBR_Pipeliner/Tools/cooltool/.v1.0.0 diff --git a/tests/test_templates.py b/tests/test_templates.py index 97639e4..2af7ae9 100644 --- a/tests/test_templates.py +++ b/tests/test_templates.py @@ -4,6 +4,7 @@ import tempfile from ccbr_tools.templates import read_template, use_template, use_quarto_ext +from ccbr_tools.pipeline.hpc import get_hpc def test_read_template(): @@ -38,6 +39,18 @@ def test_use_template(): assert all(assertions) +def generate_slurm_template(): + hpc = get_hpc(debug="biowulf") + use_template( + "submit_slurm.sh", + output_filepath="tests/data/templates/submit_slurm.sh", + PIPELINE="CCBR_nxf", + MODULES=hpc.modules["nxf"], + ENV_VARS=hpc.env_vars, + RUN_COMMAND="nextflow run main.nf -stub", + ) + + def test_use_template_blanks(): with tempfile.TemporaryDirectory() as tmp_dir: out_filepath = pathlib.Path(tmp_dir) / "test.sh"