@@ -31,12 +31,10 @@ class _JupyterRenderer:
31
31
32
32
@staticmethod
33
33
def _find_available_port ():
34
- """
35
- Find an available port.
34
+ """Find an available port.
36
35
37
36
Thank you Mihai Capotă, https://stackoverflow.com/a/61685162
38
37
"""
39
-
40
38
import socketserver
41
39
42
40
with socketserver .TCPServer (("localhost" , 0 ), None ) as s :
@@ -46,10 +44,7 @@ def _find_available_port():
46
44
# check docs about proxy settings
47
45
48
46
def run (self , layout ):
49
- """
50
- Run Dash app.
51
- """
52
-
47
+ """Run Dash app."""
53
48
app = Dash (plugins = [CrystalToolkitPlugin (layout = layout )])
54
49
55
50
port = SETTINGS .JUPYTER_EMBED_PORT or self ._find_available_port ()
@@ -63,10 +58,7 @@ def run(self, layout):
63
58
app .run (port = free_port , jupyter_mode = SETTINGS .JUPYTER_EMBED_MODE )
64
59
65
60
def display (self , obj ):
66
- """
67
- Display a provided object.
68
- """
69
-
61
+ """Display a provided object."""
70
62
for kls , component in self .registry .items ():
71
63
if isinstance (obj , kls ):
72
64
layout = ctl .Block (
@@ -79,35 +71,27 @@ def display(self, obj):
79
71
80
72
81
73
def _to_plotly_json (self ):
82
- """
83
- Patch to ensure MSONable objects can be serialized into JSON by plotly tools.
84
- """
74
+ """Patch to ensure MSONable objects can be serialized into JSON by plotly tools."""
85
75
return self .as_dict ()
86
76
87
77
88
78
def _display_json (self , ** kwargs ):
89
- """
90
- Display JSON representation of an MSONable object inside Jupyter.
91
- """
79
+ """Display JSON representation of an MSONable object inside Jupyter."""
92
80
from IPython .display import JSON
93
81
94
82
JSON (self .as_dict (), ** kwargs )
95
83
96
84
97
85
def _repr_mimebundle_ (self , include = None , exclude = None ):
98
- """
99
- Method used by Jupyter. A default for MSONable objects to return JSON representation.
100
- """
86
+ """Method used by Jupyter. A default for MSONable objects to return JSON representation."""
101
87
return {
102
88
"application/json" : self .as_dict (),
103
89
"text/plain" : repr (self ),
104
90
}
105
91
106
92
107
93
def _ipython_display_ (self ):
108
- """
109
- Display MSONable objects using a Crystal Toolkit component, if available.
110
- """
94
+ """Display MSONable objects using a Crystal Toolkit component, if available."""
111
95
from IPython .display import publish_display_data
112
96
113
97
if any (isinstance (self , x ) for x in _JupyterRenderer .registry ):
@@ -140,11 +124,9 @@ def _ipython_display_(self):
140
124
141
125
142
126
def patch_msonable ():
143
- """
144
- Patch MSONable to allow MSONable objects to render in Jupyter
127
+ """Patch MSONable to allow MSONable objects to render in Jupyter
145
128
environments using Crystal Toolkit components.
146
129
"""
147
-
148
130
from monty .json import MSONable
149
131
150
132
MSONable .to_plotly_json = _to_plotly_json
0 commit comments