diff --git a/src/ape/utils/basemodel.py b/src/ape/utils/basemodel.py index 0b15e2344a..cc7d9f29d9 100644 --- a/src/ape/utils/basemodel.py +++ b/src/ape/utils/basemodel.py @@ -23,7 +23,7 @@ from ape.managers.converters import ConversionManager from ape.managers.networks import NetworkManager from ape.managers.plugins import PluginManager - from ape.managers.project import ProjectManager + from ape.managers.project import DependencyManager, ProjectManager from ape.managers.query import QueryManager from ape.pytest.runners import PytestApeRunner @@ -121,12 +121,12 @@ class ManagerAccessMixin: "ConversionManager", injected_before_use() ) + local_project: ClassVar["ProjectManager"] = cast("ProjectManager", injected_before_use()) + network_manager: ClassVar["NetworkManager"] = cast("NetworkManager", injected_before_use()) plugin_manager: ClassVar["PluginManager"] = cast("PluginManager", injected_before_use()) - local_project: ClassVar["ProjectManager"] = cast("ProjectManager", injected_before_use()) - Project: ClassVar[type["ProjectManager"]] = cast(type["ProjectManager"], injected_before_use()) query_manager: ClassVar["QueryManager"] = cast("QueryManager", injected_before_use()) @@ -150,6 +150,12 @@ def provider(cls) -> "ProviderAPI": raise ProviderNotConnectedError() + @classproperty + def dependency_manager(cls) -> "DependencyManager": + # We make this available for more intuitive access to + # global dependencies, which any project has access to. + return cls.local_project.dependencies + class BaseInterface(ManagerAccessMixin, ABC): """ diff --git a/src/ape_pm/_cli.py b/src/ape_pm/_cli.py index ec26a6d024..cde4a65512 100644 --- a/src/ape_pm/_cli.py +++ b/src/ape_pm/_cli.py @@ -26,11 +26,11 @@ def _list(cli_ctx, list_all): List installed packages """ - pm = cli_ctx.local_project + dm = cli_ctx.dependency_manager packages = [] - dependencies = [*list(pm.dependencies.specified)] + dependencies = [*list(dm.specified)] if list_all: - dependencies = list({*dependencies, *pm.dependencies.installed}) + dependencies = list({*dependencies, *dm.installed}) for dependency in dependencies: try: diff --git a/tests/functional/utils/test_basemodel.py b/tests/functional/utils/test_basemodel.py index 105c9d76ba..cd7392398e 100644 --- a/tests/functional/utils/test_basemodel.py +++ b/tests/functional/utils/test_basemodel.py @@ -2,6 +2,7 @@ from ape.exceptions import ProviderNotConnectedError from ape.logging import logger +from ape.managers.project import DependencyManager from ape.utils.basemodel import ManagerAccessMixin, only_raise_attribute_error @@ -50,3 +51,8 @@ def fn(): # Does not log because is already an attr err assert not spy.call_count + + +def test_dependency_manager(): + actual = ManagerAccessMixin.dependency_manager + assert isinstance(actual, DependencyManager)