Skip to content

Commit e7708d2

Browse files
committed
refactor
1 parent 7b3e9f7 commit e7708d2

File tree

1 file changed

+27
-39
lines changed

1 file changed

+27
-39
lines changed

cylc/flow/config.py

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,10 @@ def __init__(
433433
self.process_start_cycle_point()
434434
self.process_final_cycle_point()
435435
self.process_stop_cycle_point()
436-
self.start_point_checks()
436+
if self.start_point:
437+
self.cycle_point_warning('start', 'before', 'initial')
438+
self.cycle_point_warning('start', 'after', 'final')
439+
self.cycle_point_warning('stop', 'before', 'start')
437440

438441
# Parse special task cycle point offsets, and replace family names.
439442
LOG.debug("Parsing [special tasks]")
@@ -776,29 +779,24 @@ def process_start_cycle_point(self) -> None:
776779
# Start from the initial point.
777780
self.start_point = self.initial_point
778781

779-
def start_point_checks(self):
780-
"""Check that the start point makes sense.
782+
def cycle_point_warning(self, label1, order, label2):
783+
"""Centralized logic for warning that start, stop, initial and
784+
final cycle points are not sensibly ordered.
781785
"""
782-
if not self.start_point:
783-
return
784-
elif self.start_point < self.initial_point:
785-
LOG.warning(
786-
f"Start cycle point '{self.start_point}' will have no "
787-
"effect as it is before the initial cycle "
788-
f"point '{self.initial_point}'."
789-
)
790-
elif self.start_point > self.final_point:
791-
LOG.warning(
792-
f"Start cycle point '{self.start_point}' will have no "
793-
"effect as it is after the final cycle "
794-
f"point '{self.final_point}'."
795-
)
796-
elif self.start_point > self.stop_point:
797-
LOG.warning(
798-
f"Stop cycle point '{self.stop_point}' will have no "
799-
"effect as it is before the start cycle "
800-
f"point '{self.start_point}'."
786+
point1 = getattr(self, label1 + '_point')
787+
point2 = getattr(self, label2 + '_point')
788+
if (
789+
order == 'before' and point1 < point2
790+
or order == 'after' and point1 > point2
791+
):
792+
msg = (
793+
f"{label1} cycle point '{point1}' will have no effect as"
794+
f" it is {order} the {label2} cycle point '{point2}'."
801795
)
796+
# Capitalize() makes the ISO strings look very odd:
797+
LOG.warning(msg[0].upper() + msg[1:])
798+
return True
799+
return False
802800

803801
def process_final_cycle_point(self) -> None:
804802
"""Validate and set the final cycle point from flow.cylc or options.
@@ -880,25 +878,15 @@ def process_stop_cycle_point(self) -> None:
880878
self.initial_point,
881879
).standardise()
882880
if (
883-
self.final_point is not None
884-
and self.stop_point is not None
885-
and self.stop_point > self.final_point
886-
):
887-
LOG.warning(
888-
f"Stop cycle point '{self.stop_point}' will have no "
889-
"effect as it is after the final cycle "
890-
f"point '{self.final_point}'."
881+
self.stop_point is not None
882+
and (
883+
(
884+
self.final_point is not None
885+
and self.cycle_point_warning('stop', 'after', 'final')
886+
)
887+
or self.cycle_point_warning('stop', 'before', 'initial')
891888
)
892-
self.stop_point = None
893-
if (
894-
self.stop_point is not None
895-
and self.stop_point < self.initial_point
896889
):
897-
LOG.warning(
898-
f"Stop cycle point '{self.stop_point}' will have no "
899-
"effect as it is before the initial cycle "
900-
f"point '{self.initial_point}'."
901-
)
902890
self.stop_point = None
903891
stopcp_str = str(self.stop_point) if self.stop_point else None
904892
self.cfg['scheduling']['stop after cycle point'] = stopcp_str

0 commit comments

Comments
 (0)