Skip to content

Commit aea6dfe

Browse files
author
Jon M. Mease
committed
Codegen text wrapping refinements
1 parent 01d597d commit aea6dfe

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

_plotly_utils/basevalidators.py

+24-17
Original file line numberDiff line numberDiff line change
@@ -339,23 +339,25 @@ def description(self):
339339
enum_vals_str = '\n'.join(
340340
textwrap.wrap(
341341
repr(enum_vals),
342+
initial_indent=' ' * 12,
342343
subsequent_indent=' ' * 12,
343344
break_on_hyphens=False))
344345

345346
desc = desc + """
346347
- One of the following enumeration values:
347-
{enum_vals_str}""".format(enum_vals_str=enum_vals_str)
348+
{enum_vals_str}""".format(enum_vals_str=enum_vals_str)
348349

349350
if enum_regexs:
350351
enum_regexs_str = '\n'.join(
351352
textwrap.wrap(
352353
repr(enum_regexs),
354+
initial_indent=' ' * 12,
353355
subsequent_indent=' ' * 12,
354356
break_on_hyphens=False))
355357

356358
desc = desc + """
357359
- A string that matches one of the following regular expressions:
358-
{enum_vals_str}""".format(enum_vals_str=enum_regexs_str)
360+
{enum_regexs_str}""".format(enum_regexs_str=enum_regexs_str)
359361

360362
if self.array_ok:
361363
desc = desc + """
@@ -681,12 +683,13 @@ def description(self):
681683
valid_str = '\n'.join(
682684
textwrap.wrap(
683685
repr(self.values),
686+
initial_indent=' ' * 12,
684687
subsequent_indent=' ' * 12,
685688
break_on_hyphens=False))
686689

687690
desc = desc + """
688691
- One of the following strings:
689-
{valid_str}""".format(valid_str=valid_str)
692+
{valid_str}""".format(valid_str=valid_str)
690693
else:
691694
desc = desc + """
692695
- A string"""
@@ -1003,15 +1006,16 @@ def __init__(self, plotly_name, parent_name, **kwargs):
10031006

10041007
def description(self):
10051008
desc = """\
1006-
The '{plotly_name}' property is a colorscale and may be specified as:
1007-
- A list of 2-element lists where the first element is the normalized
1008-
color level value (starting at 0 and ending at 1), and the second
1009-
item is a valid color string.
1009+
The '{plotly_name}' property is a colorscale and may be
1010+
specified as:
1011+
- A list of 2-element lists where the first element is the
1012+
normalized color level value (starting at 0 and ending at 1),
1013+
and the second item is a valid color string.
10101014
(e.g. [[0, 'green'], [0.5, 'red'], [1.0, 'rgb(0, 0, 255)']])
10111015
- One of the following named colorscales:
10121016
['Greys', 'YlGnBu', 'Greens', 'YlOrRd', 'Bluered', 'RdBu',
1013-
'Reds', 'Blues', 'Picnic', 'Rainbow', 'Portland', 'Jet', 'Hot',
1014-
'Blackbody', 'Earth', 'Electric', 'Viridis']
1017+
'Reds', 'Blues', 'Picnic', 'Rainbow', 'Portland', 'Jet',
1018+
'Hot', 'Blackbody', 'Earth', 'Electric', 'Viridis']
10151019
""".format(plotly_name=self.plotly_name)
10161020

10171021
return desc
@@ -1489,8 +1493,8 @@ def description(self):
14891493
The '{plotly_name}' property is an instance of {class_str}
14901494
that may be specified as:
14911495
- An instance of {module_str}.{class_str}
1492-
- A dict of string/value properties that will be passed to the
1493-
{class_str} constructor
1496+
- A dict of string/value properties that will be passed
1497+
to the {class_str} constructor
14941498
14951499
Supported dict properties:
14961500
{constructor_params_str}""").format(
@@ -1539,8 +1543,8 @@ def description(self):
15391543
The '{plotly_name}' property is a tuple of instances of
15401544
{class_str} that may be specified as:
15411545
- A list or tuple of instances of {module_str}.{class_str}
1542-
- A list or tuple of dicts of string/value properties that will be
1543-
passed to the {class_str} constructor
1546+
- A list or tuple of dicts of string/value properties that
1547+
will be passed to the {class_str} constructor
15441548
15451549
Supported dict properties:
15461550
{constructor_params_str}""").format(
@@ -1606,7 +1610,10 @@ def description(self):
16061610

16071611
trace_types_wrapped = '\n'.join(
16081612
textwrap.wrap(
1609-
trace_types, subsequent_indent=' ' * 21, width=79 - 12))
1613+
trace_types,
1614+
initial_indent=' One of: ',
1615+
subsequent_indent=' ' * 21,
1616+
width=79 - 12))
16101617

16111618
desc = ("""\
16121619
The '{plotly_name}' property is a tuple of trace instances
@@ -1615,10 +1622,10 @@ def description(self):
16151622
(e.g. [Scatter(...), Bar(...)])
16161623
- A list or tuple of dicts of string/value properties where:
16171624
- The 'type' property specifies the trace type
1618-
One of: {trace_types}
1625+
{trace_types}
16191626
1620-
- All remaining properties are passed to the constructor of the
1621-
specified trace type
1627+
- All remaining properties are passed to the constructor of
1628+
the specified trace type
16221629
16231630
(e.g. [{{'type': 'scatter', ...}}, {{'type': 'bar, ...}}])""").format(
16241631
plotly_name=self.plotly_name, trace_types=trace_types_wrapped)

codegen/datatypes.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class {datatype_class}({node.name_base_datatype}):\n""")
116116
raw_description = subtype_node.description
117117
property_description = '\n'.join(
118118
textwrap.wrap(raw_description,
119+
initial_indent=' ' * 8,
119120
subsequent_indent=' ' * 8,
120121
width=79 - 8))
121122

@@ -131,7 +132,7 @@ class {datatype_class}({node.name_base_datatype}):\n""")
131132
132133
{validator_description}"""
133134
else:
134-
property_docstring = validator_description
135+
property_docstring = f" {validator_description}"
135136
else:
136137
property_docstring = property_description
137138

@@ -143,7 +144,7 @@ class {datatype_class}({node.name_base_datatype}):\n""")
143144
@property
144145
def {subtype_node.name_property}(self) -> {prop_type}:
145146
\"\"\"
146-
{property_docstring}
147+
{property_docstring}
147148
\"\"\"
148149
return self['{subtype_node.name_property}']""")
149150

@@ -307,6 +308,7 @@ def add_docstring(buffer, node, header):
307308
description_lines = textwrap.wrap(
308309
node_description,
309310
width=79-8,
311+
initial_indent=' ' * 8,
310312
subsequent_indent=' ' * 8)
311313

312314
node_description = '\n'.join(description_lines) + '\n\n'
@@ -317,7 +319,7 @@ def add_docstring(buffer, node, header):
317319
\"\"\"
318320
{header}
319321
320-
{node_description} Parameters
322+
{node_description} Parameters
321323
----------""")
322324

323325
# Write parameter descriptions

0 commit comments

Comments
 (0)