From 6737f66f68db49726dccdac5b290f3b2fd241839 Mon Sep 17 00:00:00 2001
From: Johannes Schumann <johannes.schumann@fau.de>
Date: Thu, 5 Aug 2021 15:47:42 +0200
Subject: [PATCH] Fix control for local GiBUU installation

---
 km3buu/ctrl.py        | 12 +++++-------
 km3buu/environment.py |  6 +++++-
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/km3buu/ctrl.py b/km3buu/ctrl.py
index 2892f2a..ebf63e2 100644
--- a/km3buu/ctrl.py
+++ b/km3buu/ctrl.py
@@ -15,6 +15,7 @@ __status__ = "Development"
 from shutil import copy
 import subprocess
 from spython.main import Client
+import os
 from os.path import join, abspath, basename, isdir, isfile
 from tempfile import NamedTemporaryFile, TemporaryDirectory
 from thepipe.logger import get_logger
@@ -22,15 +23,10 @@ from thepipe.logger import get_logger
 from . import IMAGE_NAME
 from .config import Config
 from .jobcard import Jobcard, read_jobcard
-from .environment import is_singularity_version_greater, MIN_SINGULARITY_VERSION
+from .environment import check_singularity_version
 
 log = get_logger(basename(__file__))
 
-if not is_singularity_version_greater(
-        MIN_SINGULARITY_VERSION):  # pragma: no cover
-    log.error("Singularity version lower than %s" % MIN_SINGULARITY_VERSION)
-    raise OSError("Singularity version below %s" % MIN_SINGULARITY_VERSION)
-
 GIBUU_SHELL = """
 #!/bin/bash
 
@@ -84,6 +80,7 @@ def run_jobcard(jobcard, outdir, container=False):
     with open(jobcard_fpath, "w") as f:
         f.write(str(jobcard))
     if container:
+        check_singularity_version()
         log.info("Create temporary file for associated runscript")
         script_fpath = join(input_dir.name, "run.sh")
         with open(script_fpath, "w") as f:
@@ -106,6 +103,7 @@ def run_jobcard(jobcard, outdir, container=False):
         return output["return_code"]
     else:
         p = subprocess.Popen(
-            [os.environ["CONTAINER_GIBUU_EXEC"], "<", jobcard_fpath],
+            "%s < %s" % (os.environ["CONTAINER_GIBUU_EXEC"], jobcard_fpath),
+            shell=True,
             cwd=outdir)
         return p.wait()
diff --git a/km3buu/environment.py b/km3buu/environment.py
index 8a4c3f0..624a091 100644
--- a/km3buu/environment.py
+++ b/km3buu/environment.py
@@ -25,13 +25,17 @@ log = get_logger(basename(__file__))
 
 MIN_SINGULARITY_VERSION = "3.3"
 
+def check_singularity_version():  # pragma: no cover
+    if not is_singularity_version_greater(MIN_SINGULARITY_VERSION):
+        log.error("Singularity version lower than %s" %
+                  MIN_SINGULARITY_VERSION)
+        raise OSError("Singularity version below %s" % MIN_SINGULARITY_VERSION)
 
 def is_singularity_version_greater(min_version):  # pragma: no cover
     singularity_version = LooseVersion(get_singularity_version().split()[-1])
     retval = singularity_version > LooseVersion(MIN_SINGULARITY_VERSION)
     return retval
 
-
 def build_image(output_dir):
     if not isdir(output_dir):
         raise OSError("Directory not found!")
-- 
GitLab