Skip to content

Commit

Permalink
feat: make the dependency manager accessible on ManagerAccessMixin (A…
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Aug 22, 2024
1 parent 6d9a0a3 commit b6216a5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/ape/utils/basemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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())
Expand All @@ -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):
"""
Expand Down
6 changes: 3 additions & 3 deletions src/ape_pm/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/utils/test_basemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)

0 comments on commit b6216a5

Please sign in to comment.