Skip to content

Instantly share code, notes, and snippets.

@ajkerrigan
Last active January 6, 2022 18:51
Show Gist options
  • Select an option

  • Save ajkerrigan/bf4b01074ddb73d82a0564f7cf3388ab to your computer and use it in GitHub Desktop.

Select an option

Save ajkerrigan/bf4b01074ddb73d82a0564f7cf3388ab to your computer and use it in GitHub Desktop.
VisiData Automatic Plugin Import

VisiData Plugin Discovery / Automatic Import

This is an experimental Python snippet that can be used (such as from .visidatarc) to discover VisiData plugins based on entry points. The approach is inspired by the Pluggy framework, and specifically the entry point group naming that flake8 uses for plugin registration.

This means that you could pip-install a plugin package and VisiData would find and import it at startup. I've tested this by packaging up vds3 with poetry and using an entry point to map the plugin name to an importable module name.

from importlib import import_module
from visidata import vd
try:
from importlib import metadata
plugins = metadata.entry_points().select(group="visidata.plugin")
except (AttributeError, ImportError):
try:
# Required for selectable entry points prior to Python 3.10
# https://docs.python.org/3/library/importlib.metadata.html#entry-points
import importlib_metadata
plugins = importlib_metadata.entry_points().select(group="visidata.plugin")
except (ImportError, FileNotFoundError):
plugins = ()
for plugin in plugins:
vd.status(f"importing module {plugin.value} for plugin: {plugin.name}")
import_module(plugin.value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment