From 28a4719b86cac6ccf2e4785fd2c389c923a1234a Mon Sep 17 00:00:00 2001 From: Tom Most Date: Tue, 23 Jul 2024 14:40:31 -0700 Subject: [PATCH] Restore the setuptools version hack --- _build_meta.py | 72 ------------------------------------- pyproject.toml | 3 ++ src/incremental/__init__.py | 4 +++ 3 files changed, 7 insertions(+), 72 deletions(-) diff --git a/_build_meta.py b/_build_meta.py index 3bd7659..a5bd38c 100644 --- a/_build_meta.py +++ b/_build_meta.py @@ -13,78 +13,6 @@ We comply by re-publishing setuptools' ``build_meta``. """ -import sys -from pathlib import Path - -if sys.version_info > (3, 11): - import tomllib -else: - import tomli as tomllib - -from importlib.metadata import Distribution, DistributionFinder - from setuptools import build_meta - -def _entry_points_txt(): - """ - Format the entry points from ``pyproject.toml`` as the INI-style - ``entry_points.txt`` used in package metadata. - """ - with open(Path(__file__).parent / "pyproject.toml", "rb") as f: - data = tomllib.load(f) - - lines = [] - for section, pairs in data["project"]["entry-points"].items(): - lines.append(f"[{section}]") - for key, value in pairs.items(): - lines.append(f"{key} = {value}") - lines.append("") - return "\n".join(lines) - - -class IncrementalEntryPoints(Distribution): - """ - A distribution that exposes the incremental entry points by by - reading them from ``pyproject.toml``. - """ - - def read_text(self, filename): - if filename == "METADATA": - return None - if filename == "PKG-INFO": - return ( - "Metadata-Version: 2.1\n" - "Name: incrementalbuildhack\n" - "Version: 0.0.0\n" - ) - if filename == "entry_points.txt": - return _entry_points_txt() - raise NotImplementedError(f"Can't synthesize {filename=}") - - def locate_file(self, path): - raise NotImplementedError(f"Can't locate_file({path=})") - - -class EntryPointInjector(DistributionFinder): - """ - Inject incremental's setuptools entry points so that - setuptools can find Incremental's own version. - """ - - def find_distributions(self, context): - if context.name is None: - yield IncrementalEntryPoints() - - # No-op abstract methods from importlib.abc.MetaPathFinder: - - def find_spec(self, fullname, path, target=None): - return None - - def invalidate_caches(self): - pass - - -sys.meta_path.insert(0, EntryPointInjector()) - __all__ = ["build_meta"] diff --git a/pyproject.toml b/pyproject.toml index d80bd8d..5882834 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,6 +51,9 @@ use_incremental = "incremental:_get_distutils_version" [project.entry-points."setuptools.finalize_distribution_options"] incremental = "incremental:_get_setuptools_version" +[tool.setuptools.dynamic] +version = {attr = "incremental._setuptools_version"} + [tool.incremental] [tool.black] diff --git a/src/incremental/__init__.py b/src/incremental/__init__.py index 9e89b8a..646bd88 100644 --- a/src/incremental/__init__.py +++ b/src/incremental/__init__.py @@ -517,4 +517,8 @@ def _load_pyproject_toml(toml_path): # type: (str) -> Optional[_IncrementalConf from ._version import __version__ # noqa: E402 +def _setuptools_version(): # type: () -> str + return __version__.public() + + __all__ = ["__version__", "Version", "getVersionString"]