From 9a3b33b3c26bfe0e52f52b3ad425b7ef83433c99 Mon Sep 17 00:00:00 2001 From: Sheng Yu Date: Thu, 18 Jan 2024 11:04:04 -0500 Subject: [PATCH] refactor: use craft-application plugins register --- requirements-dev.txt | 2 +- requirements.txt | 2 +- rockcraft/application.py | 7 +++++ rockcraft/cli.py | 5 ---- rockcraft/plugins/__init__.py | 3 +-- rockcraft/plugins/register.py | 26 ------------------- .../integration/plugins/test_python_plugin.py | 3 ++- 7 files changed, 12 insertions(+), 36 deletions(-) delete mode 100644 rockcraft/plugins/register.py diff --git a/requirements-dev.txt b/requirements-dev.txt index 34bded355..168228dd5 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -14,7 +14,7 @@ click==8.1.7 codespell==2.2.6 colorama==0.4.6 coverage==7.4.0 -craft-application==1.2.0 +craft-application @ git+https://github.com/canonical/craft-application@CRAFT-2401-support-plugins craft-archives==1.1.3 craft-cli==2.5.0 craft-parts==1.26.1 diff --git a/requirements.txt b/requirements.txt index 3f243fb33..5166812c7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ certifi==2023.11.17 charset-normalizer==3.3.2 -craft-application==1.2.0 +craft-application @ git+https://github.com/canonical/craft-application@CRAFT-2401-support-plugins craft-archives==1.1.3 craft-cli==2.5.0 craft-parts==1.26.1 diff --git a/rockcraft/application.py b/rockcraft/application.py index d933a0022..006f9dcd9 100644 --- a/rockcraft/application.py +++ b/rockcraft/application.py @@ -19,10 +19,12 @@ from typing import Any from craft_application import Application, AppMetadata, util +from craft_parts.plugins.plugins import PluginType from overrides import override # type: ignore[reportUnknownVariableType] from rockcraft import models from rockcraft.models import project +from rockcraft.plugins.python_plugin import PythonPlugin APP_METADATA = AppMetadata( name="rockcraft", @@ -35,6 +37,11 @@ class Rockcraft(Application): """Rockcraft application definition.""" + @override + def _get_app_plugins(self) -> dict[str, PluginType]: + """Register Rockcraft plugins.""" + return {"python": PythonPlugin} + @override def _extra_yaml_transform(self, yaml_data: dict[str, Any]) -> dict[str, Any]: return models.transform_yaml(self._work_dir, yaml_data) diff --git a/rockcraft/cli.py b/rockcraft/cli.py index 98fe3595a..077cafc31 100644 --- a/rockcraft/cli.py +++ b/rockcraft/cli.py @@ -19,8 +19,6 @@ import logging from typing import TYPE_CHECKING -from rockcraft import plugins - from . import commands from .services import RockcraftServiceFactory @@ -30,9 +28,6 @@ def run() -> int: """Command-line interface entrypoint.""" - # Register our own plugins - plugins.register() - # set lib loggers to debug level so that all messages are sent to Emitter for lib_name in ("craft_providers", "craft_parts"): logger = logging.getLogger(lib_name) diff --git a/rockcraft/plugins/__init__.py b/rockcraft/plugins/__init__.py index e90b77a72..714276d02 100644 --- a/rockcraft/plugins/__init__.py +++ b/rockcraft/plugins/__init__.py @@ -17,6 +17,5 @@ """Rockcraft-specific plugins.""" from .python_plugin import PythonPlugin -from .register import register -__all__ = ["PythonPlugin", "register"] +__all__ = ["PythonPlugin"] diff --git a/rockcraft/plugins/register.py b/rockcraft/plugins/register.py deleted file mode 100644 index 624f87f80..000000000 --- a/rockcraft/plugins/register.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- -# -# Copyright 2022 Canonical Ltd. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 3 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -"""Rockcraft-provided plugin registration.""" - -import craft_parts - -from .python_plugin import PythonPlugin - - -def register() -> None: - """Register Rockcraft plugins.""" - craft_parts.plugins.register({"python": PythonPlugin}) diff --git a/tests/integration/plugins/test_python_plugin.py b/tests/integration/plugins/test_python_plugin.py index 052891127..71fdf8a16 100644 --- a/tests/integration/plugins/test_python_plugin.py +++ b/tests/integration/plugins/test_python_plugin.py @@ -18,6 +18,7 @@ from dataclasses import dataclass from pathlib import Path +import craft_parts.plugins import pytest from craft_application import errors from craft_cli import EmitterMode, emit @@ -44,7 +45,7 @@ def setup_python_test(monkeypatch): # Keep craft-parts from trying to refresh apt's cache, so that we can run # this test as regular users. monkeypatch.setenv("CRAFT_PARTS_PACKAGE_REFRESH", "0") - plugins.register() + craft_parts.plugins.register({"python": plugins.PythonPlugin}) def create_python_project(base, extra_part_props=None) -> Project: