Skip to content

Commit d6e98d9

Browse files
committed
blacken
1 parent 842fea0 commit d6e98d9

File tree

10 files changed

+1609
-1314
lines changed

10 files changed

+1609
-1314
lines changed

packages/python/plotly/_plotly_utils/importers.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ def __getattr__(import_name):
3232
# Check for submodule class
3333
if import_name in class_names:
3434
# print(parent_name, import_name)
35-
rel_path_parts = class_names[import_name].split('.')
36-
rel_module = '.'.join(rel_path_parts[:-1])
35+
rel_path_parts = class_names[import_name].split(".")
36+
rel_module = ".".join(rel_path_parts[:-1])
3737
class_name = import_name
38-
class_module = importlib.import_module(
39-
rel_module, parent_name
40-
)
38+
class_module = importlib.import_module(rel_module, parent_name)
4139
return getattr(class_module, class_name)
4240

4341
raise AttributeError(

packages/python/plotly/codegen/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
FrameNode,
1919
write_init_py,
2020
ElementDefaultsNode,
21-
build_from_imports_py)
21+
build_from_imports_py,
22+
)
2223
from codegen.validators import (
2324
write_validator_py,
2425
write_data_validator_py,
@@ -312,16 +313,18 @@ def __getattr__(import_name):
312313

313314
# ### Output graph_objects.py alias
314315
graph_objects_rel_classes = [
315-
"..graph_objs." + rel_path.split('.')[-1]
316+
"..graph_objs." + rel_path.split(".")[-1]
316317
for rel_path in datatype_rel_class_imports[()]
317318
]
318319
graph_objects_rel_modules = [
319-
"..graph_objs." + rel_module.split('.')[-1]
320+
"..graph_objs." + rel_module.split(".")[-1]
320321
for rel_module in datatype_rel_module_imports[()]
321322
]
322323

323324
graph_objects_init_source = build_from_imports_py(
324-
graph_objects_rel_modules, graph_objects_rel_classes, init_extra=optional_figure_widget_import
325+
graph_objects_rel_modules,
326+
graph_objects_rel_classes,
327+
init_extra=optional_figure_widget_import,
325328
)
326329
graph_objects_path = opath.join(outdir, "graph_objects", "__init__.py")
327330
os.makedirs(opath.join(outdir, "graph_objects"), exist_ok=True)

packages/python/plotly/codegen/datatypes.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,18 @@ def _subplot_re_match(self, prop):
155155

156156
child_datatype_nodes = node.child_datatypes
157157
subtype_nodes = child_datatype_nodes
158-
valid_props_list = sorted([node.name_property for node in subtype_nodes + literal_nodes])
159-
buffer.write(f"""
158+
valid_props_list = sorted(
159+
[node.name_property for node in subtype_nodes + literal_nodes]
160+
)
161+
buffer.write(
162+
f"""
160163
# class properties
161164
# --------------------
162165
_parent_path_str = '{node.parent_path_str}'
163166
_path_str = '{node.path_str}'
164167
_valid_props = {{"{'", "'.join(valid_props_list)}"}}
165-
""")
168+
"""
169+
)
166170

167171
# ### Property definitions ###
168172
for subtype_node in subtype_nodes:
@@ -307,22 +311,27 @@ def __init__(self"""
307311
return_type=node.name_datatype_class,
308312
)
309313

310-
buffer.write(f"""
314+
buffer.write(
315+
f"""
311316
super({datatype_class}, self).__init__('{node.name_property}')
312317
313318
if '_parent' in kwargs:
314319
self._parent = kwargs['_parent']
315320
return
316-
""")
321+
"""
322+
)
317323

318324
if datatype_class == "Layout":
319-
buffer.write(f"""
325+
buffer.write(
326+
f"""
320327
# Override _valid_props for instance so that instance can mutate set
321328
# to support subplot properties (e.g. xaxis2)
322329
self._valid_props = {{"{'", "'.join(valid_props_list)}"}}
323-
""")
330+
"""
331+
)
324332

325-
buffer.write(f"""
333+
buffer.write(
334+
f"""
326335
# Validate arg
327336
# ------------
328337
if arg is None:
@@ -340,7 +349,8 @@ def __init__(self"""
340349
# Handle skip_invalid
341350
# -------------------
342351
self._skip_invalid = kwargs.pop('skip_invalid', False)
343-
""")
352+
"""
353+
)
344354

345355
buffer.write(
346356
f"""
@@ -351,7 +361,7 @@ def __init__(self"""
351361
for subtype_node in subtype_nodes:
352362
name_prop = subtype_node.name_property
353363
buffer.write(
354-
f"""
364+
f"""
355365
_v = arg.pop('{name_prop}', None)
356366
_v = {name_prop} if {name_prop} is not None else _v
357367
if _v is not None:

packages/python/plotly/codegen/utils.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ def build_from_imports_py(rel_modules=(), rel_classes=(), init_extra=""):
6565

6666
import_lines = []
6767
for rel in rel_modules + rel_classes:
68-
rel_parts = rel.split('.')
69-
parent_module = '.'.join(rel_parts[:-1]) or '.'
68+
rel_parts = rel.split(".")
69+
parent_module = ".".join(rel_parts[:-1]) or "."
7070
import_target = rel_parts[-1]
7171
import_line = f"from {parent_module} import {import_target}"
7272
import_lines.append(import_line)
7373

74-
imports_str = '\n '.join(import_lines)
74+
imports_str = "\n ".join(import_lines)
7575

7676
result = f"""\
7777
import sys
@@ -89,6 +89,7 @@ def build_from_imports_py(rel_modules=(), rel_classes=(), init_extra=""):
8989
"""
9090
return result
9191

92+
9293
# buffer = StringIO()
9394
# for import_info in imports_info:
9495
#
@@ -442,10 +443,7 @@ def name_validator_class(self) -> str:
442443
-------
443444
str
444445
"""
445-
return (
446-
self.name_property.title()
447-
+ "Validator"
448-
)
446+
return self.name_property.title() + "Validator"
449447

450448
@property
451449
def name_base_validator(self) -> str:

packages/python/plotly/plotly/__init__.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@
4545
from plotly.version import __version__
4646

4747
__all__ = [
48-
'graph_objs',
49-
'tools',
50-
'utils',
51-
'offline',
52-
'colors',
53-
'io',
54-
'data',
55-
'colors',
56-
'__version__'
48+
"graph_objs",
49+
"tools",
50+
"utils",
51+
"offline",
52+
"colors",
53+
"io",
54+
"data",
55+
"colors",
56+
"__version__",
5757
]
5858
else:
5959
__all__, __getattr__ = relative_import(
@@ -69,7 +69,7 @@
6969
".data",
7070
".colors",
7171
],
72-
['.version.__version__']
72+
[".version.__version__"],
7373
)
7474

7575
# Trigger docstring generation
@@ -78,4 +78,5 @@
7878

7979
# TODO: Set default template here to make sure import process is complete
8080
from plotly.io import templates
81+
8182
templates._default = "plotly"

packages/python/plotly/plotly/basedatatypes.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class is a subclass of both BaseFigure and widgets.DOMWidget.
8989
is invalid AND skip_invalid is False
9090
"""
9191
from .validators import DataValidator, LayoutValidator, FramesValidator
92+
9293
super(BaseFigure, self).__init__()
9394

9495
# Assign layout_plotly to layout
@@ -247,6 +248,7 @@ class is a subclass of both BaseFigure and widgets.DOMWidget.
247248
# Animation property validators
248249
# -----------------------------
249250
from . import animation
251+
250252
self._animation_duration_validator = animation.DurationValidator()
251253
self._animation_easing_validator = animation.EasingValidator()
252254

@@ -1787,6 +1789,7 @@ def append_trace(self, trace, row, col):
17871789

17881790
def _set_trace_grid_position(self, trace, row, col, secondary_y=False):
17891791
from plotly.subplots import _set_trace_grid_reference
1792+
17901793
grid_ref = self._validate_get_grid_ref()
17911794
return _set_trace_grid_reference(
17921795
trace, self.layout, grid_ref, row, col, secondary_y
@@ -1843,6 +1846,7 @@ def get_subplot(self, row, col, secondary_y=False):
18431846
- yaxis: plotly.graph_objs.layout.YAxis instance for subplot
18441847
"""
18451848
from plotly.subplots import _get_grid_subplot
1849+
18461850
return _get_grid_subplot(self, row, col, secondary_y)
18471851

18481852
# Child property operations
@@ -1934,7 +1938,7 @@ def _init_child_props(self, child):
19341938
def _initialize_layout_template(self):
19351939
import plotly.io as pio
19361940

1937-
if self._layout_obj._props.get('template', None) is None:
1941+
if self._layout_obj._props.get("template", None) is None:
19381942
if pio.templates.default is not None:
19391943
with validate(False):
19401944
# Assume default template is already validated
@@ -2842,7 +2846,10 @@ def _perform_update(plotly_obj, update_obj, overwrite=False):
28422846
:class:`BasePlotlyType`, ``update_obj`` should be a tuple or list
28432847
of dicts
28442848
"""
2845-
from _plotly_utils.basevalidators import CompoundValidator, CompoundArrayValidator
2849+
from _plotly_utils.basevalidators import (
2850+
CompoundValidator,
2851+
CompoundArrayValidator,
2852+
)
28462853

28472854
if update_obj is None:
28482855
# Nothing to do
@@ -2956,8 +2963,8 @@ class BasePlotlyType(object):
29562963
# of relative path to new property (e.g. ('title', 'font')
29572964
_mapped_properties = {}
29582965

2959-
_parent_path_str = ''
2960-
_path_str = ''
2966+
_parent_path_str = ""
2967+
_path_str = ""
29612968
_valid_props = set()
29622969

29632970
def __init__(self, plotly_name, **kwargs):
@@ -3014,6 +3021,7 @@ def __init__(self, plotly_name, **kwargs):
30143021

30153022
def _get_validator(self, prop):
30163023
from .validator_cache import ValidatorCache
3024+
30173025
return ValidatorCache.get_validator(self._path_str, prop)
30183026

30193027
def _process_kwargs(self, **kwargs):
@@ -3099,7 +3107,11 @@ def _get_child_props(self, child):
30993107
else:
31003108
# ### Child a compound property ###
31013109
if child.plotly_name in self:
3102-
from _plotly_utils.basevalidators import CompoundValidator, CompoundArrayValidator
3110+
from _plotly_utils.basevalidators import (
3111+
CompoundValidator,
3112+
CompoundArrayValidator,
3113+
)
3114+
31033115
validator = self._get_validator(child.plotly_name)
31043116

31053117
if isinstance(validator, CompoundValidator):
@@ -3114,7 +3126,8 @@ def _get_child_props(self, child):
31143126
children_props = self._props.get(child.plotly_name, None)
31153127
return (
31163128
children_props[child_ind]
3117-
if children_props is not None and len(children_props) > child_ind
3129+
if children_props is not None
3130+
and len(children_props) > child_ind
31183131
else None
31193132
)
31203133

@@ -3325,7 +3338,9 @@ def __getitem__(self, prop):
33253338
Any
33263339
"""
33273340
from _plotly_utils.basevalidators import (
3328-
CompoundValidator, CompoundArrayValidator, BaseDataValidator
3341+
CompoundValidator,
3342+
CompoundArrayValidator,
3343+
BaseDataValidator,
33293344
)
33303345

33313346
# Normalize prop
@@ -3348,7 +3363,6 @@ def __getitem__(self, prop):
33483363
raise KeyError(prop)
33493364

33503365
validator = self._get_validator(prop)
3351-
self._init_props()
33523366

33533367
if isinstance(validator, CompoundValidator):
33543368
if self._compound_props.get(prop, None) is None:
@@ -3364,10 +3378,13 @@ def __getitem__(self, prop):
33643378
elif isinstance(validator, (CompoundArrayValidator, BaseDataValidator)):
33653379
if self._compound_array_props.get(prop, None) is None:
33663380
# Init list of compound objects
3367-
self._compound_array_props[prop] = [
3368-
validator.data_class(_parent=self)
3369-
for _ in self._props.get(prop, [])
3370-
]
3381+
if self._props is not None:
3382+
self._compound_array_props[prop] = [
3383+
validator.data_class(_parent=self)
3384+
for _ in self._props.get(prop, [])
3385+
]
3386+
else:
3387+
self._compound_array_props[prop] = []
33713388

33723389
return validator.present(self._compound_array_props[prop])
33733390
elif self._props is not None and prop in self._props:
@@ -3446,7 +3463,11 @@ def __setitem__(self, prop, value):
34463463
-------
34473464
None
34483465
"""
3449-
from _plotly_utils.basevalidators import CompoundValidator, CompoundArrayValidator, BaseDataValidator
3466+
from _plotly_utils.basevalidators import (
3467+
CompoundValidator,
3468+
CompoundArrayValidator,
3469+
BaseDataValidator,
3470+
)
34503471

34513472
# Normalize prop
34523473
# --------------
@@ -3504,7 +3525,6 @@ def __setitem__(self, prop, value):
35043525
self._compound_props.pop(prop, None)
35053526
self._compound_array_props.pop(prop, None)
35063527

3507-
35083528
# Handle non-scalar case
35093529
# ----------------------
35103530
# e.g. ('foo', 1), ()
@@ -3592,6 +3612,7 @@ def _build_repr_for_class(props, class_name, parent_path_str=None):
35923612
The representation string
35933613
"""
35943614
from plotly.utils import ElidedPrettyPrinter
3615+
35953616
if parent_path_str:
35963617
class_name = parent_path_str + "." + class_name
35973618

packages/python/plotly/plotly/io/__init__.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,19 @@
2929
else:
3030
__all__, __getattr__ = relative_import(
3131
__name__,
32+
[".orca", ".base_renderers"],
3233
[
33-
'.orca',
34-
'.base_renderers'
34+
"._orca.to_image",
35+
"._orca.write_image",
36+
"._json.to_json",
37+
"._json.from_json",
38+
"._json.read_json",
39+
"._json.write_json",
40+
"._templates.templates",
41+
"._templates.to_templated",
42+
"._html.to_html",
43+
"._html.write_html",
44+
"._renderers.renderers",
45+
"._renderers.show",
3546
],
36-
[
37-
'._orca.to_image',
38-
'._orca.write_image',
39-
'._json.to_json',
40-
'._json.from_json',
41-
'._json.read_json',
42-
'._json.write_json',
43-
'._templates.templates',
44-
'._templates.to_templated',
45-
'._html.to_html',
46-
'._html.write_html',
47-
'._renderers.renderers',
48-
'._renderers.show',
49-
]
5047
)

0 commit comments

Comments
 (0)