Skip to content

Commit

Permalink
Fix vizplugin multiple warning (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaogaotiantian authored Nov 13, 2022
1 parent 0466c3a commit 138269b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/viztracer/vizplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def __init__(self, tracer: "VizTracer", plugins: Sequence[Union[VizPluginBase, s
else:
raise TypeError("Invalid plugin!")
self._plugins.append(plugin_instance)

support_version = plugin_instance.support_version()
if compare_version(support_version, __version__) > 0:
color_print("WARNING", "The plugin support version is higher than "
"viztracer version. Consider update your viztracer")
self._send_message(plugin_instance, "event", {"when": "initialize"})

def _get_plugin_from_string(self, plugin: str) -> VizPluginBase:
Expand Down Expand Up @@ -102,9 +107,6 @@ def _send_message(self, plugin: VizPluginBase, m_type: str, payload: Dict) -> No
# in the future we may need to do version compatibility
# here
support_version = plugin.support_version()
if compare_version(support_version, __version__) > 0:
color_print("WARNING", "The plugin support version is higher than "
"viztracer version. Consider update your viztracer")

ret = plugin.message(m_type, payload)
if m_type == "command":
Expand Down
3 changes: 2 additions & 1 deletion tests/test_vizplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def test_version(self):
with redirect_stdout(s):
with VizTracer(plugins=[pl], verbose=0):
_ = []
self.assertIn("support version is higher", s.getvalue())
output = s.getvalue()
self.assertEqual(output.count("support version is higher"), 1)

def test_cmdline(self):
self.template(["viztracer", "--plugin", "tests.modules.dummy_vizplugin", "--", "cmdline_test.py"])
Expand Down

0 comments on commit 138269b

Please sign in to comment.