Skip to content

Commit bd6c2b0

Browse files
committed
plugins: add initializer on base plugin class
Summary: Prior to this change, defining a (possibly dynamically loaded) plugin without this initializer would yield the rather inscrutable error ``` File "/VIRTUAL_ENV/tensorboard/plugins/base_plugin.py", line 253, in load return self._plugin_class(context) TypeError: object() takes no parameters ``` whose stack trace does not contain the offending plugin code at all. (The error is because initializers are effectively inherited in Python.) Test Plan: Cherry-pick #2354, delete its example plugin’s `__init__`, and note that the example still works. (You’ll have to build TensorBoard’s Pip package and install it into a virtualenv.) wchargin-branch: plugin-empty-initializer
1 parent 1cbac0b commit bd6c2b0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tensorboard/plugins/base_plugin.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class TBPlugin(object):
6767
6868
Every plugin must extend from this class.
6969
70-
Subclasses must have a trivial constructor that takes a TBContext
70+
Subclasses should have a trivial constructor that takes a TBContext
7171
argument. Any operation that might throw an exception should either be
7272
done lazily or made safe with a TBLoader subclass, so the plugin won't
7373
negatively impact the rest of TensorBoard.
@@ -83,6 +83,17 @@ class TBPlugin(object):
8383

8484
plugin_name = None
8585

86+
def __init__(self, context):
87+
"""Initializes this plugin.
88+
89+
The default implementation does nothing. Subclasses are encouraged
90+
to override this and save any necessary fields from the `context`.
91+
92+
Args:
93+
context: A `base_plugin.TBContext` object.
94+
"""
95+
pass
96+
8697
@abstractmethod
8798
def get_plugin_apps(self):
8899
"""Returns a set of WSGI applications that the plugin implements.

0 commit comments

Comments
 (0)