-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into centralised-reg-parse
- Loading branch information
Showing
11 changed files
with
186 additions
and
20 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. | ||
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. | ||
# | ||
# 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/>. | ||
|
||
from contextlib import suppress | ||
from functools import partial | ||
import re | ||
from typing import List, Any | ||
|
||
|
||
_NAT_SORT_SPLIT = re.compile(r'([\d\.]+)') | ||
|
||
|
||
def natural_sort_key(key: str, fcns=(int, str)) -> List[Any]: | ||
"""Returns a key suitable for sorting. | ||
Splits the key into sortable chunks to preserve numerical order. | ||
Examples: | ||
>>> natural_sort_key('a1b2c3') | ||
['a', 1, 'b', 2, 'c', 3] | ||
>>> natural_sort_key('a123b') | ||
['a', 123, 'b'] | ||
>>> natural_sort_key('a1.23b', fcns=(float, str)) | ||
['a', 1.23, 'b'] | ||
>>> natural_sort_key('a.b') | ||
['a', '.', 'b'] | ||
""" | ||
ret = [] | ||
for item in _NAT_SORT_SPLIT.split(key): | ||
for fcn in fcns: | ||
with suppress(TypeError, ValueError): | ||
ret.append(fcn(item)) | ||
break | ||
if ret[-1] == '': | ||
ret.pop(-1) | ||
return ret | ||
|
||
|
||
def natural_sort(items: List[str], fcns=(int, str)) -> None: | ||
"""Sorts a list preserving numerical order. | ||
Note this is an in-place sort. | ||
Examples: | ||
>>> lst = ['a10', 'a1', 'a2'] | ||
>>> natural_sort(lst) | ||
>>> lst | ||
['a1', 'a2', 'a10'] | ||
>>> lst = ['a1', '1a'] | ||
>>> natural_sort(lst) | ||
>>> lst | ||
['1a', 'a1'] | ||
""" | ||
items.sort(key=partial(natural_sort_key, fcns=fcns)) |
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,47 @@ | ||
#!/usr/bin/env bash | ||
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. | ||
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. | ||
# | ||
# 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/>. | ||
#------------------------------------------------------------------------------- | ||
# Test log dev-mode. | ||
|
||
. "$(dirname "$0")/test_header" | ||
set_test_number 5 | ||
init_workflow "${TEST_NAME_BASE}" <<'__FLOW_CONFIG__' | ||
[scheduling] | ||
cycling mode = integer | ||
initial cycle point = 1 | ||
final cycle point = 1 | ||
[[graph]] | ||
P1 = t1 | ||
[runtime] | ||
[[t1]] | ||
script = true | ||
__FLOW_CONFIG__ | ||
|
||
run_ok "${TEST_NAME_BASE}-validate-plain" \ | ||
cylc validate "${WORKFLOW_NAME}" | ||
|
||
run_ok "${TEST_NAME_BASE}-validate-vvv" \ | ||
cylc validate -vvv "${WORKFLOW_NAME}" | ||
grep_ok " DEBUG - \[config:.*\]" "${TEST_NAME_BASE}-validate-vvv.stderr" | ||
|
||
|
||
run_ok "${TEST_NAME_BASE}-validate-vvv--no-timestamp" \ | ||
cylc validate -vvv --no-timestamp "${WORKFLOW_NAME}" | ||
grep_ok "^DEBUG - \[config:.*\]" "${TEST_NAME_BASE}-validate-vvv--no-timestamp.stderr" | ||
|
||
purge | ||
exit |
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