Skip to content

Commit

Permalink
make docstrings play nicely with Napoleon
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Feb 1, 2024
1 parent b543af7 commit 26bc684
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
17 changes: 15 additions & 2 deletions cylc/flow/xtriggers/echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,26 @@

from cylc.flow.exceptions import WorkflowConfigError

from typing import Tuple

def echo(*args, **kwargs):

def echo(*args, **kwargs) -> Tuple:
"""Print arguments to stdout, return kwargs['succeed'] and kwargs.
This may be a useful aid to understanding how xtriggers work.
Args:
succeed: Set the succeess of failure of this xtrigger.
*args: Print to stdout.
**kwargs: Print to stdout, and return as output.
Examples:
>>> echo('Breakfast Time', succeed=True, egg='poached')
True, {'succeed': True, 'egg': 'poached'}
Returns
tuple: (True/False, kwargs)
(True/False, kwargs)
"""
print("echo: ARGS:", args)
Expand All @@ -35,6 +47,7 @@ def echo(*args, **kwargs):


def validate(f_args, f_kwargs, f_signature):

"""
Validate the xtrigger function arguments parsed from the workflow config.
Expand Down
30 changes: 20 additions & 10 deletions cylc/flow/xtriggers/xrandom.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,50 @@

from random import random, randint
from time import sleep
from typing import TYPE_CHECKING

from cylc.flow.exceptions import WorkflowConfigError


if TYPE_CHECKING:
from typing import Any, Dict, Tuple


COLORS = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]
SIZES = ["tiny", "small", "medium", "large", "huge", "humongous"]


def xrandom(percent, secs=0, _=None):
def xrandom(
percent: float, secs: int = 0, _: 'Any' = None
) -> 'Tuple[bool, Dict]':
"""Random xtrigger, with configurable sleep and percent success.
Sleep for ``sec`` seconds, and report satisfied with ~``percent``
Sleep for ``sec`` seconds, and report satisfied with ``percent``
likelihood.
The ``_`` argument is not used in the function code, but can be used to
specialize the function signature to cycle point or task.
Args:
percent (float):
percent:
Percent likelihood of passing.
secs (int):
secs:
Seconds to sleep before starting the trigger.
_ (object):
_:
Used to allow users to specialize the trigger with extra
parameters.
Examples:
If the percent is zero, it returns that the trigger condition was
not satisfied, and an empty dictionary.
>>> xrandom(0, 0)
(False, {})
If the percent is not zero, but the random percent success is not met,
then it also returns that the trigger condition was not satisfied,
and an empty dictionary.
>>> import sys
>>> mocked_random = lambda: 0.3
>>> sys.modules[__name__].random = mocked_random
Expand All @@ -60,6 +69,7 @@ def xrandom(percent, secs=0, _=None):
Finally, if the percent is not zero, and the random percent success is
met, then it returns that the trigger condition was satisfied, and a
dictionary containing random color and size as result.
>>> import sys
>>> mocked_random = lambda: 0.9
>>> sys.modules[__name__].random = mocked_random
Expand All @@ -69,17 +79,17 @@ def xrandom(percent, secs=0, _=None):
(True, {'COLOR': 'orange', 'SIZE': 'small'})
Returns:
tuple: (satisfied, results)
Tuple, containing:
satisfied (bool):
satisfied:
True if ``satisfied`` else ``False``.
results (dict):
results:
A dictionary containing the following keys:
``COLOR``
A random color (e.g. red, orange, ...)
A random color (e.g. red, orange, ...).
``SIZE``
A random size (e.g. small, medium, ...) as the result.
A random size (e.g. small, medium, ...).
"""
sleep(float(secs))
Expand Down

0 comments on commit 26bc684

Please sign in to comment.