@@ -20,79 +20,83 @@ def get_help(object_name, path=(), parent_object_names=(), attribute=None):
20
20
:return: (str) A printable string to show to users.
21
21
22
22
"""
23
- help_string = 'Help for {}\n \n ' .format (object_name )
24
23
if object_name in graph_reference .ARRAYS :
25
- help_string + = _list_help (object_name , path , parent_object_names )
24
+ help_string = _list_help (object_name , path , parent_object_names )
26
25
else :
27
26
if attribute :
28
- help_string + = _dict_attribute_help (object_name , path ,
29
- parent_object_names , attribute )
27
+ help_string = _dict_attribute_help (object_name , path ,
28
+ parent_object_names , attribute )
30
29
else :
31
- help_string += _dict_object_help (object_name , path ,
32
- parent_object_names )
33
- help_string = help_string .expandtabs (TAB_SIZE )
34
- return help_string
30
+ help_string = _dict_object_help (object_name , path ,
31
+ parent_object_names )
32
+ return help_string .expandtabs (TAB_SIZE )
35
33
36
34
37
35
def _list_help (object_name , path = (), parent_object_names = ()):
36
+ """See get_help()."""
38
37
items = graph_reference .ARRAYS [object_name ]['items' ]
39
38
items_classes = [graph_reference .string_to_class_name (item )
40
39
for item in items ]
41
- lines = textwrap .wrap (repr (items_classes ), width = LINE_SIZE - TAB_SIZE )
42
- items_string = '\n \t ' .join (lines )
43
- help_string = 'Valid Item Classes:\n {}\n ' .format (items_string )
44
- return help_string
40
+ lines = textwrap .wrap (repr (items_classes ), width = LINE_SIZE - TAB_SIZE )
41
+
42
+ help_dict = {
43
+ 'object_name' : object_name ,
44
+ 'path_string' : '[' + '][' .join (repr (k ) for k in path ) + ']' ,
45
+ 'parent_object_names' : parent_object_names ,
46
+ 'items_string' : '\t ' + '\n \t ' .join (lines )
47
+ }
48
+
49
+ return (
50
+ "Valid items for '{object_name}' at path {path_string} under parents "
51
+ "{parent_object_names}:\n {items_string}\n " .format (** help_dict )
52
+ )
45
53
46
54
47
55
def _dict_object_help (object_name , path , parent_object_names ):
48
- """
49
- Get general help information on an dict-like plotly graph object.
50
-
51
- :param object_name:
52
- :param path:
53
- :param parent_object_names:
54
- :return:
55
-
56
- """
57
- parent_class_names = [
58
- graph_reference .string_to_class_name (parent_object_name )
59
- for parent_object_name in parent_object_names
60
- ]
56
+ """See get_help()."""
61
57
attributes = graph_reference .get_valid_attributes (object_name ,
62
58
parent_object_names )
63
- help_dict = {'path' : path ,
64
- 'parent_class_names' : parent_class_names }
65
-
66
- lines = textwrap .wrap (repr (list (attributes )), width = LINE_SIZE - TAB_SIZE )
67
- attributes_str = '\n \t ' .join (lines )
68
- help_string = (
69
- "Run `.help('attribute')` on any of the following attributes:\n \n \t "
70
- "{attributes_str}"
59
+ lines = textwrap .wrap (repr (list (attributes )), width = LINE_SIZE - TAB_SIZE )
60
+
61
+ help_dict = {
62
+ 'object_name' : object_name ,
63
+ 'path_string' : '[' + '][' .join (repr (k ) for k in path ) + ']' ,
64
+ 'parent_object_names' : parent_object_names ,
65
+ 'attributes_string' : '\t ' + '\n \t ' .join (lines )
66
+ }
67
+
68
+ return (
69
+ "Valid attributes for '{object_name}' at path {path_string} under "
70
+ "parents {parent_object_names}:\n \n {attributes_string}\n \n "
71
+ "Run `<{object_name}-object>.help('attribute')` on any of the above.\n "
72
+ "'<{object_name}-object>' is the object at {path_string}"
73
+ .format (** help_dict )
71
74
)
72
- return help_string .format (attributes_str = attributes_str , ** help_dict )
73
75
74
76
75
77
def _dict_attribute_help (object_name , path , parent_object_names , attribute ):
76
78
"""
77
79
Get general help information or information on a specific attribute.
78
80
81
+ See get_help().
82
+
79
83
:param (str|unicode) attribute: The attribute we'll get info for.
80
84
81
85
"""
82
- parent_class_names = [
83
- graph_reference .string_to_class_name (parent_object_name )
84
- for parent_object_name in parent_object_names
85
- ]
86
+ help_dict = {
87
+ 'object_name' : object_name ,
88
+ 'path_string' : '[' + '][' .join (repr (k ) for k in path ) + ']' ,
89
+ 'parent_object_names' : parent_object_names ,
90
+ 'attribute' : attribute
91
+ }
92
+
86
93
valid_attributes = graph_reference .get_valid_attributes (
87
94
object_name , parent_object_names
88
95
)
89
- help_dict = {'path' : path ,
90
- 'parent_class_names' : parent_class_names ,
91
- 'attribute' : attribute }
92
96
93
97
help_string = (
94
- "Current path: {path }\n "
95
- "Current parents : {parent_class_names }\n \n " )
98
+ "Current path: {path_string }\n "
99
+ "Current parent object_names : {parent_object_names }\n \n " )
96
100
97
101
if attribute not in valid_attributes :
98
102
help_string += "'{attribute}' is not allowed here.\n "
0 commit comments