-
Notifications
You must be signed in to change notification settings - Fork 2
docstring conform to PEP 484 #30
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,9 +36,9 @@ class ScriptManager(object): | |
multiple globals that pylint would complain about. | ||
|
||
Attributes: | ||
all_scripts (dict): a dict of name:script | ||
action_class (class): the class to instantiate for new actions | ||
script_class (class): the class to instantiate for new scripts | ||
all_scripts (Dict[str, scriptharness.script.Script]): a dict of name:script | ||
action_class (scriptharness.actions.Action): the class to instantiate for new actions | ||
script_class (scriptharness.script.Script): the class to instantiate for new scripts | ||
""" | ||
def __init__(self): | ||
self.all_scripts = {} | ||
|
@@ -59,6 +59,10 @@ def get_script(self, *args, **kwargs): | |
|
||
def get_config(self, name="root"): | ||
"""Back end for scriptharness.get_config(). | ||
|
||
Args: | ||
name (Optional[str]): The name of the script to get the config from. | ||
Defaults to "root". | ||
""" | ||
if name not in self.all_scripts: | ||
raise ScriptHarnessException(os.linesep.join([ | ||
|
@@ -74,6 +78,10 @@ def get_config(self, name="root"): | |
|
||
def get_logger(self, name="root"): | ||
"""Back end for scriptharness.get_logger(). | ||
|
||
Args: | ||
name (Optional[str]): The name of the script to get the config from. | ||
Defaults to "root". | ||
""" | ||
if name not in self.all_scripts: | ||
raise ScriptHarnessException(os.linesep.join([ | ||
|
@@ -104,8 +112,8 @@ def get_script(*args, **kwargs): | |
"""This will retrieve an existing script or create one and return it. | ||
|
||
Args: | ||
actions (tuple of Actions): When creating a new Script, | ||
this is required. When retrieving an existing script, this is | ||
actions (Tuple[scriptharness.actions.Action...]): When creating a new | ||
Script, this is required. When retrieving an existing script, this is | ||
ignored/optional. | ||
|
||
parser (argparse.ArgumentParser): When creating a new Script, | ||
|
@@ -136,7 +144,7 @@ def get_config(name="root"): | |
of name `name`. | ||
|
||
Returns: | ||
config (dict): By default scriptharness.structures.LoggingDict | ||
config (Dict[str, str]): By default scriptharness.structures.LoggingDict | ||
""" | ||
return MANAGER.get_config(name=name) | ||
|
||
|
@@ -158,7 +166,7 @@ def get_logger(name="root"): | |
of name `name`. | ||
|
||
Returns: | ||
logger (logging.Logger) | ||
logging.Logger: logger | ||
""" | ||
return MANAGER.get_logger(name=name) | ||
|
||
|
@@ -185,11 +193,11 @@ def get_actions(all_actions): | |
"""Build a tuple of Action objects for the script. | ||
|
||
Args: | ||
all_actions (data structure): ordered mapping of action_name:enabled | ||
all_actions (Sequence[str, bool]): ordered mapping of action_name:enabled | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be right. all_actions can be a tuple of tuples or list of lists or a dict. I'm not entirely sure Sequence is accurate, but I'm not sure how to improve it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I read in this case it would either be a Sequence or an Iterable, but to be honest the difference is also quite blurry for me. Do you think it would be better to have it as Iterable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think leave it, for now. I think Sequence is better than Mapping, at least. |
||
bool, as accepted by iterate_pairs() | ||
|
||
Returns: | ||
tuple of Action objects | ||
Tuple[scriptharness.actions.Action, ...]: tuple of Action objects | ||
""" | ||
action_list = [] | ||
for action_name, value in iterate_pairs(all_actions): | ||
|
@@ -201,11 +209,11 @@ def get_actions_from_list(all_actions, default_actions=None): | |
"""Helper method to generate the ordered mapping for get_actions(). | ||
|
||
Args: | ||
all_actions (list): ordered list of all action names | ||
default_actions (Optional[list]): actions that are enabled by default | ||
all_actions (List[str]): ordered list of all action names | ||
default_actions (Optional[List[str]]): actions that are enabled by default | ||
|
||
Returns: | ||
tuple of Action objects | ||
Tuple[scriptharness.actions.Action, ...]: tuple of Action objects | ||
""" | ||
if default_actions is None: | ||
default_actions = all_actions[:] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,8 @@ | |
|
||
Attributes: | ||
LOGGER_NAME (str): logging.Logger name to use | ||
STRINGS (dict): strings for actions. In the future these may be in a | ||
function to allow for localization. | ||
STRINGS (Dict[str, Dict[str, str]]): strings for actions. In the future | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is accurate at the moment, but really, it's just a freeform dict of dicts and strings. Are these docstrings really this inflexible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I preferred doing it this way because as you just said, it is a free form which is not clear for someone that hasn't seen the code at all. I think it is just more clear this way. Nevertheless the docstrings are not inflexible at all, you could define a new type and use it there instead of the nested dicts. Another option is to define your own class and use that type (I did that for the LoggingDict) but since it was a free form I thought it was clearer this way. |
||
these may be in a function to allow for localization. | ||
""" | ||
from __future__ import absolute_import, division, print_function, \ | ||
unicode_literals | ||
|
@@ -43,7 +43,7 @@ def get_function_by_name(function_name): | |
function_name (str): The name of the function to find. | ||
|
||
Returns: | ||
function: the function found. | ||
Callable[[Any], Any]: the function found. | ||
|
||
Raises: | ||
scriptharness.exceptions.ScriptHarnesException: if the function is | ||
|
@@ -70,28 +70,29 @@ class Action(object): | |
enabled (bool): Enabled actions will run. Disabled actions will log | ||
the skip_message and not run. | ||
|
||
strings (dict): Strings for action-specific log messages. | ||
strings (Dict[str, str]): Strings for action-specific log messages. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
|
||
logger_name (str): The logger name for logging calls inside this object. | ||
|
||
function (function): This is the function to call in run_function(). | ||
function (Callable[[Any], Any]): This is the function to call in | ||
run_function(). | ||
|
||
history (dict): History of the action (return_value, status, start_time, | ||
end_time). | ||
history (Dict[str, Any]): History of the action (return_value, status, | ||
start_time, end_time). | ||
""" | ||
def __init__(self, name, action_groups=None, function=None, enabled=True): | ||
r"""Create the Action object. | ||
|
||
Args: | ||
name (str): Action name, for logging. | ||
|
||
action_groups (list): a list of action group names that this | ||
action_groups (List[str]): a list of action group names that this | ||
Action belongs to. If scriptharness_volatile_action_group is | ||
specified in config (usually via \--action-group), all actions | ||
belonging to that action group will be enabled by default, and all | ||
others disabled by default. | ||
|
||
function (Optional[function]). This is the function or method | ||
function (Optional[Callable[[Any], Any]]). This is the function or method | ||
to run in run_function(). If not specified, use | ||
get_function_by_name() to find the function that matches the | ||
action name. If not found, raise. | ||
|
@@ -124,8 +125,8 @@ def run_function(self, context): | |
This sets self.history['return_value'] for posterity. | ||
|
||
Args: | ||
context (Context): the context from the calling Script | ||
(passed from run()). | ||
context (Context): the context from the calling Script; as defined | ||
in `script.py`. (passed from run()). | ||
""" | ||
self.history['return_value'] = self.function(context) | ||
|
||
|
@@ -135,7 +136,8 @@ def run(self, context): | |
This sets self.history timestamps and status. | ||
|
||
Args: | ||
context (Context): the context from the calling Script. | ||
context (Context): the context from the calling Script; as defined | ||
in `script.py` | ||
|
||
Returns: | ||
status (int): one of SUCCESS, ERROR, or FATAL. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config doesn't have to have str values; they can be dicts, lists, strs, ints... maybe 'object' or 'various' or something?
Ah, looks like 'Any'.