Skip to content

Commit

Permalink
handle shadowed plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
brimoor committed Jan 5, 2025
1 parent 199872a commit d697f93
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 66 deletions.
7 changes: 5 additions & 2 deletions docs/source/cli/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1239,14 +1239,14 @@ List plugins that are installed locally.

.. code-block:: text
fiftyone plugins info [-h] NAME
fiftyone plugins info [-h] NAME_OR_DIR
**Arguments**

.. code-block:: text
positional arguments:
NAME the plugin name
NAME_OR_DIR the plugin name or directory
optional arguments:
-h, --help show this help message and exit
Expand All @@ -1258,6 +1258,9 @@ List plugins that are installed locally.
# Prints information about a plugin
fiftyone plugins info <name>
# Prints information about a plugin in a given directory
fiftyone plugins info <dir>
.. _cli-fiftyone-plugins-download:

Download plugins
Expand Down
51 changes: 42 additions & 9 deletions fiftyone/core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3596,7 +3596,9 @@ def execute(parser, args):


def _print_plugins_list(enabled, builtin, names_only):
plugin_defintions = fop.list_plugins(enabled=enabled, builtin=builtin)
plugin_defintions = fop.list_plugins(
enabled=enabled, builtin=builtin, shadowed="all"
)

if names_only:
for pd in plugin_defintions:
Expand All @@ -3606,19 +3608,37 @@ def _print_plugins_list(enabled, builtin, names_only):

enabled_plugins = set(fop.list_enabled_plugins())

headers = ["plugin", "version", "enabled", "builtin", "directory"]
shadowed_paths = set()
for pd in plugin_defintions:
if pd.shadow_paths:
shadowed_paths.update(pd.shadow_paths)

headers = [
"plugin",
"version",
"enabled",
"builtin",
"shadowed",
"directory",
]
rows = []
for pd in plugin_defintions:
shadowed = pd.directory in shadowed_paths
enabled = (pd.builtin or pd.name in enabled_plugins) and not shadowed
rows.append(
{
"plugin": pd.name,
"version": pd.version or "",
"enabled": pd.builtin or pd.name in enabled_plugins,
"enabled": enabled,
"builtin": pd.builtin,
"shadowed": shadowed,
"directory": pd.directory,
}
)

if not shadowed_paths:
headers.remove("shadowed")

records = [tuple(_format_cell(r[key]) for key in headers) for r in rows]

table_str = tabulate(records, headers=headers, tablefmt=_TABLE_FORMAT)
Expand All @@ -3632,22 +3652,35 @@ class PluginsInfoCommand(Command):
# Prints information about a plugin
fiftyone plugins info <name>
# Prints information about a plugin in a given directory
fiftyone plugins info <dir>
"""

@staticmethod
def setup(parser):
parser.add_argument("name", metavar="NAME", help="the plugin name")
parser.add_argument(
"name_or_dir",
metavar="NAME_OR_DIR",
help="the plugin name or directory",
)

@staticmethod
def execute(parser, args):
_print_plugin_info(args.name)
_print_plugin_info(args.name_or_dir)


def _print_plugin_info(name):
plugin_defintion = fop.get_plugin(name)
def _print_plugin_info(name_or_dir):
try:
pd = fop.get_plugin(name_or_dir)
except:
if os.path.isdir(name_or_dir):
pd = fop.get_plugin(plugin_dir=name_or_dir)
else:
raise

d = plugin_defintion.to_dict()
d["directory"] = plugin_defintion.directory
d = pd.to_dict()
d["directory"] = pd.directory
_print_dict_as_table(d)


Expand Down
Loading

0 comments on commit d697f93

Please sign in to comment.