-
Notifications
You must be signed in to change notification settings - Fork 90
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
Allow stepped integer parameters. #2240
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ | |
from cylc.network import PRIVILEGE_LEVELS | ||
|
||
|
||
REC_PARAM_INT_RANGE = re.compile('(\d+)\.\.(\d+)') | ||
REC_PARAM_INT_RANGE = re.compile('(\d+)\.\.(\d+)(\^(\d+))?') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose you can do: REC_PARAM_INT_RANGE = re.compile('(\d+)\.\.(\d+)(?:\^(\d+))?') to avoid capturing the 3rd bracket? |
||
|
||
|
||
def _coerce_cycleinterval(value, keys, _): | ||
|
@@ -141,19 +141,19 @@ def _coerce_final_cycletime(value, keys, _): | |
def _coerce_parameter_list(value, keys, _): | ||
"""Coerce parameter list.""" | ||
value = _strip_and_unquote_list(keys, value) | ||
if len(value) == 1: | ||
# May be a range e.g. '1..5' (bounds inclusive) | ||
try: | ||
lower, upper = REC_PARAM_INT_RANGE.match(value[0]).groups() | ||
except AttributeError: | ||
if '.' in value[0]: | ||
# Dot is illegal in node names, probably bad range syntax. | ||
raise IllegalValueError("parameter", keys, value) | ||
else: | ||
n_dig = len(upper) | ||
return [ | ||
str(i).zfill(n_dig) for i in range(int(lower), int(upper) + 1)] | ||
return value | ||
# May be an integer range with step e.g. '1..6^2' (bounds inclusive). | ||
try: | ||
lower, upper, junk, step = REC_PARAM_INT_RANGE.match(value[0]).groups() | ||
step = step or 1 | ||
except AttributeError: | ||
if '.' in value[0]: | ||
# Dot is illegal in node names, probably bad range syntax. | ||
raise IllegalValueError("parameter", keys, value) | ||
return value | ||
else: | ||
n_dig = len(upper) | ||
return [str(i).zfill(n_dig) for i in | ||
range(int(lower), int(upper) + 1, int(step))] | ||
|
||
coercers['cycletime'] = _coerce_cycletime | ||
coercers['cycletime_format'] = _coerce_cycletime_format | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
# THIS FILE IS PART OF THE CYLC SUITE ENGINE. | ||
# Copyright (C) 2008-2017 NIWA | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
#------------------------------------------------------------------------------- | ||
# check tasks and graph generated by parameter expansion. | ||
. $(dirname $0)/test_header | ||
#------------------------------------------------------------------------------- | ||
set_test_number 2 | ||
#------------------------------------------------------------------------------- | ||
install_suite $TEST_NAME_BASE $TEST_NAME_BASE | ||
#------------------------------------------------------------------------------- | ||
TEST_NAME=$TEST_NAME_BASE-validate | ||
run_ok $TEST_NAME cylc validate "${SUITE_NAME}" | ||
#------------------------------------------------------------------------------- | ||
cylc graph --reference $SUITE_NAME > new.graph.ref | ||
cmp_ok new.graph.ref $TEST_SOURCE_DIR/$TEST_NAME_BASE/graph.ref | ||
#------------------------------------------------------------------------------- | ||
purge_suite $SUITE_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
edge "foo_cat.1" "bar_j1.1" solid | ||
edge "foo_cat.1" "bar_j2.1" solid | ||
edge "foo_cat.1" "bar_j3.1" solid | ||
edge "foo_cat.1" "bar_j4.1" solid | ||
edge "foo_cat.1" "bar_j5.1" solid | ||
edge "foo_dog.1" "bar_j1.1" solid | ||
edge "foo_dog.1" "bar_j2.1" solid | ||
edge "foo_dog.1" "bar_j3.1" solid | ||
edge "foo_dog.1" "bar_j4.1" solid | ||
edge "foo_dog.1" "bar_j5.1" solid | ||
edge "foo_fish.1" "bar_j1.1" solid | ||
edge "foo_fish.1" "bar_j2.1" solid | ||
edge "foo_fish.1" "bar_j3.1" solid | ||
edge "foo_fish.1" "bar_j4.1" solid | ||
edge "foo_fish.1" "bar_j5.1" solid | ||
edge "qux_j1.1" "waz_k01.1" solid | ||
edge "qux_j1.1" "waz_k05.1" solid | ||
edge "qux_j1.1" "waz_k09.1" solid | ||
edge "qux_j2.1" "waz_k01.1" solid | ||
edge "qux_j2.1" "waz_k05.1" solid | ||
edge "qux_j2.1" "waz_k09.1" solid | ||
edge "qux_j3.1" "waz_k01.1" solid | ||
edge "qux_j3.1" "waz_k05.1" solid | ||
edge "qux_j3.1" "waz_k09.1" solid | ||
edge "qux_j4.1" "waz_k01.1" solid | ||
edge "qux_j4.1" "waz_k05.1" solid | ||
edge "qux_j4.1" "waz_k09.1" solid | ||
edge "qux_j5.1" "waz_k01.1" solid | ||
edge "qux_j5.1" "waz_k05.1" solid | ||
edge "qux_j5.1" "waz_k09.1" solid | ||
graph | ||
node "bar_j1.1" "bar_j1\n1" unfilled box black | ||
node "bar_j2.1" "bar_j2\n1" unfilled box black | ||
node "bar_j3.1" "bar_j3\n1" unfilled box black | ||
node "bar_j4.1" "bar_j4\n1" unfilled box black | ||
node "bar_j5.1" "bar_j5\n1" unfilled box black | ||
node "foo_cat.1" "foo_cat\n1" unfilled box black | ||
node "foo_dog.1" "foo_dog\n1" unfilled box black | ||
node "foo_fish.1" "foo_fish\n1" unfilled box black | ||
node "qux_j1.1" "qux_j1\n1" unfilled box black | ||
node "qux_j2.1" "qux_j2\n1" unfilled box black | ||
node "qux_j3.1" "qux_j3\n1" unfilled box black | ||
node "qux_j4.1" "qux_j4\n1" unfilled box black | ||
node "qux_j5.1" "qux_j5\n1" unfilled box black | ||
node "waz_k01.1" "waz_k01\n1" unfilled box black | ||
node "waz_k05.1" "waz_k05\n1" unfilled box black | ||
node "waz_k09.1" "waz_k09\n1" unfilled box black | ||
stop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[cylc] | ||
[[parameters]] | ||
i = cat, dog, fish | ||
j = 1..5 | ||
k = 1..10^4 | ||
[scheduling] | ||
[[dependencies]] | ||
graph = """ | ||
foo<i> => bar<j> | ||
qux<j> => waz<k> | ||
""" | ||
[runtime] | ||
[[root]] | ||
script = true | ||
[[foo<i>]] | ||
[[bar<j>]] | ||
[[qux<j>]] | ||
[[waz<k>]] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As a matter of interest, did you borrow this syntax from any language? (In both Perl and Python, the
^
operator appears to be the bitwise XOR operator.)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.
Nope, thought that might be a point of contention. We can't use comma, obviously.
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.
In fact, the
^
operator appears to be the bitwise XOR operator in most languages derived from C. The only other thing I can think of is to use..
again in a ternary way,START..END[..STEP]
, e.g.1..9..2
.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 think @matthewrmshin's solution makes sense as it's in line with what you'd expect from something like python's
range(start, end, step=1)
function.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... IMO
..
is intuitive syntax for a range, but ideally we'd have something else for step. What about1..9;2
?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.
Or how about 1:9:2?
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.
Yeah, I could go for the colon.
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
..
operator is a well known operator in various languages including Perl and Ruby, but none of them have thought about steps.I don't like
:
or;
for the same reason as^
- both are well known operators that mean something else.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.
1..9..2
mimics bash,1:9:2
is python slice style...I like either. Making up our own seems confusing possibly?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.
+1 for
START..END..STEP
. In python's slice syntax the end-point is excluded i.e.1:9:2 = 1, 3, 5, 7
, whereas in bash this is inclusive i.e.1..9..2 = 1, 3, 5, 7, 9
.