From 16a6ad54dc4be1142e8c555977902941e4c58b12 Mon Sep 17 00:00:00 2001 From: Karl-Hermann Wieners <karl-hermann.wieners@mpimet.mpg.de> Date: Mon, 22 Jul 2024 14:54:42 +0200 Subject: [PATCH] Templates: load user template also if user dir is not in mkexp path --- CHANGES.rst | 8 ++++++++ mkexp | 11 +++++++++-- test.py | 9 +++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index df724e3..a56197f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,14 @@ Make Experiments! Release Changes --------------- +Release 1.4.1 +============= + +Templates +--------- + +* Load user template also if user dir is not in mkexp path + Release 1.4.0 ============= diff --git a/mkexp b/mkexp index 69a45ef..b130c86 100755 --- a/mkexp +++ b/mkexp @@ -286,11 +286,15 @@ if args.path: config_roots = args.path.split(':') experiment_config_name = args.config -experiment_config_id = os.path.splitext(os.path.basename(args.config))[0] if not os.path.exists(experiment_config_name): feedback.die("config file '{0}' does not exist".format(experiment_config_name)) +(experiment_config_dir, + experiment_config_base) = os.path.split(experiment_config_name) +(experiment_config_id, + experiment_config_format) = os.path.splitext(experiment_config_base) + # Overrides invalid_args = [x for x in args.assigns if not x.find('=')+1] @@ -300,8 +304,11 @@ if invalid_args: # Setup templating environment +template_roots = config_roots +if experiment_config_dir not in template_roots: + template_roots.append(experiment_config_dir) template_env = Environment( - loader = ChoiceLoader(list(map(FileSystemLoader, config_roots))), + loader = ChoiceLoader(list(map(FileSystemLoader, template_roots))), variable_start_string = '%{', variable_end_string = '}', line_statement_prefix = '#%', diff --git a/test.py b/test.py index bb47039..81c8f46 100644 --- a/test.py +++ b/test.py @@ -160,6 +160,15 @@ class RunningTestCase(MkexpTestCase): self.assertTrue(is_exec('test/experiments/test0001/test0001.run')) self.assertFalse(is_exec('test/experiments/test0001/test0001.nox')) + def test_template_not_in_path(self): + expected = align(u""" + Script directory: 'experiments/test0001' + Data directory: 'experiments/test0001' (already exists) + Work directory: 'experiments/test0001' (already exists) + """) + result = output(script("mkexp -p does_not_exist test0001.config")) + self.assertMultiLineEqual(expected, result) + class CommandLineTestCase(MkexpTestCase): def test_pass_section_variables(self): -- GitLab