|
26 | 26 | get_data_validator_instance,
|
27 | 27 | )
|
28 | 28 |
|
| 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 | + |
29 | 33 |
|
30 | 34 | # Import notes
|
31 | 35 | # ------------
|
@@ -85,7 +89,7 @@ def preprocess_schema(plotly_schema):
|
85 | 89 | items["colorscale"] = items.pop("concentrationscales")
|
86 | 90 |
|
87 | 91 |
|
88 |
| -def perform_codegen(): |
| 92 | +def perform_codegen(reformat=True): |
89 | 93 | # Set root codegen output directory
|
90 | 94 | # ---------------------------------
|
91 | 95 | # (relative to project root)
|
@@ -267,36 +271,24 @@ def perform_codegen():
|
267 | 271 | root_datatype_imports.append(f"._deprecations.{dep_clas}")
|
268 | 272 |
|
269 | 273 | 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 |
297 | 284 | return FigureWidget
|
| 285 | + else: |
| 286 | + raise ImportError() |
| 287 | + except Exception: |
| 288 | + from ..missing_anywidget import FigureWidget |
| 289 | + return FigureWidget |
298 | 290 |
|
299 |
| - return orig_getattr(import_name) |
| 291 | + return orig_getattr(import_name) |
300 | 292 | """
|
301 | 293 | # ### __all__ ###
|
302 | 294 | for path_parts, class_names in alls.items():
|
@@ -337,9 +329,15 @@ def __getattr__(import_name):
|
337 | 329 | f.write(graph_objects_init_source)
|
338 | 330 |
|
339 | 331 | # ### 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") |
343 | 341 |
|
344 | 342 |
|
345 | 343 | if __name__ == "__main__":
|
|
0 commit comments