Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 012471d

Browse files
committed
Replace yapf with black for codegen
1 parent 0a0de08 commit 012471d

File tree

10 files changed

+19
-88
lines changed

10 files changed

+19
-88
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ jobs:
310310
- checkout
311311
- run:
312312
name: Install tox
313-
command: 'sudo pip install tox requests yapf pytz decorator retrying inflect'
313+
command: 'sudo pip install tox requests black pytz decorator retrying inflect'
314314
- run:
315315
name: Update jupyterlab-plotly version
316316
command: 'cd packages/python/plotly; python setup.py updateplotlywidgetversion'

packages/python/plotly/codegen/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os.path as opath
33
import shutil
4+
import subprocess
45

56
from codegen.datatypes import build_datatype_py, write_datatype_py
67
from codegen.compatibility import (
@@ -252,6 +253,10 @@ def perform_codegen():
252253
for path_parts, import_pairs in path_to_datatype_import_info.items():
253254
write_init_py(graph_objs_pkg, path_parts, import_pairs)
254255

256+
# ### Run black code formatter on output directories ###
257+
subprocess.call(["black", validators_pkgdir])
258+
subprocess.call(["black", graph_objs_pkgdir])
259+
255260

256261
if __name__ == "__main__":
257262
perform_codegen()

packages/python/plotly/codegen/compatibility.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from io import StringIO
22
from os import path as opath
33

4-
from codegen.utils import format_and_write_source_py
4+
from codegen.utils import write_source_py
55

66
# Build dict with info about deprecated datatypes
77
DEPRECATED_DATATYPES = {
@@ -181,7 +181,7 @@ def write_deprecated_datatypes(outdir):
181181

182182
# Write file
183183
# ----------
184-
format_and_write_source_py(datatype_source, filepath)
184+
write_source_py(datatype_source, filepath)
185185

186186

187187
def write_graph_objs_graph_objs(outdir):

packages/python/plotly/codegen/datatypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import textwrap
33
from io import StringIO
44

5-
from codegen.utils import PlotlyNode, format_and_write_source_py
5+
from codegen.utils import PlotlyNode, write_source_py
66

77

88
def get_typing_type(plotly_type, array_ok=False):
@@ -615,4 +615,4 @@ def write_datatype_py(outdir, node):
615615
# Write file
616616
# ----------
617617

618-
format_and_write_source_py(datatype_source, filepath, leading_newlines=2)
618+
write_source_py(datatype_source, filepath, leading_newlines=2)

packages/python/plotly/codegen/figure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
add_constructor_params,
1212
add_docstring,
1313
)
14-
from codegen.utils import PlotlyNode, format_and_write_source_py
14+
from codegen.utils import PlotlyNode, write_source_py
1515

1616
import inflect
1717

@@ -419,4 +419,4 @@ def write_figure_classes(
419419

420420
# ### Format and write to file###
421421
filepath = opath.join(outdir, "graph_objs", f"_{fig_classname.lower()}.py")
422-
format_and_write_source_py(figure_source, filepath)
422+
write_source_py(figure_source, filepath)

packages/python/plotly/codegen/utils.py

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,10 @@
77
from typing import List
88
import re
99

10-
from yapf.yapflib.yapf_api import FormatCode
11-
1210

1311
# Source code utilities
1412
# =====================
15-
def format_source(input_source):
16-
"""
17-
Use yapf to format a string containing Python source code
18-
19-
Parameters
20-
----------
21-
input_source : str
22-
String containing Python source code
23-
24-
Returns
25-
-------
26-
String containing yapf-formatted python source code
27-
"""
28-
style_config = {
29-
"based_on_style": "google",
30-
"DEDENT_CLOSING_BRACKETS": True,
31-
"COLUMN_LIMIT": 79,
32-
}
33-
formatted_source, _ = FormatCode(input_source, style_config=style_config)
34-
return formatted_source
35-
36-
37-
def format_and_write_source_py(py_source, filepath, leading_newlines=0):
13+
def write_source_py(py_source, filepath, leading_newlines=0):
3814
"""
3915
Format Python source code and write to a file, creating parent
4016
directories as needed.
@@ -51,22 +27,16 @@ def format_and_write_source_py(py_source, filepath, leading_newlines=0):
5127
None
5228
"""
5329
if py_source:
54-
try:
55-
formatted_source = format_source(py_source)
56-
except Exception as e:
57-
print(py_source)
58-
raise e
59-
6030
# Make dir if needed
6131
# ------------------
6232
filedir = opath.dirname(filepath)
6333
os.makedirs(filedir, exist_ok=True)
6434

6535
# Write file
6636
# ----------
67-
formatted_source = "\n" * leading_newlines + formatted_source
37+
py_source = "\n" * leading_newlines + py_source
6838
with open(filepath, "at") as f:
69-
f.write(formatted_source)
39+
f.write(py_source)
7040

7141

7242
def build_from_imports_py(imports_info):
@@ -135,7 +105,7 @@ def write_init_py(pkg_root, path_parts, import_pairs):
135105
# Write file
136106
# ----------
137107
filepath = opath.join(pkg_root, *path_parts, "__init__.py")
138-
format_and_write_source_py(init_source, filepath, leading_newlines=2)
108+
write_source_py(init_source, filepath, leading_newlines=2)
139109

140110

141111
def format_description(desc):

packages/python/plotly/codegen/validators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from io import StringIO
33

44
import _plotly_utils.basevalidators
5-
from codegen.utils import PlotlyNode, TraceNode, format_and_write_source_py
5+
from codegen.utils import PlotlyNode, TraceNode, write_source_py
66

77

88
def build_validator_py(node: PlotlyNode):
@@ -109,7 +109,7 @@ def write_validator_py(outdir, node: PlotlyNode):
109109
# ----------
110110
filepath = opath.join(outdir, "validators", *node.parent_path_parts, "__init__.py")
111111

112-
format_and_write_source_py(validator_source, filepath, leading_newlines=2)
112+
write_source_py(validator_source, filepath, leading_newlines=2)
113113

114114

115115
def build_data_validator_params(base_trace_node: TraceNode):
@@ -260,4 +260,4 @@ def write_data_validator_py(outdir, base_trace_node: TraceNode):
260260
# Write file
261261
# ----------
262262
filepath = opath.join(outdir, "validators", "__init__.py")
263-
format_and_write_source_py(source, filepath, leading_newlines=2)
263+
write_source_py(source, filepath, leading_newlines=2)

packages/python/plotly/optional-requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ nose==1.3.3
1818
pytest==3.5.1
1919
backports.tempfile==1.0
2020
xarray
21-
## orca ##
2221
psutil
2322

2423
## code formatting
2524
pre-commit
2625

2726
## codegen dependencies ##
28-
yapf
2927
inflect
3028

3129
## template generation ##

packages/python/plotly/plotly/graph_objs/layout/template/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from plotly.graph_objs import Layout
22

3-
43
from plotly.basedatatypes import BaseLayoutHierarchyType as _BaseLayoutHierarchyType
54
import copy as _copy
65

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,83 @@
11
from plotly.graph_objs import Waterfall
22

3-
43
from plotly.graph_objs import Volume
54

6-
75
from plotly.graph_objs import Violin
86

9-
107
from plotly.graph_objs import Table
118

12-
139
from plotly.graph_objs import Surface
1410

15-
1611
from plotly.graph_objs import Sunburst
1712

18-
1913
from plotly.graph_objs import Streamtube
2014

21-
2215
from plotly.graph_objs import Splom
2316

24-
2517
from plotly.graph_objs import Scatterternary
2618

27-
2819
from plotly.graph_objs import Scatter
2920

30-
3121
from plotly.graph_objs import Scatterpolar
3222

33-
3423
from plotly.graph_objs import Scatterpolargl
3524

36-
3725
from plotly.graph_objs import Scattermapbox
3826

39-
4027
from plotly.graph_objs import Scattergl
4128

42-
4329
from plotly.graph_objs import Scattergeo
4430

45-
4631
from plotly.graph_objs import Scattercarpet
4732

48-
4933
from plotly.graph_objs import Scatter3d
5034

51-
5235
from plotly.graph_objs import Sankey
5336

54-
5537
from plotly.graph_objs import Pointcloud
5638

57-
5839
from plotly.graph_objs import Pie
5940

60-
6141
from plotly.graph_objs import Parcoords
6242

63-
6443
from plotly.graph_objs import Parcats
6544

66-
6745
from plotly.graph_objs import Ohlc
6846

69-
7047
from plotly.graph_objs import Mesh3d
7148

72-
7349
from plotly.graph_objs import Isosurface
7450

75-
7651
from plotly.graph_objs import Histogram
7752

78-
7953
from plotly.graph_objs import Histogram2d
8054

81-
8255
from plotly.graph_objs import Histogram2dContour
8356

84-
8557
from plotly.graph_objs import Heatmap
8658

87-
8859
from plotly.graph_objs import Heatmapgl
8960

90-
9161
from plotly.graph_objs import Funnel
9262

93-
9463
from plotly.graph_objs import Funnelarea
9564

96-
9765
from plotly.graph_objs import Contour
9866

99-
10067
from plotly.graph_objs import Contourcarpet
10168

102-
10369
from plotly.graph_objs import Cone
10470

105-
10671
from plotly.graph_objs import Choropleth
10772

108-
10973
from plotly.graph_objs import Carpet
11074

111-
11275
from plotly.graph_objs import Candlestick
11376

114-
11577
from plotly.graph_objs import Box
11678

117-
11879
from plotly.graph_objs import Bar
11980

120-
12181
from plotly.graph_objs import Barpolar
12282

123-
12483
from plotly.graph_objs import Area

0 commit comments

Comments
 (0)