Skip to content
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

Merged
merged 6 commits into from
Jun 1, 2017

Conversation

challurip
Copy link
Contributor

@challurip challurip commented May 26, 2017

Parameterized task environment "CYLC_TASK_PARAM_task" is now available in suite envionments.

Close #2225

@hjoliver hjoliver self-requested a review May 26, 2017 01:57
@@ -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 = {}
Copy link
Member

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.

new_environ[p_var_name] = p_val
new_param = OrderedDictWithDefaults()
new_param[p_var_name] = p_val
self.task_param[name] = new_param
Copy link
Member

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, ...}

@@ -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])
Copy link
Member

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.

if job_conf['param_var']:
for var, val in job_conf['param_var'].items():
value = str(val) # (needed?)
match = re.match(r"^(~[^/\s]*/)(.*)$", value)
Copy link
Member

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).

handle.write(
'\n export %s=%s"%s"' %
(var, head, tail))
elif re.match(r"^~[^\s]*$", value):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and here)

@@ -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 = []
Copy link
Member

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.

@matthewrmshin matthewrmshin added this to the next release milestone May 26, 2017
@@ -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():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much indent here.

@@ -31,6 +31,9 @@ class JobFileWriter(object):

"""Write task job files."""

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

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...)

# 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))
Copy link
Member

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}"
Copy link
Member

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 using cylc 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).

@hjoliver
Copy link
Member

Looks good - @matthewrmshin please review or reassign.

Copy link
Contributor

@matthewrmshin matthewrmshin left a 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.

@@ -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?)
Copy link
Contributor

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.

@@ -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,
Copy link
Contributor

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.

@matthewrmshin matthewrmshin merged commit f76e864 into cylc:master Jun 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants