Skip to content

Commit

Permalink
Modified code to support multiple parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
challurip committed May 29, 2017
1 parent ff7adee commit f30d341
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
11 changes: 5 additions & 6 deletions lib/cylc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def __init__(self, suite, fpath, template_vars=None,
self.actual_first_point = None
self._start_point_for_actual_first_point = None

self.task_param = {}
self.task_param_vars = {}
self.custom_runahead_limit = None
self.max_num_active_cycle_points = None

Expand Down Expand Up @@ -780,11 +780,10 @@ def _expand_runtime(self):
replicate(newruntime[name], namespace_dict)
if indices:
new_environ = OrderedDictWithDefaults()
self.task_param_vars[name] = {}
for p_name, p_val in indices.items():
p_var_name = 'CYLC_TASK_PARAM_%s' % p_name
new_param = OrderedDictWithDefaults()
new_param[p_var_name] = p_val
self.task_param[name] = new_param
self.task_param_vars[name][p_var_name] = p_val
if 'environment' in newruntime[name]:
for k, v in newruntime[name]['environment'].items():
new_environ[k] = v
Expand Down Expand Up @@ -2027,8 +2026,8 @@ def _get_taskdef(self, name):
foo.reverse()
taskd.namespace_hierarchy = foo

if name in self.task_param:
taskd.param_var = copy(self.task_param[name])
if name in self.task_param_vars:
taskd.param_var = self.task_param_vars[name]

return taskd

Expand Down
11 changes: 7 additions & 4 deletions lib/cylc/job_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class JobFileWriter(object):

"""Write task job files."""

env_match1 = re.compile(r"^(~[^/\s]*/)(.*)$")
env_match2 = re.compile(r"^~[^\s]*$")

def __init__(self):
self.suite_env = {}
self.batch_sys_mgr = BatchSysManager()
Expand Down Expand Up @@ -209,15 +212,15 @@ def _write_environment_1(self, handle, job_conf):
if job_conf['param_var']:
for var, val in job_conf['param_var'].items():
value = str(val) # (needed?)
match = re.match(r"^(~[^/\s]*/)(.*)$", value)
match = self.env_match1.match(value)
if match:
# ~foo/bar or ~/bar
# write as ~foo/"bar" or ~/"bar"
head, tail = match.groups()
handle.write(
'\n export %s=%s"%s"' %
(var, head, tail))
elif re.match(r"^~[^\s]*$", value):
elif self.env_match2.match(value):
# plain ~foo or just ~
# just leave unquoted as subsequent spaces don't
# make sense in this case anyway
Expand Down Expand Up @@ -254,13 +257,13 @@ def _write_environment_2(self, handle, job_conf):
handle.write("\n # TASK RUNTIME ENVIRONMENT:")
for var, val in job_conf['environment'].items():
value = str(val) # (needed?)
match = re.match(r"^(~[^/\s]*/)(.*)$", value)
match = self.env_match1.match(value)
if match:
# ~foo/bar or ~/bar
# write as ~foo/"bar" or ~/"bar"
head, tail = match.groups()
handle.write('\n %s=%s"%s"' % (var, head, tail))
elif re.match(r"^~[^\s]*$", value):
elif self.env_match2.match(value):
# plain ~foo or just ~
# just leave unquoted as subsequent spaces don't
# make sense in this case anyway
Expand Down
2 changes: 1 addition & 1 deletion lib/cylc/taskdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(self, name, rtcfg, run_mode, start_point, spawn_ahead):
self.namespace_hierarchy = []
self.dependencies = {}
self.outputs = []
self.param_var = []
self.param_var = {}
self.external_triggers = []

self.name = name
Expand Down
5 changes: 3 additions & 2 deletions tests/cylc-get-config/05-param-vars.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ install_suite "${TEST_NAME_BASE}" "${TEST_NAME_BASE}"

TEST_NAME="${TEST_NAME_BASE}-config"
run_ok "${TEST_NAME}" \
cylc get-config -i "[runtime][foo_t1]environment" "${SUITE_NAME}"
cylc get-config -i "[runtime][foo_t1_right]environment" "${SUITE_NAME}"
cmp_ok "${TEST_NAME}.stdout" - <<__END__
PARAM = \$CYLC_TASK_PARAM_t
PARAM1 = \$CYLC_TASK_PARAM_t
PARAM2 = \$CYLC_TASK_PARAM_u
__END__

purge_suite "${SUITE_NAME}"
10 changes: 6 additions & 4 deletions tests/cylc-get-config/05-param-vars/suite.rc
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
[cylc]
[[parameters]]
t = 1..5
u = right,left
[scheduling]
[[dependencies]]
graph = foo<t>
graph = foo<t,u>
[runtime]
[[root]]
script = sleep 1
[[[environment]]]
PARAM = 'something'
[[foo<t>]]
PARAM1 = 'something'
[[foo<t,u>]]
[[[environment]]]
PARAM = $CYLC_TASK_PARAM_t
PARAM1 = $CYLC_TASK_PARAM_t
PARAM2 = $CYLC_TASK_PARAM_u

0 comments on commit f30d341

Please sign in to comment.