From 509168571ef9bc71bb73e2272085646ec0ffed0c Mon Sep 17 00:00:00 2001
From: Karl-Hermann Wieners <karl-hermann.wieners@mpimet.mpg.de>
Date: Mon, 8 Jul 2024 17:01:27 +0200
Subject: [PATCH] mkexp: add list of removed jobs to template namespace

---
 CHANGES.rst |  1 +
 mkexp       |  1 +
 test.py     | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/CHANGES.rst b/CHANGES.rst
index 308523c..df724e3 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -18,6 +18,7 @@ Config
 ------
 
 * Add option to allow scripts to be non-executable
+* Add list of removed jobs to template namespace
 
 Tools
 -----
diff --git a/mkexp b/mkexp
index 42b078c..ad1067a 100755
--- a/mkexp
+++ b/mkexp
@@ -572,6 +572,7 @@ for subjob, subconfig in jobs_config.items():
         var_format = job_config['JOB'].get('.var_format', '${%s}')
         var_list = set()
         job_config['jobs'] = {}
+        job_config['jobs']['.remove'] = (remove_list[1:] if remove_list else [])
         job_config['jobs'].merge(expconfig.odict(jobs_config))
         expconfig.merge_comments(job_config['jobs'], jobs_config)
         job_config.walk(format_vars, log=var_list, fmt=var_format)
diff --git a/test.py b/test.py
index e7ac5cf..bb47039 100644
--- a/test.py
+++ b/test.py
@@ -1723,6 +1723,38 @@ class JobSiblingsTestCase(MkexpSimpleTestCase):
         result = align(result)
         self.assertMultiLineEqual(expected, result)
 
+class DisabledJobsTestCase(MkexpSimpleTestCase):
+
+    def test_removed_job_in_template(self):
+        writeconfig(self.exp_id, u"""
+            [jobs]
+              .remove = job1
+              [[job1]]
+              [[job2]]
+        """)
+        writetemplate(self.exp_id, 'job2', u"""
+            #% for job in jobs.sections:
+            %{job}
+            #% endfor
+            ---
+            #% for job in jobs.sections:
+            #%   if job is not in jobs['.remove']:
+            %{job}
+            #%   endif
+            #% endfor
+        """)
+        expected = align(u"""
+            job1
+            job2
+            ---
+            job2
+        """)
+        ignore = output(script("mkexp "+self.exp_id+".config"))
+        result = readfile(join("test", "experiments", self.exp_id,
+                               self.exp_id+".job2"))
+        result = align(result)
+        self.assertMultiLineEqual(expected, result)
+
 class NativeVariableTestCase(MkexpSimpleTestCase):
 
     def test_var_statement(self):
-- 
GitLab