Skip to content

fix #1131: allow self-build without importlib_metadata #1132

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

Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v8.3.1

### Fixed

- fixed #1131: allow self-build without importlib_metadata avaliable on python3.9

## v8.3.0

### Fixed
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ build-backend = "_own_version_helper:build_meta"
requires = [
"setuptools>=61",
'tomli<=2.0.2; python_version < "3.11"',
'importlib-metadata>=4.6; python_version < "3.10"',
]
backend-path = [
".",
Expand Down
25 changes: 19 additions & 6 deletions src/setuptools_scm/_entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,33 @@
from . import _log
from . import version

__all__ = [
"entry_points",
"im",
]
if TYPE_CHECKING:
from . import _types as _t
from ._config import Configuration
from ._config import ParseFunction

if sys.version_info[:2] < (3, 10):
from importlib_metadata import EntryPoint as EntryPoint
from importlib_metadata import entry_points as entry_points
else:
from importlib.metadata import EntryPoint as EntryPoint
from importlib.metadata import entry_points as entry_points
if sys.version_info[:2] < (3, 10):
import importlib_metadata as im
else:
from importlib import metadata as im


log = _log.log.getChild("entrypoints")


def entry_points(**kw: Any) -> im.EntryPoints:
if sys.version_info[:2] < (3, 10):
import importlib_metadata as im
else:
import importlib.metadata as im

return im.entry_points(**kw)


def version_from_entrypoint(
config: Configuration, *, entrypoint: str, root: _t.PathT
) -> version.ScmVersion | None:
Expand All @@ -52,6 +63,8 @@ def _get_ep(group: str, name: str) -> Any | None:

def _get_from_object_reference_str(path: str, group: str) -> Any | None:
# todo: remove for importlib native spelling
from importlib.metadata import EntryPoint # hack

ep = EntryPoint(path, path, group)
try:
return ep.load()
Expand Down
3 changes: 1 addition & 2 deletions src/setuptools_scm/_file_finders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from .. import _log
from .. import _types as _t
from .._entrypoints import EntryPoint
from .._entrypoints import entry_points
from .pathtools import norm_real

Expand Down Expand Up @@ -102,7 +101,7 @@ def is_toplevel_acceptable(toplevel: str | None) -> TypeGuard[str]:


def find_files(path: _t.PathT = "") -> list[str]:
eps: list[EntryPoint] = [
eps = [
*entry_points(group="setuptools_scm.files_command"),
*entry_points(group="setuptools_scm.files_command_fallback"),
]
Expand Down
7 changes: 6 additions & 1 deletion src/setuptools_scm/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os

from pathlib import Path
from typing import TYPE_CHECKING
from typing import Iterable
from typing import Iterator

Expand All @@ -11,6 +12,10 @@
from . import _types as _t
from ._config import Configuration

if TYPE_CHECKING:
from ._entrypoints import im


log = _log.log.getChild("discover")


Expand Down Expand Up @@ -48,7 +53,7 @@ def match_entrypoint(root: _t.PathT, name: str) -> bool:

def iter_matching_entrypoints(
root: _t.PathT, entrypoint: str, config: Configuration
) -> Iterable[_entrypoints.EntryPoint]:
) -> Iterable[im.EntryPoint]:
"""
Consider different entry-points in ``root`` and optionally its parents.
:param root: File path.
Expand Down
Loading