Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make the dependency manager accessible on ManagerAccessMixin #2233

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading