Skip to content
Draft
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
27 changes: 13 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ between ``setuptools-git-versioning`` and other tools.

- Only Git v2 is supported

- Setuptools and `scikit-build-core <https://scikit-build-core.readthedocs.io>`_ build backends are
supported (no Poetry & others)
- Setuptools and build backends supporting `dynamic-metadata <https://dynamic-metadata.readthedocs.io>`_
(e.g. `scikit-build-core <https://scikit-build-core.readthedocs.io>`_ 1.0+) are supported.

- Currently does not support automatic exporting of package version to a file for runtime use
(but you can use ``setuptools-git-versioning > file`` redirect instead)
Expand Down Expand Up @@ -144,30 +144,29 @@ and then add new argument ``setuptools_git_versioning`` with config options:

Commands are the same as above, plus ``python -m setup.py`` returns the same version.

``scikit-build-core``
~~~~~~~~~~~~~~~~~~~~~
``dynamic-metadata``
~~~~~~~~~~~~~~~~~~~~

If your project uses the `scikit-build-core <https://scikit-build-core.readthedocs.io>`_ build backend,
add ``setuptools-git-versioning`` to ``build-system.requires``,
mark the ``version`` field as dynamic,
register the dynamic-metadata provider,
and configure options under the usual ``[tool.setuptools-git-versioning]`` section:
For build backends supporting `dynamic-metadata <https://dynamic-metadata.readthedocs.io>`_ 0.4+,
select the registered provider in ``[[tool.dynamic-metadata]]``. For example, with
`scikit-build-core <https://scikit-build-core.readthedocs.io>`_ 1.0+:

.. code:: toml

[build-system]
requires = [ "scikit-build-core", "setuptools-git-versioning>=3.0,<4", ]
requires = [ "scikit-build-core>=1.0", "dynamic-metadata>=0.4", "setuptools-git-versioning>=3.0,<4", ]
build-backend = "scikit_build_core.build"

[project]
name = "mypackage"
dynamic = ["version"]

[tool.scikit-build.metadata.version]
provider = "setuptools_git_versioning.scikit_metadata"
[[tool.dynamic-metadata]]
provider = "setuptools_git_versioning.dynamic_metadata"

[tool.setuptools-git-versioning]
enabled = true

All options under ``[tool.setuptools-git-versioning]`` work exactly as the for ``setuptools`` backend.
Inline configuration under ``[tool.scikit-build.metadata.version]`` is not supported.
The provider sets only ``version`` and reads options from ``[tool.setuptools-git-versioning]``.
Inline settings in ``[[tool.dynamic-metadata]]`` are not supported.
The provider itself has no runtime dependency on ``dynamic-metadata``.
1 change: 1 addition & 0 deletions docs/changelog/next_release/161.deprecation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecated the ``setuptools_git_versioning.scikit_metadata`` provider. Migrate to ``[[tool.dynamic-metadata]]`` with ``provider = "setuptools_git_versioning.dynamic_metadata"`` on scikit-build-core 1.0+ or another compatible backend.
1 change: 1 addition & 0 deletions docs/changelog/next_release/161.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for ``dynamic-metadata`` 0.4+ through the ``setuptools_git_versioning.dynamic_metadata`` provider. This enables automatic versioning with scikit-build-core 1.0+ and other compatible backends.
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ setuptools_git_versioning = "setuptools_git_versioning:infer_version"
[project.entry-points."console_scripts"]
setuptools-git-versioning = "setuptools_git_versioning.cli:main"

[project.entry-points."dynamic_metadata.provider"]
"setuptools_git_versioning.dynamic_metadata" = "setuptools_git_versioning.dynamic_metadata"

[tool.setuptools.packages.find]
include = ["setuptools_git_versioning*"]
exclude = ["docs*", "tests*"]
Expand All @@ -79,6 +82,7 @@ test = [
"tomli-w>=1.0.0",
"wheel>=0.42.0",
"scikit-build-core>=0.5",
"dynamic-metadata>=0.4; python_version >= '3.8'",
]
docs = [
"furo~=2025.12.19",
Expand Down Expand Up @@ -176,3 +180,8 @@ showcontent = true
directory = "misc"
name = "Misc"
showcontent = true

[[tool.towncrier.type]]
directory = "deprecation"
name = "Deprecation"
showcontent = true
51 changes: 51 additions & 0 deletions setuptools_git_versioning/dynamic_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Version provider for the dynamic-metadata protocol."""

from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING, Any

from setuptools_git_versioning.defaults import set_default_options
from setuptools_git_versioning.setup import read_toml
from setuptools_git_versioning.version import version_from_git

if TYPE_CHECKING:
from collections.abc import Mapping

__all__ = ["dynamic_metadata"]


def dynamic_metadata(
settings: Mapping[str, Any],
project: Mapping[str, Any],
) -> dict[str, str]:
if settings:
msg = (
"Inline configuration under [[tool.dynamic-metadata]] is not supported. "
"Configure setuptools-git-versioning under [tool.setuptools-git-versioning] instead."
)
raise ValueError(msg)

root = Path.cwd()

config = read_toml(root=root)
if not config:
msg = (
"Missing [tool.setuptools-git-versioning] section in pyproject.toml. "
"Add it (with at minimum 'enabled = true') to use this provider."
)
raise ValueError(msg)

if not config.pop("enabled", True):
msg = (
"[tool.setuptools-git-versioning] has 'enabled = false' but the "
"metadata provider for setuptools-git-versioning was selected. "
"Either remove the provider or set 'enabled = true'."
)
raise ValueError(msg)

set_default_options(config)

name = project.get("name")
package_name = name if isinstance(name, str) else None
return {"version": str(version_from_git(package_name, **config, root=root))}
39 changes: 12 additions & 27 deletions setuptools_git_versioning/scikit_metadata.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
"""Dynamic metadata provider for the scikit-build-core build backend."""
"""Deprecated version provider for the classic scikit-build-core protocol."""

from __future__ import annotations

import warnings
from pathlib import Path
from typing import TYPE_CHECKING, Any

from setuptools_git_versioning.defaults import set_default_options
from setuptools_git_versioning.setup import read_toml
from setuptools_git_versioning.version import version_from_git
from setuptools_git_versioning.dynamic_metadata import dynamic_metadata as _dynamic_metadata

if TYPE_CHECKING:
from collections.abc import Mapping

__all__ = ["dynamic_metadata", "get_requires_for_dynamic_metadata"]

warnings.warn(
"setuptools_git_versioning.scikit_metadata is deprecated; "
"migrate to [[tool.dynamic-metadata]] with provider = 'setuptools_git_versioning.dynamic_metadata' "
"on a backend supporting dynamic-metadata such as scikit-build-core>=1.0.",
DeprecationWarning,
stacklevel=2,
)


def dynamic_metadata(
field: str,
Expand All @@ -30,29 +37,7 @@ def dynamic_metadata(
)
raise ValueError(msg)

root = Path.cwd()

config = read_toml(root=root)
if not config:
msg = (
"Missing [tool.setuptools-git-versioning] section in pyproject.toml. "
"Add it (with at minimum 'enabled = true') to use this provider."
)
raise ValueError(msg)

if not config.pop("enabled", True):
msg = (
"[tool.setuptools-git-versioning] has 'enabled = false' but the scikit-build-core "
"metadata provider for setuptools-git-versioning was selected. "
"Either remove the provider or set 'enabled = true'."
)
raise ValueError(msg)

set_default_options(config)

package_name = _read_project_name(root)

return str(version_from_git(package_name, **config, root=root))
return _dynamic_metadata({}, {"name": _read_project_name(Path.cwd())})["version"]


def _read_project_name(root: Path) -> str | None:
Expand Down
Loading
Loading