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

Cycle point dump format 78x #3603

Merged
merged 4 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ cylc-7.9.x (which requires Python 2.7) bundles Jinja2 2.11.
cylc-8 (master branch, Python 3 - not yet released) uses proper Python package
management and does not bundle Jinja2.


[#3603](https://github.com/cylc/cylc-flow/pull/3603) - Fix a bug that prevented
cycle point format conversion by the `cylc suite-state` command and the
`suite_state` xtrigger function, if the target suite used the default format
but downstream command or suite did not.

-------------------------------------------------------------------------------
## __cylc-7.8.5 (2020-04-22)__

Expand Down
8 changes: 5 additions & 3 deletions lib/cylc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from cylc.cycling.loader import (
get_point, get_point_relative, get_interval, get_interval_cls,
get_sequence, get_sequence_cls, init_cyclers, INTEGER_CYCLING_TYPE,
ISO8601_CYCLING_TYPE)
ISO8601_CYCLING_TYPE, get_dump_format)
from cylc.cycling import IntervalParsingError
from cylc.cycling.iso8601 import ingest_time
import cylc.flags
Expand Down Expand Up @@ -353,6 +353,8 @@ def __init__(

# after the call to init_cyclers, we can start getting proper points.
init_cyclers(self.cfg)
self.cycling_type = get_interval_cls().get_null().TYPE
self.cycle_point_dump_format = get_dump_format(self.cycling_type)

# Running in UTC time? (else just use the system clock)
if self.cfg['cylc']['UTC mode'] is None:
Expand Down Expand Up @@ -413,7 +415,7 @@ def __init__(
fcp_str = self.cfg['scheduling']['final cycle point']
if fcp_str is not None:
# Is the final "point"(/interval) relative to initial?
if get_interval_cls().get_null().TYPE == INTEGER_CYCLING_TYPE:
if self.cycling_type == INTEGER_CYCLING_TYPE:
if "P" in fcp_str:
# Relative, integer cycling.
self.final_point = get_point_relative(
Expand Down Expand Up @@ -1115,7 +1117,7 @@ def compute_runahead_limits(self):
if not limit:
limit = None
if (limit is not None and limit.isdigit() and
get_interval_cls().get_null().TYPE == ISO8601_CYCLING_TYPE):
self.cycling_type == ISO8601_CYCLING_TYPE):
# Backwards-compatibility for raw number of hours.
limit = "PT%sH" % limit

Expand Down
6 changes: 6 additions & 0 deletions lib/cylc/cycling/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,12 @@ def init_from_cfg(_):
pass


def get_dump_format(cycling_type=None):
"""Return cycle point string dump format."""
# Not used for integer cycling.
return None


def get_point_relative(point_expr, context_point):
"""Create a point from relative_string applied to base_point."""
if REC_RELATIVE_POINT.search(point_expr):
Expand Down
5 changes: 5 additions & 0 deletions lib/cylc/cycling/iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,11 @@ def init(num_expanded_year_digits=0, custom_dump_format=None, time_zone=None,
)


def get_dump_format():
"""Return cycle point string dump format."""
return SuiteSpecifics.DUMP_FORMAT


def get_point_relative(offset_string, base_point):
"""Create a point from offset_string applied to base_point."""
try:
Expand Down
8 changes: 8 additions & 0 deletions lib/cylc/cycling/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
POINTS = {INTEGER_CYCLING_TYPE: integer.IntegerPoint,
ISO8601_CYCLING_TYPE: iso8601.ISO8601Point}

DUMP_FORMAT_GETTERS = {INTEGER_CYCLING_TYPE: integer.get_dump_format,
ISO8601_CYCLING_TYPE: iso8601.get_dump_format}

POINT_RELATIVE_GETTERS = {
INTEGER_CYCLING_TYPE: integer.get_point_relative,
ISO8601_CYCLING_TYPE: iso8601.get_point_relative
Expand Down Expand Up @@ -75,6 +78,11 @@ def get_point_cls(cycling_type=None):
return POINTS[cycling_type]


def get_dump_format(cycling_type=None):
"""Return cycle point string dump format, or None."""
return DUMP_FORMAT_GETTERS[cycling_type]()


def get_point_relative(*args, **kwargs):
"""Return a point from an offset expression and a base point."""
cycling_type = kwargs.pop("cycling_type", DefaultCycler.TYPE)
Expand Down
4 changes: 2 additions & 2 deletions lib/cylc/suite_db_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ def put_suite_params(self, schd):
{"key": "cylc_version", "value": CYLC_VERSION},
{"key": "UTC_mode", "value": get_utc_mode()},
])
if schd.config.cfg['cylc']['cycle point format']:
if schd.config.cycle_point_dump_format is not None:
self.db_inserts_map[self.TABLE_SUITE_PARAMS].append({
"key": "cycle_point_format",
"value": schd.config.cfg['cylc']['cycle point format']})
"value": schd.config.cycle_point_dump_format})
if schd.pool.is_held:
self.db_inserts_map[self.TABLE_SUITE_PARAMS].append({
"key": "is_held", "value": 1})
Expand Down
1 change: 1 addition & 0 deletions tests/restart/15-state-to-db.t
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ run_ok "${TEST_NAME_BASE}-suite_params" \
'SELECT key,value FROM suite_params WHERE key != "uuid_str" ORDER BY key'
cmp_ok "${TEST_NAME_BASE}-suite_params.stdout" <<__OUT__
UTC_mode|1
cycle_point_format|CCYYMMDDThhmmZ
cylc_version|$(cylc version)
fcp|20050101T0000Z
icp|20000101T0000Z
Expand Down
43 changes: 28 additions & 15 deletions tests/suite-state/06-format.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# THIS FILE IS PART OF THE CYLC SUITE ENGINE.
# Copyright (C) 2008-2019 NIWA & British Crown (Met Office) & Contributors.
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
#
hjoliver marked this conversation as resolved.
Show resolved Hide resolved
# 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
Expand All @@ -15,29 +15,42 @@
# 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 cylc suite-state "template" option
. $(dirname $0)/test_header
# Test "cylc suite-state" cycle point format conversion, when the target suite
# sets an explicit cycle point format, and the CLI does not.
. "$(dirname "$0")/test_header"
#-------------------------------------------------------------------------------
set_test_number 5
#-------------------------------------------------------------------------------
install_suite $TEST_NAME_BASE format
#-------------------------------------------------------------------------------
TEST_NAME=$TEST_NAME_BASE-run
suite_run_ok $TEST_NAME cylc run --debug --no-detach $SUITE_NAME
#-------------------------------------------------------------------------------
TEST_NAME=$TEST_NAME_BASE-cli-template-poll
run_ok $TEST_NAME cylc suite-state $SUITE_NAME -p 20100101T0000Z \
init_suite "${TEST_NAME_BASE}" <<'__SUITERC__'
[cylc]
UTC mode = True
cycle point format = CCYY-MM-DD
[scheduling]
initial cycle point = 20100101
[[dependencies]]
[[[R1]]]
graph = foo
[runtime]
[[foo]]
script = true
__SUITERC__
#-------------------------------------------------------------------------------
TEST_NAME="${TEST_NAME_BASE}-run"
suite_run_ok "${TEST_NAME}" cylc run --debug --no-detach "${SUITE_NAME}"
#-------------------------------------------------------------------------------
TEST_NAME=${TEST_NAME_BASE}-cli-poll
run_ok "${TEST_NAME}" cylc suite-state "${SUITE_NAME}" -p 20100101T0000Z \
--task=foo --status=succeeded
contains_ok $TEST_NAME.stdout <<__OUT__
contains_ok "${TEST_NAME}.stdout" <<__OUT__
polling for 'succeeded': satisfied
__OUT__
#-------------------------------------------------------------------------------
TEST_NAME=$TEST_NAME_BASE-cli-template-dump
run_ok $TEST_NAME cylc suite-state $SUITE_NAME -p 20100101T0000Z
contains_ok $TEST_NAME.stdout <<__OUT__
TEST_NAME=${TEST_NAME_BASE}-cli-dump
run_ok "${TEST_NAME}" cylc suite-state "${SUITE_NAME}" -p 20100101T0000Z
contains_ok "${TEST_NAME}.stdout" <<__OUT__
foo, 2010-01-01, succeeded
__OUT__
#-------------------------------------------------------------------------------
purge_suite $SUITE_NAME
purge_suite "${SUITE_NAME}"
#-------------------------------------------------------------------------------
exit 0
57 changes: 57 additions & 0 deletions tests/suite-state/06a-noformat.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
# THIS FILE IS PART OF THE CYLC SUITE 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 "cylc suite-state" cycle point format conversion, when the target suite
# sets no explicit cycle point format, and the CLI does (the reverse of 06.t).

. "$(dirname "$0")/test_header"
#-------------------------------------------------------------------------------
set_test_number 5
#-------------------------------------------------------------------------------
init_suite "${TEST_NAME_BASE}" <<'__SUITERC__'
[cylc]
UTC mode = True
# (Use default cycle point format)
[scheduling]
initial cycle point = 20100101T0000Z
[[dependencies]]
[[[R1]]]
graph = foo
[runtime]
[[foo]]
script = true
__SUITERC__
#-------------------------------------------------------------------------------
TEST_NAME="${TEST_NAME_BASE}-run"
suite_run_ok "${TEST_NAME}" cylc run --debug --no-detach "${SUITE_NAME}"
#-------------------------------------------------------------------------------
TEST_NAME=${TEST_NAME_BASE}-cli-poll
run_ok "${TEST_NAME}" cylc suite-state "${SUITE_NAME}" -p 2010-01-01T00:00Z \
--task=foo --status=succeeded
contains_ok "${TEST_NAME}.stdout" <<__OUT__
polling for 'succeeded': satisfied
__OUT__
#-------------------------------------------------------------------------------
TEST_NAME=${TEST_NAME_BASE}-cli-dump
run_ok "${TEST_NAME}" cylc suite-state "${SUITE_NAME}" -p 2010-01-01T00:00Z
contains_ok "${TEST_NAME}.stdout" <<__OUT__
foo, 20100101T0000Z, succeeded
__OUT__
#-------------------------------------------------------------------------------
purge_suite "${SUITE_NAME}"
#-------------------------------------------------------------------------------
exit 0
16 changes: 0 additions & 16 deletions tests/suite-state/format/suite.rc

This file was deleted.