|
14 | 14 | # ============================================================================== |
15 | 15 | """TensorBoard WSGI Application Logic. |
16 | 16 |
|
17 | | -TensorBoardApplication constructs TensorBoard as a WSGI application. |
18 | | -It handles serving static assets, and implements TensorBoard data APIs. |
| 17 | +Provides TensorBoardWSGIApp for building a TensorBoard WSGI app. |
19 | 18 | """ |
20 | 19 |
|
21 | 20 | from __future__ import absolute_import |
@@ -147,28 +146,54 @@ def standard_tensorboard_wsgi(flags, plugin_loaders, assets_zip_provider): |
147 | 146 | path_to_run = parse_event_files_spec(flags.logdir) |
148 | 147 | start_reloading_multiplexer( |
149 | 148 | multiplexer, path_to_run, reload_interval, flags.reload_task) |
| 149 | + return TensorBoardWSGIApp( |
| 150 | + flags, plugin_loaders, data_provider, assets_zip_provider, multiplexer) |
150 | 151 |
|
151 | | - db_uri = getattr(multiplexer, 'db_uri', None) |
152 | | - db_connection_provider = getattr(multiplexer, 'db_connection_provider', None) |
| 152 | + |
| 153 | +def TensorBoardWSGIApp( |
| 154 | + flags, |
| 155 | + plugins, |
| 156 | + data_provider=None, |
| 157 | + assets_zip_provider=None, |
| 158 | + deprecated_multiplexer=None): |
| 159 | + """Constructs a TensorBoard WSGI app from plugins and data providers. |
| 160 | +
|
| 161 | + Args: |
| 162 | + flags: An argparse.Namespace containing TensorBoard CLI flags. |
| 163 | + plugins: A list of TBLoader subclasses for the plugins to load. |
| 164 | + assets_zip_provider: See TBContext documentation for more information. |
| 165 | + data_provider: Instance of `tensorboard.data.provider.DataProvider`. May |
| 166 | + be `None` if `flags.generic_data` is set to `"false"` in which case |
| 167 | + `deprecated_multiplexer` must be passed instead. |
| 168 | + deprecated_multiplexer: Optional instance of EventMultiplexer to use |
| 169 | + for any plugins not yet enabled for the DataProvider API. Required if |
| 170 | + the data_provider argument is not passed. |
| 171 | +
|
| 172 | + Returns: |
| 173 | + A WSGI application that implements the TensorBoard backend. |
| 174 | + """ |
| 175 | + db_uri = getattr(deprecated_multiplexer, 'db_uri', None) |
| 176 | + db_connection_provider = getattr( |
| 177 | + deprecated_multiplexer, 'db_connection_provider', None) |
153 | 178 | plugin_name_to_instance = {} |
154 | 179 | context = base_plugin.TBContext( |
155 | 180 | data_provider=data_provider, |
156 | 181 | db_connection_provider=db_connection_provider, |
157 | 182 | db_uri=db_uri, |
158 | 183 | flags=flags, |
159 | 184 | logdir=flags.logdir, |
160 | | - multiplexer=multiplexer, |
| 185 | + multiplexer=deprecated_multiplexer, |
161 | 186 | assets_zip_provider=assets_zip_provider, |
162 | 187 | plugin_name_to_instance=plugin_name_to_instance, |
163 | 188 | window_title=flags.window_title) |
164 | | - plugins = [] |
165 | | - for loader in plugin_loaders: |
| 189 | + tbplugins = [] |
| 190 | + for loader in plugins: |
166 | 191 | plugin = loader.load(context) |
167 | 192 | if plugin is None: |
168 | 193 | continue |
169 | | - plugins.append(plugin) |
| 194 | + tbplugins.append(plugin) |
170 | 195 | plugin_name_to_instance[plugin.plugin_name] = plugin |
171 | | - return TensorBoardWSGI(plugins, flags.path_prefix) |
| 196 | + return TensorBoardWSGI(tbplugins, flags.path_prefix) |
172 | 197 |
|
173 | 198 |
|
174 | 199 | class TensorBoardWSGI(object): |
|
0 commit comments