diff --git a/src/ape/managers/plugins.py b/src/ape/managers/plugins.py index 0d57635924..3f523d7d4a 100644 --- a/src/ape/managers/plugins.py +++ b/src/ape/managers/plugins.py @@ -4,10 +4,10 @@ from ape.exceptions import ApeAttributeError from ape.logging import logger -from ape.plugins._utils import CORE_PLUGINS, _filter_plugins_from_dists, clean_plugin_name +from ape.plugins._utils import CORE_PLUGINS, clean_plugin_name, get_plugin_dists from ape.plugins.pluggy_patch import plugin_manager as pluggy_manager from ape.utils.basemodel import _assert_not_ipython_check, only_raise_attribute_error -from ape.utils.misc import _get_distributions, log_instead_of_fail +from ape.utils.misc import log_instead_of_fail def valid_impl(api_class: Any) -> bool: @@ -122,18 +122,15 @@ def _register_plugins(self): if self.__registered: return - plugins = list( - {n.replace("-", "_") for n in _filter_plugins_from_dists(_get_distributions())} - ) - locals = [p for p in CORE_PLUGINS if p != "ape"] - plugin_modules = tuple([*plugins, *locals]) + plugins = list({n.replace("-", "_") for n in get_plugin_dists()}) + plugin_modules = tuple([*plugins, *CORE_PLUGINS]) for module_name in plugin_modules: try: module = importlib.import_module(module_name) pluggy_manager.register(module) except Exception as err: - if module_name in CORE_PLUGINS: + if module_name in CORE_PLUGINS or module_name == "ape": # Always raise core plugin registration errors. raise diff --git a/src/ape/plugins/_utils.py b/src/ape/plugins/_utils.py index 7db6b82311..43d98eb666 100644 --- a/src/ape/plugins/_utils.py +++ b/src/ape/plugins/_utils.py @@ -3,7 +3,6 @@ from collections.abc import Iterable, Iterator, Sequence from enum import Enum from functools import cached_property -from pathlib import Path from shutil import which from typing import Any, Optional @@ -25,12 +24,18 @@ PIP_COMMAND = ["uv", "pip"] if which("uv") else [sys.executable, "-m", "pip"] PLUGIN_PATTERN = re.compile(r"\bape_\w+(?!\S)") CORE_PLUGINS = [ - "ape", - *[ - f.name - for f in Path(__file__).parent.parent.parent.iterdir() - if f.name.startswith("ape_") and f.is_dir() and re.match(PLUGIN_PATTERN, f.name) - ], + "ape_accounts", + "ape_cache", + "ape_compile", + "ape_console", + "ape_ethereum", + "ape_node", + "ape_init", + "ape_networks", + "ape_plugins", + "ape_pm", + "ape_run", + "ape_test", ] @@ -38,6 +43,10 @@ def clean_plugin_name(name: str) -> str: return name.replace("_", "-").replace("ape-", "") +def get_plugin_dists(): + return _filter_plugins_from_dists(_get_distributions()) + + def _filter_plugins_from_dists(dists: Iterable) -> Iterator[str]: for dist in dists: if name := getattr(dist, "name", ""): @@ -384,7 +393,7 @@ def check_installed(self, use_cache: bool = True) -> bool: if not use_cache: _get_distributions.cache_clear() - return any(n == self.package_name for n in _filter_plugins_from_dists(_get_distributions())) + return any(n == self.package_name for n in get_plugin_dists()) def _prepare_install( self, upgrade: bool = False, skip_confirmation: bool = False diff --git a/src/ape_plugins/_cli.py b/src/ape_plugins/_cli.py index 9bdc23dbe7..60e563e419 100644 --- a/src/ape_plugins/_cli.py +++ b/src/ape_plugins/_cli.py @@ -15,10 +15,10 @@ PluginMetadata, PluginMetadataList, PluginType, - _filter_plugins_from_dists, ape_version, + get_plugin_dists, ) -from ape.utils.misc import _get_distributions, load_config +from ape.utils.misc import load_config @click.group(short_help="Manage ape plugins") @@ -273,7 +273,7 @@ def _change_version(spec: str): # NOTE: It is possible plugins may depend on each other and may update in # an order causing some error codes to pop-up, so we ignore those for now. plugin_retcode = 0 - for plugin in _filter_plugins_from_dists(_get_distributions()): + for plugin in get_plugin_dists(): logger.info(f"Updating {plugin} ...") name = plugin.split("=")[0].strip() retcode = _install(name, spec, exit_on_fail=False) diff --git a/tests/functional/test_plugins.py b/tests/functional/test_plugins.py index 825004ea51..89b9531aa3 100644 --- a/tests/functional/test_plugins.py +++ b/tests/functional/test_plugins.py @@ -6,6 +6,7 @@ from ape.exceptions import PluginVersionError from ape.logging import LogLevel from ape.managers.plugins import _get_unimplemented_methods_warning +from ape.plugins._utils import CORE_PLUGINS as CORE_PLUGINS_LIST from ape.plugins._utils import ( ApePluginsRepr, ModifyPluginResultHandler, @@ -388,3 +389,11 @@ def test_get_unimplemented_methods_warning_list_containing_plugin(abstract_metho "Remaining abstract methods: 'serialize_transaction, txn_hash'." ) assert actual == expected + + +def test_core_plugins(): + # In case any of these happen to be installed, and this feature + # is broken, it will fail. If none are installed, the test will always pass. + non_core_plugins = ("ape_arbitrum", "ape_vyper", "ape_solidity", "ape_ens") + assert not any(p in CORE_PLUGINS_LIST for p in non_core_plugins) + assert "ape_ethereum" in CORE_PLUGINS_LIST