From fd5dafaad07b84d2055947183c05deab8c34ddbb Mon Sep 17 00:00:00 2001
From: Thomas Kluyver <thomas.kluyver@xfel.eu>
Date: Thu, 16 May 2024 09:27:55 +0100
Subject: [PATCH] Remove unnecessary 'module load' command from jobs to be
 repeated

---
 src/xfel_calibrate/repeat.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/xfel_calibrate/repeat.py b/src/xfel_calibrate/repeat.py
index 3112a960f..e9939b5d3 100644
--- a/src/xfel_calibrate/repeat.py
+++ b/src/xfel_calibrate/repeat.py
@@ -95,6 +95,20 @@ def munge_requirements(reqs: str):
     return '\n'.join(reqs)
 
 
+def script_fix(cal_work_dir: Path):
+    # Workaround: until May 2024, this script contained a leftover & unnecessary
+    # 'module load anaconda/3' command. This module is not available on EL9.
+    # We don't use the module at all, so we can safely cut the command out.
+    script = cal_work_dir / "pycalib-run-nb.sh"
+    if not script.is_file():
+        return
+
+    lines = script.read_text().splitlines(keepends=True)
+    script.write_text(''.join(
+        l for l in lines if l.strip().split() != ['module', 'load', 'anaconda/3']
+    ))
+
+
 def main(argv=None):
     ap = argparse.ArgumentParser()
     ap.add_argument("from_dir", type=Path, help="A directory containing steps.json")
@@ -143,6 +157,8 @@ def main(argv=None):
     )
     print(f"New working directory: {cal_work_dir}")
 
+    script_fix(cal_work_dir)  # Strip out 'module load anaconda/3'
+
     # Update metadata YAML file & notebooks with any changes
     cal_metadata = CalibrationMetadata(cal_work_dir)
     cal_metadata['calibration-configurations'] = parameters
-- 
GitLab