Created
July 26, 2022 05:09
-
-
Save ajkerrigan/58cc84e6b7b8842329dbb6ae3f19a5e9 to your computer and use it in GitHub Desktop.
Load VisiData Plugins using Entry Points
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # sample poetry plugin section (which equates to setup.py entry point) | |
| # extracted from https://github.com/ajkerrigan/visidata-plugins/pull/17/files#diff-4335f179817b92f616b8895564efdcb417ef24644176089a2a4be9d213768c2fR20-R21 | |
| # map a plugin name to the importable module that implements it | |
| [tool.poetry.plugins."visidata.plugin"] | |
| "vds3" = "visidata_s3" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # sample visidatrc snippet to find and load visidata plugin modules that define a `visidata.plugin` entry point | |
| 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