From 9c9633fd0d395e170797ce9ac715ffa32854e130 Mon Sep 17 00:00:00 2001 From: Facundo Tuesca Date: Fri, 8 Nov 2024 18:06:13 +0100 Subject: [PATCH] Remove plugin type and register individual hook Signed-off-by: Facundo Tuesca --- src/pip_plugin_pep740/__init__.py | 4 ++-- src/pip_plugin_pep740/_impl.py | 17 +++-------------- test/test_impl.py | 5 +---- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/pip_plugin_pep740/__init__.py b/src/pip_plugin_pep740/__init__.py index 5e5e43c..22ba5cd 100644 --- a/src/pip_plugin_pep740/__init__.py +++ b/src/pip_plugin_pep740/__init__.py @@ -2,6 +2,6 @@ __version__ = "0.0.1" -from ._impl import plugin_type, pre_download, pre_extract +from ._impl import pre_download, provided_hooks -__all__ = ["plugin_type", "pre_extract", "pre_download"] +__all__ = ["provided_hooks", "pre_download"] diff --git a/src/pip_plugin_pep740/_impl.py b/src/pip_plugin_pep740/_impl.py index 904895f..348a86b 100644 --- a/src/pip_plugin_pep740/_impl.py +++ b/src/pip_plugin_pep740/_impl.py @@ -3,7 +3,6 @@ from __future__ import annotations from json import JSONDecodeError -from typing import TYPE_CHECKING, Literal import requests import rfc3986 @@ -16,11 +15,6 @@ ) from rfc3986 import builder -if TYPE_CHECKING: - from pathlib import Path # pragma: no cover - -PluginType = Literal["dist-inspector"] - def _get_provenance_url(filename: str, index_host: str) -> str | None: if filename.endswith(".tar.gz"): @@ -101,9 +95,9 @@ def _get_provenance(filename: str, url: str) -> Provenance | None: raise ValueError(msg) from e -def plugin_type() -> PluginType: - """Return the plugin type.""" - return "dist-inspector" +def provided_hooks() -> list[str]: + """Return the hooks we want to register.""" + return ["pre_download"] def pre_download(url: str, filename: str, digest: str) -> None: @@ -125,8 +119,3 @@ def pre_download(url: str, filename: str, digest: str) -> None: msg = f"Provenance failed verification: {e}" raise ValueError(msg) from e return - - -def pre_extract(dist: Path) -> None: # noqa: ARG001 - """Check before extraction.""" - return diff --git a/test/test_impl.py b/test/test_impl.py index 0398788..6dcc247 100644 --- a/test/test_impl.py +++ b/test/test_impl.py @@ -32,7 +32,7 @@ class TestPlugin: def test_plugin_type(self) -> None: - assert pip_plugin_pep740.plugin_type() == "dist-inspector" + assert pip_plugin_pep740.provided_hooks() == ["pre_download"] @pytest.mark.parametrize( ("filename", "provenance_file", "digest"), @@ -254,6 +254,3 @@ def test_pre_download_malformed_provenance_valid_json(self) -> None: filename=DIST_FILE_1.name, digest=DIST_DIGEST_1, ) - - def test_pre_extract(self) -> None: - assert pip_plugin_pep740.pre_extract(dist=Path("filename")) is None