Skip to content

Commit

Permalink
Merge pull request #922 from RonnyPfannschmidt/fix-914-add-shim-for-l…
Browse files Browse the repository at this point in the history
…egacy-plugins

fix #914: ignore the deprecated git archival plugin
  • Loading branch information
RonnyPfannschmidt committed Sep 21, 2023
2 parents 9d6ab45 + d67d61c commit 4bc06ac
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ v8.0.2

bugfix
------

* fix #914: ignore the deprecated git archival plugin as its integrated now
* fix #912: ensure mypy safety of the version template + regression test
* fix #913: use 240s timeout instead of 20 for git unshallow
to account for large repos or slow connections
Expand Down
2 changes: 2 additions & 0 deletions src/setuptools_scm/_entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

class EntrypointProtocol(Protocol):
name: str
value: str

def load(self) -> Any:
pass
Expand Down Expand Up @@ -61,6 +62,7 @@ def iter_entry_points(
name=name,
)
)

return cast(Iterator[EntrypointProtocol], iter(res))


Expand Down
6 changes: 6 additions & 0 deletions src/setuptools_scm/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def match_entrypoint(root: _t.PathT, name: str) -> bool:
return False


# blocked entrypints from legacy plugins
_BLOCKED_EP_TARGETS = {"setuptools_scm_git_archive:parse"}


def iter_matching_entrypoints(
root: _t.PathT, entrypoint: str, config: Configuration
) -> Iterable[_entrypoints.EntrypointProtocol]:
Expand All @@ -57,6 +61,8 @@ def iter_matching_entrypoints(

for wd in walk_potential_roots(root, config.search_parent_directories):
for ep in iter_entry_points(entrypoint):
if ep.value in _BLOCKED_EP_TARGETS:
continue
if match_entrypoint(wd, ep.name):
log.debug("found ep %s in %s", ep, wd)
config.parent = wd
Expand Down
22 changes: 22 additions & 0 deletions testing/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import importlib.metadata
import sys
import textwrap
from pathlib import Path
Expand All @@ -8,11 +9,14 @@

import setuptools_scm._integration.setuptools
from .wd_wrapper import WorkDir
from setuptools_scm import Configuration
from setuptools_scm._integration.setuptools import _warn_on_old_setuptools
from setuptools_scm._overrides import PRETEND_KEY
from setuptools_scm._overrides import PRETEND_KEY_NAMED
from setuptools_scm._run_cmd import run

c = Configuration()


@pytest.fixture
def wd(wd: WorkDir) -> WorkDir:
Expand Down Expand Up @@ -183,3 +187,21 @@ def test_setuptools_version_keyword_ensures_regex(

dist = setuptools.Distribution({"name": "test"})
version_keyword(dist, "use_scm_version", {"tag_regex": "(1.0)"})


@pytest.mark.parametrize(
"ep_name", ["setuptools_scm.parse_scm", "setuptools_scm.parse_scm_fallback"]
)
def test_git_archival_plugin_ignored(tmp_path: Path, ep_name: str) -> None:
tmp_path.joinpath(".git_archival.txt").write_text("broken")
try:
dist = importlib.metadata.distribution("setuptools_scm_git_archive")
except importlib.metadata.PackageNotFoundError:
pytest.skip("setuptools_scm_git_archive not installed")
else:
print(dist.metadata["Name"], dist.version)
from setuptools_scm.discover import iter_matching_entrypoints

found = list(iter_matching_entrypoints(tmp_path, config=c, entrypoint=ep_name))
imports = [item.value for item in found]
assert "setuptools_scm_git_archive:parse" not in imports

0 comments on commit 4bc06ac

Please sign in to comment.