-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameterized task environment moved to suite environments #2308
Conversation
b5a9e4f
to
c9f5308
Compare
lib/cylc/config.py
Outdated
@@ -155,6 +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 = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a more descriptive name, e.g. task_param_vars
.
lib/cylc/config.py
Outdated
new_environ[p_var_name] = p_val | ||
new_param = OrderedDictWithDefaults() | ||
new_param[p_var_name] = p_val | ||
self.task_param[name] = new_param |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed the branch doesn't work properly with multiple parameters, e.g. foo<m,n>
.
- new_param doesn't need to be ordered dict, a plain dict will do
{}
- new_param should be defined outside the loop, we need to store `task_param_vars[task-name] = {p_var_name_1: p_val_1, p_var_name_2:p_val_2, ...}
lib/cylc/config.py
Outdated
@@ -2025,6 +2027,9 @@ 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]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for copy()
here.
lib/cylc/job_file.py
Outdated
if job_conf['param_var']: | ||
for var, val in job_conf['param_var'].items(): | ||
value = str(val) # (needed?) | ||
match = re.match(r"^(~[^/\s]*/)(.*)$", value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inside a loop - we should use compiled regexes here (use re.compile()
at class or module level).
lib/cylc/job_file.py
Outdated
handle.write( | ||
'\n export %s=%s"%s"' % | ||
(var, head, tail)) | ||
elif re.match(r"^~[^\s]*$", value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and here)
lib/cylc/taskdef.py
Outdated
@@ -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 = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is a dict, not a list.
18a43f7
to
f30d341
Compare
lib/cylc/job_file.py
Outdated
@@ -206,6 +209,28 @@ def _write_environment_1(self, handle, job_conf): | |||
' '.join(job_conf['namespace_hierarchy'])) | |||
handle.write( | |||
'\n export CYLC_TASK_TRY_NUMBER=%s' % job_conf['try_num']) | |||
if job_conf['param_var']: | |||
for var, val in job_conf['param_var'].items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too much indent here.
lib/cylc/job_file.py
Outdated
@@ -31,6 +31,9 @@ class JobFileWriter(object): | |||
|
|||
"""Write task job files.""" | |||
|
|||
env_match1 = re.compile(r"^(~[^/\s]*/)(.*)$") | |||
env_match2 = re.compile(r"^~[^\s]*$") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We capitalize constants like this, by convention - however, we don't need them at all in this case (see subsequent comments...)
lib/cylc/job_file.py
Outdated
# This gets values like "~one ~two" too, but these | ||
# (in variable values) aren't expanded by the shell | ||
# anyway so it doesn't matter. | ||
handle.write('\n export %s="%s"' % (var, value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@challurip - sorry, I didn't look closely enough first time through, but: (1) this is now the same code as in _write_environment_1()
- where you cut-and-pasted it from - so it should be factored out into a function rather than repeated. However, don't bother doing that because: (2) in fact we don't most of this code at all for parameter variables - Unix file path ~
characters (as per the comments) can appear in general user-defined variables, but not in parameter values which are only simple strings or integers. i.e. we only need the final simple case - the content under else:
.
PARAM2 = \$CYLC_TASK_PARAM_u | ||
__END__ | ||
|
||
purge_suite "${SUITE_NAME}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It occurs to me this test correctly determines that the parameter values are no longer set in the user-defined task environment, but it doesn't test that they are correctly set in the suite-defined task environment. Can you try adding several more tests to this test script:
- generate a job script via
run_ok
usingcylc jobscript ${SUITE_NAME} foo_t1_right.1
- then use
grep_ok
to check that$CYLC_TASK_PARAM_t
and..._u
are correctly defined in it.
(An alternative would be to run a test suite in which the task foo_t1_right uses its parameter variables at run time - however, checking the job script will do in this case).
Looks good - @matthewrmshin please review or reassign. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK apart from 2 minor style issues.
lib/cylc/job_file.py
Outdated
@@ -206,6 +206,10 @@ def _write_environment_1(self, handle, job_conf): | |||
' '.join(job_conf['namespace_hierarchy'])) | |||
handle.write( | |||
'\n export CYLC_TASK_TRY_NUMBER=%s' % job_conf['try_num']) | |||
if job_conf['param_var']: | |||
for var, val in job_conf['param_var'].items(): | |||
value = str(val) # (needed?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be needed. The template will do the essential string conversion.
lib/cylc/task_job_mgr.py
Outdated
@@ -949,4 +948,5 @@ def _prep_submit_task_job_impl(self, suite, itask): | |||
'task_id': itask.identity, | |||
'try_num': itask.get_try_num(), | |||
'work_d': rtconfig['work sub-directory'], | |||
'param_var': itask.tdef.param_var, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The keys were sorted alphabetically. Please insert param_var
in the right place.
…t not in task environment
d4f5fe9
to
bd4934b
Compare
Parameterized task environment "CYLC_TASK_PARAM_task" is now available in suite envionments.
Close #2225