From a2e44a7e3d8788019396f97af0c36c377aae34d5 Mon Sep 17 00:00:00 2001 From: Peter van Heusden Date: Wed, 20 May 2026 13:51:16 +0200 Subject: [PATCH 1/4] Fix where singularity build ends up with empty parameter --- bactopia/cli/download.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bactopia/cli/download.py b/bactopia/cli/download.py index 2a398bd..79346d0 100644 --- a/bactopia/cli/download.py +++ b/bactopia/cli/download.py @@ -315,7 +315,7 @@ def build_singularity_image( singularity_exe="singularity", ): """Build Conda env, with chance to retry.""" - force = "--force" if force else "" + force = "--force " if force else "" retry = 0 allow_fail = False success = False @@ -323,7 +323,7 @@ def build_singularity_image( result = None if use_build: result = execute( - f"{singularity_exe} build {force} {image} {pull}", allow_fail=allow_fail + f"{singularity_exe} build {force}{image} {pull}", allow_fail=allow_fail ) else: # Download from Galaxy Project From 5d4554844082e2f90a1d428e896b8720c634faac Mon Sep 17 00:00:00 2001 From: Peter van Heusden Date: Wed, 20 May 2026 14:05:21 +0200 Subject: [PATCH 2/4] Replace string split with shlex split --- bactopia/cli/download.py | 4 ++-- bactopia/utils.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bactopia/cli/download.py b/bactopia/cli/download.py index 79346d0..2a398bd 100644 --- a/bactopia/cli/download.py +++ b/bactopia/cli/download.py @@ -315,7 +315,7 @@ def build_singularity_image( singularity_exe="singularity", ): """Build Conda env, with chance to retry.""" - force = "--force " if force else "" + force = "--force" if force else "" retry = 0 allow_fail = False success = False @@ -323,7 +323,7 @@ def build_singularity_image( result = None if use_build: result = execute( - f"{singularity_exe} build {force}{image} {pull}", allow_fail=allow_fail + f"{singularity_exe} build {force} {image} {pull}", allow_fail=allow_fail ) else: # Download from Galaxy Project diff --git a/bactopia/utils.py b/bactopia/utils.py index 66daa53..35ddf3c 100644 --- a/bactopia/utils.py +++ b/bactopia/utils.py @@ -1,4 +1,5 @@ import logging +import shlex import subprocess import sys from pathlib import Path @@ -33,7 +34,7 @@ def execute( logging.debug(f"Working directory: {directory}") try: command = subprocess.run( - cmd.split(" "), # Replace with your command and arguments + shlex.split(cmd), # Replace with your command and arguments cwd=directory, capture_output=True, text=True, # Decodes stdout/stderr as strings using default encoding From 4efd8ae7e5ee361cf672ee068cfba9e219cb10ca Mon Sep 17 00:00:00 2001 From: Peter van Heusden Date: Wed, 20 May 2026 14:08:03 +0200 Subject: [PATCH 3/4] Return stdout and stderr even if command fails --- bactopia/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bactopia/utils.py b/bactopia/utils.py index 35ddf3c..337583e 100644 --- a/bactopia/utils.py +++ b/bactopia/utils.py @@ -49,6 +49,8 @@ def execute( else: return command.returncode except subprocess.CalledProcessError as e: + logging.debug(f"STDOUT: \n{command.stdout}") + logging.debug(f"STDERR:\n{command.stderr}") if allow_fail: logging.debug(f'"{cmd}" return exit code {e.returncode}') logging.debug(e) From 55c6de218b14260c27593efc24786544146822d0 Mon Sep 17 00:00:00 2001 From: Peter van Heusden Date: Wed, 20 May 2026 14:36:37 +0200 Subject: [PATCH 4/4] Fix and rationalise error reporting --- bactopia/utils.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bactopia/utils.py b/bactopia/utils.py index 337583e..ba6646f 100644 --- a/bactopia/utils.py +++ b/bactopia/utils.py @@ -49,18 +49,19 @@ def execute( else: return command.returncode except subprocess.CalledProcessError as e: - logging.debug(f"STDOUT: \n{command.stdout}") - logging.debug(f"STDERR:\n{command.stderr}") if allow_fail: - logging.debug(f'"{cmd}" return exit code {e.returncode}') - logging.debug(e) + logger = logging.debug + else: + logger = logging.error + logger(f"STDOUT: \n{e.stdout}") + logger(f"STDERR:\n{e.stderr}") + logger(f'"{cmd}" return exit code {e.returncode}') + logger(e) + if allow_fail: return None else: - logging.error(f'"{cmd}" return exit code {e.returncode}') - logging.error(e) sys.exit(e.returncode) - def pgzip(files: list, cpus: int) -> list: """ Parallel gzip a list of files