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

refactor: drop _Dispatcher #106

Merged
merged 1 commit into from
Oct 20, 2023
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
20 changes: 5 additions & 15 deletions craft_application/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"""Main application classes for a craft-application."""
from __future__ import annotations

import argparse
import functools
import importlib
import os
Expand Down Expand Up @@ -44,15 +43,6 @@
)


class _Dispatcher(craft_cli.Dispatcher):
"""Application command dispatcher."""

@property
def parsed_args(self) -> argparse.Namespace:
"""The map of parsed command-line arguments."""
return self._parsed_command_args or argparse.Namespace()


@dataclass(frozen=True)
class AppFeatures:
"""Specific features that can be enabled/disabled per-application."""
Expand Down Expand Up @@ -247,7 +237,7 @@ def run_managed(self, platform: str | None, build_for: str | None) -> None:
def configure(self, global_args: dict[str, Any]) -> None:
"""Configure the application using any global arguments."""

def _get_dispatcher(self) -> _Dispatcher:
def _get_dispatcher(self) -> craft_cli.Dispatcher:
"""Configure this application. Should be called by the run method.

Side-effect: This method may exit the process.
Expand All @@ -262,7 +252,7 @@ def _get_dispatcher(self) -> _Dispatcher:
streaming_brief=True,
)

dispatcher = _Dispatcher(
dispatcher = craft_cli.Dispatcher(
self.app.name,
self.command_groups,
summary=str(self.app.summary),
Expand Down Expand Up @@ -327,11 +317,11 @@ def run(self) -> int: # noqa: PLR0912 (too many branches due to error handling)
}
),
)
platform = getattr(dispatcher.parsed_args, "platform", None)
build_for = getattr(dispatcher.parsed_args, "build_for", None)
platform = getattr(dispatcher.parsed_args(), "platform", None)
build_for = getattr(dispatcher.parsed_args(), "build_for", None)
self._configure_services(platform, build_for)

if not command.run_managed(dispatcher.parsed_args):
if not command.run_managed(dispatcher.parsed_args()):
# command runs in the outer instance
craft_cli.emit.debug(f"Running {self.app.name} {command.name} on host")
if command.always_load_project:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "craft-application"
description = "A framework for *craft applications."
dynamic = ["version", "readme"]
dependencies = [
"craft-cli>=2.0.0",
"craft-cli>=2.3.0",
"craft-parts>=1.21.1",
"craft-providers>=1.14.0,<2.0",
"pydantic>=1.10,<2.0",
Expand Down
6 changes: 2 additions & 4 deletions tests/unit/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ def app(app_metadata, fake_services):

@pytest.fixture()
def mock_dispatcher(monkeypatch):
dispatcher = mock.Mock(spec_set=application._Dispatcher)
monkeypatch.setattr(
"craft_application.application._Dispatcher", mock.Mock(return_value=dispatcher)
)
dispatcher = mock.Mock(spec_set=craft_cli.Dispatcher)
monkeypatch.setattr("craft_cli.Dispatcher", mock.Mock(return_value=dispatcher))
return dispatcher


Expand Down
Loading