Skip to content

Commit

Permalink
perf: only load necessary plugins for cli
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Oct 31, 2024
1 parent faed339 commit c67063d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/ape/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def parse_args(self, ctx: "Context", args: list[str]) -> list[str]:

def format_commands(self, ctx, formatter) -> None:
from ape.plugins._utils import PluginMetadataList
from ape.utils.basemodel import ManagerAccessMixin as access

commands = []
for subcommand in self.list_commands(ctx):
Expand All @@ -86,8 +85,7 @@ def format_commands(self, ctx, formatter) -> None:
"Plugin": [],
"3rd-Party Plugin": [],
}
plugin_manager = access.plugin_manager
pl_metadata = PluginMetadataList.load(plugin_manager, include_available=False)
pl_metadata = PluginMetadataList.from_package_names(f"ape_{c[0]}" for c in commands)
for cli_name, cmd in commands:
help = cmd.get_short_help_str(limit)
plugin = pl_metadata.get_plugin(cli_name, check_available=False)
Expand Down
7 changes: 5 additions & 2 deletions src/ape/plugins/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from enum import Enum
from functools import cached_property
from shutil import which
from typing import Any, Optional
from typing import TYPE_CHECKING, Any, Optional
from urllib.parse import urlparse

import click
Expand All @@ -19,6 +19,9 @@
from ape.utils.misc import _get_distributions, get_package_version, log_instead_of_fail
from ape.version import version as ape_version_str

if TYPE_CHECKING:
from ape.managers.plugins import PluginManager

# Plugins maintained OSS by ApeWorX (and trusted)
# Use `uv pip` if installed, otherwise `python -m pip`
PIP_COMMAND = ["uv", "pip"] if which("uv") else [sys.executable, "-m", "pip"]
Expand Down Expand Up @@ -202,7 +205,7 @@ class PluginMetadataList(BaseModel):
third_party: "PluginGroup"

@classmethod
def load(cls, plugin_manager, include_available: bool = True):
def load(cls, plugin_manager: "PluginManager", include_available: bool = True):
plugins = plugin_manager.registered_plugins
if include_available:
plugins = plugins.union(github_client.available_plugins)
Expand Down

0 comments on commit c67063d

Please sign in to comment.