Skip to content

Commit b610cd4

Browse files
committed
Convert sphinx-style docstrings to Google-style across src/
1 parent e23d969 commit b610cd4

9 files changed

Lines changed: 512 additions & 334 deletions

File tree

src/workflows/contrib/start_service.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ def run(
6060
**kwargs,
6161
):
6262
"""Example command line interface to start services.
63-
:param cmdline_args: List of command line arguments to pass to parser
64-
:param program_name: Name of the command line tool to display in help
65-
:param version: Version number to print when run with '--version'
63+
64+
Args:
65+
cmdline_args: List of command line arguments to pass to parser
66+
program_name: Name of the command line tool to display in help
67+
version: Version number to print when run with '--version'
6668
"""
6769

6870
# Enumerate all known services

src/workflows/frontend/__init__.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,24 @@ def __init__(
4444
"""Create a frontend instance. Connect to the transport layer, start any
4545
requested service, begin broadcasting status information and listen
4646
for control commands.
47-
:param restart_service:
48-
If the service process dies unexpectedly the frontend should start
49-
a new instance.
50-
:param service:
51-
A class or name of the class to be instantiated in a subprocess as
52-
service.
53-
:param transport:
54-
Either the name of a transport class, a transport class, or a
55-
transport class object.
56-
:param transport_command_channel:
57-
An optional channel of a transport subscription to be listened to for
58-
commands.
59-
:param verbose_service:
60-
If set, run services with increased logging level (DEBUG).
61-
:param environment:
62-
An optional dictionary that is passed to started services.
47+
48+
Args:
49+
restart_service:
50+
If the service process dies unexpectedly the frontend should start
51+
a new instance.
52+
service:
53+
A class or name of the class to be instantiated in a subprocess as
54+
service.
55+
transport:
56+
Either the name of a transport class, a transport class, or a
57+
transport class object.
58+
transport_command_channel:
59+
An optional channel of a transport subscription to be listened to
60+
for commands.
61+
verbose_service:
62+
If set, run services with increased logging level (DEBUG).
63+
environment:
64+
An optional dictionary that is passed to started services.
6365
"""
6466
self.__lock = threading.RLock()
6567
self.__hostid = workflows.util.generate_unique_host_id()
@@ -148,9 +150,12 @@ def update_status(self, status_code=None):
148150
broadcast if it is held for over 0.5 seconds.
149151
When the status does not change it is still broadcast every
150152
_status_interval seconds.
151-
:param status_code: Either an integer describing the service status
152-
(see workflows.services.common_service), or None
153-
if the status is unchanged.
153+
154+
Args:
155+
status_code:
156+
Either an integer describing the service status (see
157+
workflows.services.common_service), or None if the status is
158+
unchanged.
154159
"""
155160
if status_code is not None:
156161
self._service_status = status_code
@@ -399,9 +404,13 @@ def exponential_backoff(self):
399404

400405
def switch_service(self, new_service=None):
401406
"""Start a new service in a subprocess.
402-
:param new_service: Either a service name or a service class. If not set,
403-
start up a new instance of the previous class
404-
:return: True on success, False on failure.
407+
408+
Args:
409+
new_service: Either a service name or a service class. If not set,
410+
start up a new instance of the previous class.
411+
412+
Returns:
413+
True on success, False on failure.
405414
"""
406415
if new_service:
407416
self._service_factory = new_service

src/workflows/recipe/__init__.py

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,44 @@ def _wrap_subscription(
3535
"""Internal method to create an intercepting function for incoming messages
3636
to interpret recipes. This function is then used to subscribe to a channel
3737
on the transport layer.
38-
:param transport_layer: Reference to underlying transport object.
39-
:param subscription_call: Reference to the subscribing function of the
40-
transport layer.
41-
:param channel: Channel name to subscribe to.
42-
:param callback: Real function to be called when messages are received.
43-
The callback will pass three arguments,
44-
a RecipeWrapper object (details below), the header as
45-
a dictionary structure, and the message.
46-
47-
:param allow_non_recipe_messages: Pass on incoming messages that do not
48-
include recipe information. In this case the first
49-
argument to the callback function will be 'None'.
50-
:param log_extender: If the recipe contains useful contextual information
51-
for log messages, such as a unique ID which can be used
52-
to connect all messages originating from the same
53-
recipe, then the information will be passed to this
54-
function, which must be a context manager factory.
55-
:return: Return value of call to subscription_call.
38+
39+
Args:
40+
transport_layer: Reference to underlying transport object.
41+
subscription_call: Reference to the subscribing function of the transport layer.
42+
channel: Channel name to subscribe to.
43+
callback:
44+
Real function to be called when messages are received.
45+
The callback will pass three arguments: a RecipeWrapper object,
46+
the header as a dictionary structure, and the message.
47+
allow_non_recipe_messages:
48+
Pass on incoming messages that do not include recipe information.
49+
In this case the first argument to the callback function will be None.
50+
log_extender:
51+
If the recipe contains useful contextual information for log messages,
52+
such as a unique ID which can be used to connect all messages
53+
originating from the same recipe, then the information will be passed
54+
to this function, which must be a context manager factory.
55+
56+
Returns:
57+
Return value of call to subscription_call.
5658
"""
5759

5860
allow_non_recipe_messages = kwargs.pop("allow_non_recipe_messages", False)
5961
log_extender = kwargs.pop("log_extender", None)
6062

6163
@functools.wraps(callback)
6264
def unwrap_recipe(header, message):
63-
"""This is a helper function unpacking incoming messages when they are
64-
in a recipe format. Other messages are passed through unmodified.
65-
:param header: A dictionary of message headers. If the header contains
66-
an entry 'workflows-recipe' then the message is parsed
67-
and the embedded recipe information is passed on in a
68-
RecipeWrapper object to the target function.
69-
:param message: Incoming deserialized message object.
65+
"""Unpack incoming messages when they are in a recipe format.
66+
67+
Other messages are passed through unmodified.
68+
69+
Args:
70+
header:
71+
A dictionary of message headers. If the header contains an entry
72+
'workflows-recipe' then the message is parsed and the embedded
73+
recipe information is passed on in a RecipeWrapper object to the
74+
target function.
75+
message: Incoming deserialized message object.
7076
"""
7177
if mangle_for_receiving:
7278
message = mangle_for_receiving(message)
@@ -125,13 +131,17 @@ def wrap_subscribe(
125131
transport/common_transport.py. Intercept all incoming messages and parse
126132
for recipe information.
127133
See common_transport.subscribe for possible additional keyword arguments.
128-
:param transport_layer: Reference to underlying transport object.
129-
:param channel: Queue name to subscribe to.
130-
:param callback: Function to be called when messages are received.
131-
The callback will pass three arguments,
132-
a RecipeWrapper object (details below), the header as
133-
a dictionary structure, and the message.
134-
:return: A unique subscription ID
134+
135+
Args:
136+
transport_layer: Reference to underlying transport object.
137+
channel: Queue name to subscribe to.
138+
callback:
139+
Function to be called when messages are received. The callback will
140+
pass three arguments: a RecipeWrapper object, the header as a
141+
dictionary structure, and the message.
142+
143+
Returns:
144+
A unique subscription ID
135145
"""
136146

137147
return _wrap_subscription(
@@ -157,13 +167,17 @@ def wrap_subscribe_broadcast(
157167
subscribe_broadcast call in transport/common_transport.py. Intercept all
158168
incoming messages and parse for recipe information.
159169
See common_transport.subscribe_broadcast for possible arguments.
160-
:param transport_layer: Reference to underlying transport object.
161-
:param channel: Topic name to subscribe to.
162-
:param callback: Function to be called when messages are received.
163-
The callback will pass three arguments,
164-
a RecipeWrapper object (details below), the header as
165-
a dictionary structure, and the message.
166-
:return: A unique subscription ID
170+
171+
Args:
172+
transport_layer: Reference to underlying transport object.
173+
channel: Topic name to subscribe to.
174+
callback:
175+
Function to be called when messages are received. The callback will
176+
pass three arguments: a RecipeWrapper object, the header as a
177+
dictionary structure, and the message.
178+
179+
Returns:
180+
A unique subscription ID
167181
"""
168182

169183
return _wrap_subscription(

src/workflows/recipe/recipe.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,12 @@ def merge(self, other):
275275
"""Merge two recipes together, returning a single recipe containing all
276276
nodes.
277277
Note: This does NOT yet return a minimal recipe.
278-
:param other: A Recipe object that should be merged with the current
279-
Recipe object.
280-
:return: A new Recipe object containing information from both recipes.
278+
279+
Args:
280+
other: A Recipe object that should be merged with the current Recipe object.
281+
282+
Returns:
283+
A new Recipe object containing information from both recipes.
281284
"""
282285

283286
# Merging empty values returns a copy of the original

src/workflows/recipe/wrapper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ def start(self, header=None, **kwargs):
143143
def checkpoint(self, message, header=None, delay=0, **kwargs):
144144
"""Send a message to the current recipe destination. This can be used to
145145
keep a state for longer processing tasks.
146-
:param delay: Delay transport of message by this many seconds
146+
147+
Args:
148+
delay: Delay transport of message by this many seconds
147149
"""
148150
if not self.transport:
149151
raise ValueError(

src/workflows/services/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66
def lookup(service: str):
77
"""Find a service class based on a name.
8-
:param service: Name of the service
9-
:return: A service class
8+
9+
Args:
10+
service: Name of the service
11+
12+
Returns:
13+
A service class
1014
"""
1115
service_factory = get_known_services().get(service)
1216
if service_factory:
@@ -17,9 +21,11 @@ def lookup(service: str):
1721

1822
def get_known_services():
1923
"""Return a dictionary of all known services.
20-
:return: A dictionary containing entries { service name : service class factory }
21-
A factory is a function that takes no arguments and returns an
22-
uninstantiated service class.
24+
25+
Returns:
26+
A dictionary containing entries { service name : service class factory }
27+
where a factory is a function that takes no arguments and returns an
28+
uninstantiated service class.
2329
"""
2430
if not hasattr(get_known_services, "cache"):
2531
setattr(

0 commit comments

Comments
 (0)