Skip to content

Commit

Permalink
Remove plugin type and register individual hook
Browse files Browse the repository at this point in the history
Signed-off-by: Facundo Tuesca <[email protected]>
  • Loading branch information
facutuesca committed Nov 8, 2024
1 parent 88688a8 commit 9c9633f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/pip_plugin_pep740/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
17 changes: 3 additions & 14 deletions src/pip_plugin_pep740/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

from json import JSONDecodeError
from typing import TYPE_CHECKING, Literal

import requests
import rfc3986
Expand All @@ -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"):
Expand Down Expand Up @@ -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:
Expand All @@ -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
5 changes: 1 addition & 4 deletions test/test_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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

0 comments on commit 9c9633f

Please sign in to comment.