Skip to content

Commit cc678a0

Browse files
committed
trying to get imports to work
1 parent 73a8291 commit cc678a0

File tree

2,968 files changed

+438976
-439197
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,968 files changed

+438976
-439197
lines changed

bin/codegen/__init__.py

Lines changed: 13 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from codegen.datatypes import build_datatype_py, write_datatype_py # noqa: F401
77
from codegen.compatibility import (
88
write_deprecated_datatypes,
9-
write_graph_objs_graph_objs,
109
DEPRECATED_DATATYPES,
1110
)
1211
from codegen.figure import write_figure_classes
@@ -60,7 +59,7 @@ def preprocess_schema(plotly_schema):
6059
matching the structure of `figure.layout` and `traceTemplate` is a dict
6160
matching the structure of the trace with type `trace_type` (e.g. 'scatter').
6261
Alternatively, this may be specified as an instance of
63-
plotly.graph_objs.layout.Template.
62+
plotly.graph_objects.layout.Template.
6463
6564
Trace templates are applied cyclically to
6665
traces of each type. Container arrays (eg `annotations`) have special
@@ -89,22 +88,22 @@ def make_paths(codedir):
8988
"""Make various paths needed for code generation."""
9089

9190
validators_dir = codedir / "validators"
92-
graph_objs_dir = codedir / "graph_objs"
91+
graph_objects_dir = codedir / "graph_objects"
9392
graph_objects_path = codedir / "graph_objects" / "__init__.py"
94-
return validators_dir, graph_objs_dir, graph_objects_path
93+
return validators_dir, graph_objects_dir, graph_objects_path
9594

9695

9796
def perform_codegen(codedir, noformat=False):
9897
"""Generate code."""
9998

10099
# Get paths
101-
validators_dir, graph_objs_dir, graph_objects_path = make_paths(codedir)
100+
validators_dir, graph_objects_dir, graph_objects_path = make_paths(codedir)
102101

103102
# Delete prior codegen output
104103
if validators_dir.exists():
105104
shutil.rmtree(validators_dir)
106-
if graph_objs_dir.exists():
107-
shutil.rmtree(graph_objs_dir)
105+
if graph_objects_dir.exists():
106+
shutil.rmtree(graph_objects_dir)
108107

109108
# Load plotly schema
110109
project_root = codedir.parent
@@ -186,10 +185,10 @@ def perform_codegen(codedir, noformat=False):
186185
write_datatype_py(codedir, node)
187186

188187
# Deprecated
189-
# These are deprecated legacy datatypes like graph_objs.Marker
188+
# These are deprecated legacy datatypes like graph_objects.Marker
190189
write_deprecated_datatypes(codedir)
191190

192-
# Write figure class to graph_objs
191+
# Write figure class to graph_objects
193192
data_validator = get_data_validator_instance(base_traces_node)
194193
layout_validator = layout_node.get_validator_instance()
195194
frame_validator = frame_node.get_validator_instance()
@@ -222,11 +221,6 @@ def perform_codegen(codedir, noformat=False):
222221
f".{node.name_undercase}"
223222
)
224223

225-
# Write plotly/graph_objs/graph_objs.py
226-
# This is for backward compatibility. It just imports everything from
227-
# graph_objs/__init__.py
228-
write_graph_objs_graph_objs(codedir)
229-
230224
# Add Figure and FigureWidget
231225
root_datatype_imports = datatype_rel_class_imports[()]
232226
root_datatype_imports.append("._figure.Figure")
@@ -235,71 +229,34 @@ def perform_codegen(codedir, noformat=False):
235229
for dep_clas in DEPRECATED_DATATYPES:
236230
root_datatype_imports.append(f"._deprecations.{dep_clas}")
237231

238-
optional_figure_widget_import = """
239-
if sys.version_info < (3, 7) or TYPE_CHECKING:
240-
try:
241-
import ipywidgets as _ipywidgets
242-
from packaging.version import Version as _Version
243-
if _Version(_ipywidgets.__version__) >= _Version("7.0.0"):
244-
from ..graph_objs._figurewidget import FigureWidget
245-
else:
246-
raise ImportError()
247-
except Exception:
248-
from ..missing_anywidget import FigureWidget
249-
else:
250-
__all__.append("FigureWidget")
251-
orig_getattr = __getattr__
252-
def __getattr__(import_name):
253-
if import_name == "FigureWidget":
254-
try:
255-
import ipywidgets
256-
from packaging.version import Version
257-
if Version(ipywidgets.__version__) >= Version("7.0.0"):
258-
from ..graph_objs._figurewidget import FigureWidget
259-
return FigureWidget
260-
else:
261-
raise ImportError()
262-
except Exception:
263-
from ..missing_anywidget import FigureWidget
264-
return FigureWidget
265-
else:
266-
raise ImportError()
267-
268-
return orig_getattr(import_name)
269-
"""
270232
# __all__
271233
for path_parts, class_names in alls.items():
272234
if path_parts and class_names:
273-
filepath = codedir / "graph_objs"
235+
filepath = codedir / "graph_objects"
274236
filepath = filepath.joinpath(*path_parts) / "__init__.py"
275237
with open(filepath, "at") as f:
276238
f.write(f"\n__all__ = {class_names}")
277239

278240
# Output datatype __init__.py files
279-
graph_objs_pkg = codedir / "graph_objs"
241+
graph_objects_pkg = codedir / "graph_objects"
280242
for path_parts in datatype_rel_class_imports:
281243
rel_classes = sorted(datatype_rel_class_imports[path_parts])
282244
rel_modules = sorted(datatype_rel_module_imports.get(path_parts, []))
283-
if path_parts == ():
284-
init_extra = optional_figure_widget_import
285-
else:
286-
init_extra = ""
287-
write_init_py(graph_objs_pkg, path_parts, rel_modules, rel_classes, init_extra)
245+
write_init_py(graph_objects_pkg, path_parts, rel_modules, rel_classes)
288246

289247
# Output graph_objects.py alias
290248
graph_objects_rel_classes = [
291-
"..graph_objs." + rel_path.split(".")[-1]
249+
"..graph_objects." + rel_path.split(".")[-1]
292250
for rel_path in datatype_rel_class_imports[()]
293251
]
294252
graph_objects_rel_modules = [
295-
"..graph_objs." + rel_module.split(".")[-1]
253+
"..graph_objects." + rel_module.split(".")[-1]
296254
for rel_module in datatype_rel_module_imports[()]
297255
]
298256

299257
graph_objects_init_source = build_from_imports_py(
300258
graph_objects_rel_modules,
301259
graph_objects_rel_classes,
302-
init_extra=optional_figure_widget_import,
303260
)
304261
graph_objects_path = codedir / "graph_objects"
305262
graph_objects_path.mkdir(parents=True, exist_ok=True)

bin/codegen/compatibility.py

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
def build_deprecated_datatypes_py():
4444
"""
45-
Build datatype (graph_objs) class source code string for deprecated
45+
Build datatype (graph_objects) class source code string for deprecated
4646
datatypes
4747
4848
Returns
@@ -57,7 +57,7 @@ def build_deprecated_datatypes_py():
5757
buffer.write(
5858
r"""
5959
warnings.filterwarnings("default",
60-
r"plotly\.graph_objs\.\w+ is deprecated",
60+
r"plotly\.graph_objects\.\w+ is deprecated",
6161
DeprecationWarning)
6262
6363
@@ -100,15 +100,15 @@ def build_deprecation_message(class_name, base_type, new):
100100
new: list of str
101101
List of replacements that users should use instead.
102102
Replacements may be:
103-
- A package string relative to plotly.graph_objs. In this case the
103+
- A package string relative to plotly.graph_objects. In this case the
104104
replacement class is assumed to be named `class_name`.
105105
e.g. `new` == ['layout`] and `class_name` == 'XAxis` corresponds
106-
to the 'plotly.graph_objs.layout.XAxis' class
106+
to the 'plotly.graph_objects.layout.XAxis' class
107107
- String containing the package and class. The string is
108108
identified as containing a class name if the final name in the
109109
package string begins with an uppercase letter.
110110
e.g. `new` == ['Scatter'] corresponds to the
111-
['plotly.graph_objs.Scatter'] class.
111+
['plotly.graph_objects.Scatter'] class.
112112
- The literal string 'etc.'. This string is not interpreted as a
113113
package or class and is displayed to the user as-is to
114114
indicate that the list of replacement classes is not complete.
@@ -129,21 +129,21 @@ def build_deprecation_message(class_name, base_type, new):
129129
if not repl_is_class:
130130
repl_parts.append(class_name)
131131

132-
# Add plotly.graph_objs prefix
133-
full_class_str = ".".join(["plotly", "graph_objs"] + repl_parts)
132+
# Add plotly.graph_objects prefix
133+
full_class_str = ".".join(["plotly", "graph_objects"] + repl_parts)
134134
replacements.append(full_class_str)
135135

136136
replacemens_str = "\n - ".join(replacements)
137137

138138
if base_type is list:
139139
return f"""\
140-
plotly.graph_objs.{class_name} is deprecated.
140+
plotly.graph_objects.{class_name} is deprecated.
141141
Please replace it with a list or tuple of instances of the following types
142142
- {replacemens_str}
143143
"""
144144
else:
145145
return f"""\
146-
plotly.graph_objs.{class_name} is deprecated.
146+
plotly.graph_objects.{class_name} is deprecated.
147147
Please replace it with one of the following more specific types
148148
- {replacemens_str}
149149
"""
@@ -157,42 +157,15 @@ def write_deprecated_datatypes(codedir):
157157
Parameters
158158
----------
159159
codedir :
160-
Root directory in which the graph_objs package should reside
160+
Root directory in which the graph_objects package should reside
161161
162162
Returns
163163
-------
164164
None
165165
"""
166166
# Generate source code
167167
datatype_source = build_deprecated_datatypes_py()
168-
filepath = codedir / "graph_objs" / "_deprecations.py"
168+
filepath = codedir / "graph_objects" / "_deprecations.py"
169169

170170
# Write file
171171
write_source_py(datatype_source, filepath)
172-
173-
174-
def write_graph_objs_graph_objs(codedir):
175-
"""
176-
Write the plotly/graph_objs/graph_objs.py file
177-
178-
This module just imports everything from the plotly.graph_objs package.
179-
We write it for backward compatibility with legacy imports like:
180-
181-
from plotly.graph_objs import graph_objs
182-
183-
Parameters
184-
----------
185-
codedir : str
186-
Root directory in which the graph_objs package should reside
187-
188-
Returns
189-
-------
190-
None
191-
"""
192-
filepath = codedir / "graph_objs" / "graph_objs.py"
193-
with open(filepath, "wt") as f:
194-
f.write(
195-
"""\
196-
from plotly.graph_objs import *
197-
"""
198-
)

bin/codegen/datatypes.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def get_typing_type(plotly_type, array_ok=False):
5353

5454
def build_datatype_py(node):
5555
"""
56-
Build datatype (graph_objs) class source code string for a datatype
56+
Build datatype (graph_objects) class source code string for a datatype
5757
PlotlyNode
5858
5959
Parameters
@@ -73,14 +73,14 @@ def build_datatype_py(node):
7373
# Handle template traces
7474
#
7575
# We want template trace/layout classes like
76-
# plotly.graph_objs.layout.template.data.Scatter to map to the
77-
# corresponding trace/layout class (e.g. plotly.graph_objs.Scatter).
76+
# plotly.graph_objects.layout.template.data.Scatter to map to the
77+
# corresponding trace/layout class (e.g. plotly.graph_objects.Scatter).
7878
# So rather than generate a class definition, we just import the
7979
# corresponding trace/layout class
8080
if node.parent_path_str == "layout.template.data":
81-
return f"from plotly.graph_objs import {node.name_datatype_class}"
81+
return f"from plotly.graph_objects import {node.name_datatype_class}"
8282
elif node.path_str == "layout.template.layout":
83-
return "from plotly.graph_objs import Layout"
83+
return "from plotly.graph_objects import Layout"
8484

8585
# Extract node properties
8686
datatype_class = node.name_datatype_class
@@ -175,13 +175,13 @@ def _subplot_re_match(self, prop):
175175
for subtype_node in subtype_nodes:
176176
if subtype_node.is_array_element:
177177
prop_type = (
178-
f"tuple[plotly.graph_objs{node.dotpath_str}."
178+
f"tuple[plotly.graph_objects{node.dotpath_str}."
179179
+ f"{subtype_node.name_datatype_class}]"
180180
)
181181

182182
elif subtype_node.is_compound:
183183
prop_type = (
184-
f"plotly.graph_objs{node.dotpath_str}."
184+
f"plotly.graph_objects{node.dotpath_str}."
185185
+ f"{subtype_node.name_datatype_class}"
186186
)
187187

@@ -291,7 +291,7 @@ def __init__(self"""
291291
# Constructor Docstring
292292
header = f"Construct a new {datatype_class} object"
293293
class_name = (
294-
f"plotly.graph_objs{node.parent_dotpath_str}.{node.name_datatype_class}"
294+
f"plotly.graph_objects{node.parent_dotpath_str}.{node.name_datatype_class}"
295295
)
296296

297297
extras = [
@@ -582,12 +582,12 @@ def add_docstring(
582582

583583
def write_datatype_py(outdir, node):
584584
"""
585-
Build datatype (graph_objs) class source code and write to a file
585+
Build datatype (graph_objects) class source code and write to a file
586586
587587
Parameters
588588
----------
589589
outdir :
590-
Root outdir in which the graph_objs package should reside
590+
Root outdir in which the graph_objects package should reside
591591
node :
592592
The datatype node (node.is_datatype must evaluate to true) for which
593593
to build the datatype class
@@ -597,6 +597,6 @@ def write_datatype_py(outdir, node):
597597
None
598598
"""
599599

600-
filepath = (outdir / "graph_objs").joinpath(*node.parent_path_parts) / f"_{node.name_undercase}.py"
600+
filepath = (outdir / "graph_objects").joinpath(*node.parent_path_parts) / f"_{node.name_undercase}.py"
601601
datatype_source = build_datatype_py(node)
602602
write_source_py(datatype_source, filepath, leading_newlines=2)

bin/codegen/figure.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def add_{trace_node.plotly_name}(self"""
255255
# Function body
256256
buffer.write(
257257
f"""
258-
from plotly.graph_objs import {trace_node.name_datatype_class}
258+
from plotly.graph_objects import {trace_node.name_datatype_class}
259259
new_trace = {trace_node.name_datatype_class}(
260260
"""
261261
)
@@ -671,7 +671,7 @@ def add_{method_prefix}{singular_name}(self"""
671671
# Function body
672672
buffer.write(
673673
f"""
674-
from plotly.graph_objs import layout as _layout
674+
from plotly.graph_objects import layout as _layout
675675
new_obj = _layout.{node.name_datatype_class}(arg,
676676
"""
677677
)
@@ -714,13 +714,13 @@ def write_figure_classes(
714714
):
715715
"""
716716
Construct source code for the Figure and FigureWidget classes and
717-
write to graph_objs/_figure.py and graph_objs/_figurewidget.py
717+
write to graph_objects/_figure.py and graph_objects/_figurewidget.py
718718
respectively
719719
720720
Parameters
721721
----------
722722
codedir : str
723-
Root directory in which the graph_objs package should reside
723+
Root directory in which the graph_objects package should reside
724724
trace_node : PlotlyNode
725725
Root trace node (the node that is the parent of all of the
726726
individual trace nodes like bar, scatter, etc.)
@@ -767,5 +767,5 @@ def write_figure_classes(
767767
)
768768

769769
# Format and write to file
770-
filepath = codedir / "graph_objs" / f"_{fig_classname.lower()}.py"
770+
filepath = codedir / "graph_objects" / f"_{fig_classname.lower()}.py"
771771
write_source_py(figure_source, filepath)

0 commit comments

Comments
 (0)