Skip to content

Commit 529771d

Browse files
authored
Merge pull request #4978 from plotly/codegen2
feat: modifying code generation to reduce bundle size
2 parents 4dded6c + db82ee4 commit 529771d

File tree

14,835 files changed

+140423
-347624
lines changed

Some content is hidden

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

14,835 files changed

+140423
-347624
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ jobs:
126126
command: |
127127
python -m venv venv
128128
. venv/bin/activate
129-
pip install black==22.3.0
129+
pip install black==25.1.0
130130
- run:
131131
name: Check formatting with black
132132
command: |

_plotly_utils/basevalidators.py

+4-23
Original file line numberDiff line numberDiff line change
@@ -1328,25 +1328,14 @@ def numbers_allowed(self):
13281328
return self.colorscale_path is not None
13291329

13301330
def description(self):
1331-
1332-
named_clrs_str = "\n".join(
1333-
textwrap.wrap(
1334-
", ".join(self.named_colors),
1335-
width=79 - 16,
1336-
initial_indent=" " * 12,
1337-
subsequent_indent=" " * 12,
1338-
)
1339-
)
1340-
13411331
valid_color_description = """\
13421332
The '{plotly_name}' property is a color and may be specified as:
13431333
- A hex string (e.g. '#ff0000')
13441334
- An rgb/rgba string (e.g. 'rgb(255,0,0)')
13451335
- An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
13461336
- An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
1347-
- A named CSS color:
1348-
{clrs}""".format(
1349-
plotly_name=self.plotly_name, clrs=named_clrs_str
1337+
- A named CSS color: see https://plotly.com/python/css-colors/ for a list""".format(
1338+
plotly_name=self.plotly_name
13501339
)
13511340

13521341
if self.colorscale_path:
@@ -2483,15 +2472,11 @@ def description(self):
24832472
that may be specified as:
24842473
- An instance of :class:`{module_str}.{class_str}`
24852474
- A dict of string/value properties that will be passed
2486-
to the {class_str} constructor
2487-
2488-
Supported dict properties:
2489-
{constructor_params_str}"""
2475+
to the {class_str} constructor"""
24902476
).format(
24912477
plotly_name=self.plotly_name,
24922478
class_str=self.data_class_str,
24932479
module_str=self.module_str,
2494-
constructor_params_str=self.data_docs,
24952480
)
24962481

24972482
return desc
@@ -2560,15 +2545,11 @@ def description(self):
25602545
{class_str} that may be specified as:
25612546
- A list or tuple of instances of {module_str}.{class_str}
25622547
- A list or tuple of dicts of string/value properties that
2563-
will be passed to the {class_str} constructor
2564-
2565-
Supported dict properties:
2566-
{constructor_params_str}"""
2548+
will be passed to the {class_str} constructor"""
25672549
).format(
25682550
plotly_name=self.plotly_name,
25692551
class_str=self.data_class_str,
25702552
module_str=self.module_str,
2571-
constructor_params_str=self.data_docs,
25722553
)
25732554

25742555
return desc

_plotly_utils/colors/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
Be careful! If you have a lot of unique numbers in your color column you will
7474
end up with a colormap that is massive and may slow down graphing performance.
7575
"""
76+
7677
import decimal
7778
from numbers import Number
7879

codegen/__init__.py

+30-32
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
get_data_validator_instance,
2727
)
2828

29+
# Target Python version for code formatting with Black.
30+
# Must be one of the values listed in pyproject.toml.
31+
BLACK_TARGET_VERSIONS = "py38 py39 py310 py311 py312"
32+
2933

3034
# Import notes
3135
# ------------
@@ -85,7 +89,7 @@ def preprocess_schema(plotly_schema):
8589
items["colorscale"] = items.pop("concentrationscales")
8690

8791

88-
def perform_codegen():
92+
def perform_codegen(reformat=True):
8993
# Set root codegen output directory
9094
# ---------------------------------
9195
# (relative to project root)
@@ -267,36 +271,24 @@ def perform_codegen():
267271
root_datatype_imports.append(f"._deprecations.{dep_clas}")
268272

269273
optional_figure_widget_import = f"""
270-
if sys.version_info < (3, 7) or TYPE_CHECKING:
271-
try:
272-
import ipywidgets as _ipywidgets
273-
from packaging.version import Version as _Version
274-
if _Version(_ipywidgets.__version__) >= _Version("7.0.0"):
275-
from ..graph_objs._figurewidget import FigureWidget
276-
else:
277-
raise ImportError()
278-
except Exception:
279-
from ..missing_anywidget import FigureWidget
280-
else:
281-
__all__.append("FigureWidget")
282-
orig_getattr = __getattr__
283-
def __getattr__(import_name):
284-
if import_name == "FigureWidget":
285-
try:
286-
import ipywidgets
287-
from packaging.version import Version
288-
289-
if Version(ipywidgets.__version__) >= Version("7.0.0"):
290-
from ..graph_objs._figurewidget import FigureWidget
291-
292-
return FigureWidget
293-
else:
294-
raise ImportError()
295-
except Exception:
296-
from ..missing_anywidget import FigureWidget
274+
__all__.append("FigureWidget")
275+
orig_getattr = __getattr__
276+
def __getattr__(import_name):
277+
if import_name == "FigureWidget":
278+
try:
279+
import ipywidgets
280+
from packaging.version import Version
281+
282+
if Version(ipywidgets.__version__) >= Version("7.0.0"):
283+
from ..graph_objs._figurewidget import FigureWidget
297284
return FigureWidget
285+
else:
286+
raise ImportError()
287+
except Exception:
288+
from ..missing_anywidget import FigureWidget
289+
return FigureWidget
298290
299-
return orig_getattr(import_name)
291+
return orig_getattr(import_name)
300292
"""
301293
# ### __all__ ###
302294
for path_parts, class_names in alls.items():
@@ -337,9 +329,15 @@ def __getattr__(import_name):
337329
f.write(graph_objects_init_source)
338330

339331
# ### Run black code formatter on output directories ###
340-
subprocess.call(["black", "--target-version=py36", validators_pkgdir])
341-
subprocess.call(["black", "--target-version=py36", graph_objs_pkgdir])
342-
subprocess.call(["black", "--target-version=py36", graph_objects_path])
332+
if reformat:
333+
target_version = [
334+
f"--target-version={v}" for v in BLACK_TARGET_VERSIONS.split()
335+
]
336+
subprocess.call(["black", *target_version, validators_pkgdir])
337+
subprocess.call(["black", *target_version, graph_objs_pkgdir])
338+
subprocess.call(["black", *target_version, graph_objects_path])
339+
else:
340+
print("skipping reformatting")
343341

344342

345343
if __name__ == "__main__":

codegen/compatibility.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __init__(self, *args, **kwargs):
8989
{depr_msg}
9090
\"\"\"
9191
warnings.warn(\"\"\"{depr_msg}\"\"\", DeprecationWarning)
92-
super({class_name}, self).__init__(*args, **kwargs)\n\n\n"""
92+
super().__init__(*args, **kwargs)\n\n\n"""
9393
)
9494

9595
# Return source string

0 commit comments

Comments
 (0)