15
15
"""
16
16
The widgets sub-module contains the ui widgets created using the ipywidgets package.
17
17
"""
18
+ import contextlib
19
+ import io
18
20
import os
19
21
from time import sleep
20
22
import time
@@ -113,38 +115,42 @@ def view_clusters(namespace: str = None):
113
115
df = _fetch_cluster_data (namespace )
114
116
if df .empty :
115
117
print (f"No clusters found in the { namespace } namespace." )
116
- else :
117
- classification_widget = widgets .ToggleButtons (
118
- options = df ["Name" ].tolist (), value = None ,
119
- description = 'Select an existing cluster:' ,
120
- )
118
+ return
121
119
122
- classification_widget .observe (lambda selection_change : _on_cluster_click (selection_change , raycluster_data_output , namespace , classification_widget ), names = "value" )
120
+ classification_widget = widgets .ToggleButtons (
121
+ options = df ["Name" ].tolist (), value = df ["Name" ].tolist ()[0 ],
122
+ description = 'Select an existing cluster:' ,
123
+ )
124
+ # Setting the initial value to trigger the event handler to display the cluster details.
125
+ initial_value = classification_widget .value
126
+ _on_cluster_click ({"new" : initial_value }, raycluster_data_output , namespace , classification_widget )
127
+ classification_widget .observe (lambda selection_change : _on_cluster_click (selection_change , raycluster_data_output , namespace , classification_widget ), names = "value" )
123
128
124
- delete_button = widgets .Button (
125
- description = 'Delete Cluster' ,
126
- icon = 'trash' ,
127
- tooltip = "Delete the selected cluster"
128
- )
129
- delete_button .on_click (lambda b : _on_delete_button_click (b , classification_widget , df , raycluster_data_output , user_output , delete_button , list_jobs_button , ray_dashboard_button ))
129
+ # UI table buttons
130
+ delete_button = widgets .Button (
131
+ description = 'Delete Cluster' ,
132
+ icon = 'trash' ,
133
+ tooltip = "Delete the selected cluster"
134
+ )
135
+ delete_button .on_click (lambda b : _on_delete_button_click (b , classification_widget , df , raycluster_data_output , user_output , delete_button , list_jobs_button , ray_dashboard_button ))
130
136
131
- list_jobs_button = widgets .Button (
132
- description = 'View Jobs' ,
133
- icon = 'suitcase' ,
134
- tooltip = "Open the Ray Job Dashboard"
135
- )
136
- list_jobs_button .on_click (lambda b : _on_list_jobs_button_click (b , classification_widget , df , user_output , url_output ))
137
+ list_jobs_button = widgets .Button (
138
+ description = 'View Jobs' ,
139
+ icon = 'suitcase' ,
140
+ tooltip = "Open the Ray Job Dashboard"
141
+ )
142
+ list_jobs_button .on_click (lambda b : _on_list_jobs_button_click (b , classification_widget , df , user_output , url_output ))
137
143
138
- ray_dashboard_button = widgets .Button (
139
- description = 'Open Ray Dashboard' ,
140
- icon = 'dashboard' ,
141
- tooltip = "Open the Ray Dashboard in a new tab" ,
142
- layout = widgets .Layout (width = 'auto' ),
143
- )
144
- ray_dashboard_button .on_click (lambda b : _on_ray_dashboard_button_click (b , classification_widget , df , user_output , url_output ))
144
+ ray_dashboard_button = widgets .Button (
145
+ description = 'Open Ray Dashboard' ,
146
+ icon = 'dashboard' ,
147
+ tooltip = "Open the Ray Dashboard in a new tab" ,
148
+ layout = widgets .Layout (width = 'auto' ),
149
+ )
150
+ ray_dashboard_button .on_click (lambda b : _on_ray_dashboard_button_click (b , classification_widget , df , user_output , url_output ))
145
151
146
- display (widgets .VBox ([classification_widget , raycluster_data_output ]))
147
- display (widgets .HBox ([delete_button , list_jobs_button , ray_dashboard_button ]), url_output , user_output )
152
+ display (widgets .VBox ([classification_widget , raycluster_data_output ]))
153
+ display (widgets .HBox ([delete_button , list_jobs_button , ray_dashboard_button ]), url_output , user_output )
148
154
149
155
# Handles the event when a cluster is selected from the toggle buttons, updating the output with cluster details.
150
156
def _on_cluster_click (selection_change , raycluster_data_output : widgets .Output , namespace : str , classification_widget : widgets .ToggleButtons ):
@@ -184,7 +190,9 @@ def _on_ray_dashboard_button_click(b, classification_widget: widgets.ToggleButto
184
190
cluster_name = classification_widget .value
185
191
namespace = df [df ["Name" ]== classification_widget .value ]["Namespace" ].values [0 ]
186
192
187
- cluster = Cluster (ClusterConfiguration (cluster_name , namespace ))
193
+ # Suppress from Cluster Object initialisation widgets and outputs
194
+ with widgets .Output (), contextlib .redirect_stdout (io .StringIO ()), contextlib .redirect_stderr (io .StringIO ()):
195
+ cluster = Cluster (ClusterConfiguration (cluster_name , namespace ))
188
196
dashboard_url = cluster .cluster_dashboard_uri ()
189
197
190
198
with user_output :
@@ -198,7 +206,9 @@ def _on_list_jobs_button_click(b, classification_widget: widgets.ToggleButtons,
198
206
cluster_name = classification_widget .value
199
207
namespace = df [df ["Name" ]== classification_widget .value ]["Namespace" ].values [0 ]
200
208
201
- cluster = Cluster (ClusterConfiguration (cluster_name , namespace ))
209
+ # Suppress from Cluster Object initialisation widgets and outputs
210
+ with widgets .Output (), contextlib .redirect_stdout (io .StringIO ()), contextlib .redirect_stderr (io .StringIO ()):
211
+ cluster = Cluster (ClusterConfiguration (cluster_name , namespace ))
202
212
dashboard_url = cluster .cluster_dashboard_uri ()
203
213
204
214
with user_output :
0 commit comments