-
-
Notifications
You must be signed in to change notification settings - Fork 244
feat: add dynamic-metadata integration #1465
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
RonnyPfannschmidt
merged 6 commits into
pypa:main
from
henryiii:henryiii/feat/dynamic-metadata
Aug 8, 2026
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ab4e2d8
feat(vcs-versioning): add scikit-build dynamic-metadata provider
henryiii 99ff436
refactor: clean up and simplify
henryiii eb21ab6
refactor: export to top level
henryiii c99b4c8
refactor: dynamic-metadata 0.4 (entry-point)
henryiii e711186
fix: move entrypoint to actual package
henryiii d236eac
docs: simpler example
henryiii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add a ``vcs_versioning.dynamic_metadata`` provider for the [dynamic-metadata](https://github.com/scikit-build/dynamic-metadata) system. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| """scikit-build ``dynamic-metadata`` provider for vcs-versioning. | ||
|
|
||
| Use this module as a provider for `scikit-build/dynamic-metadata | ||
| <https://github.com/scikit-build/dynamic-metadata>`_ so any backend supporting | ||
| that can fill in a VCS-derived ``version``:: | ||
|
|
||
| [[tool.dynamic-metadata]] | ||
| provider = "vcs_versioning.dynamic_metadata" | ||
|
RonnyPfannschmidt marked this conversation as resolved.
Outdated
|
||
|
|
||
| Configuration is read from ``[tool.vcs-versioning]``; any keys in the | ||
| ``[[tool.dynamic-metadata]]`` table are passed through as overrides. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Mapping | ||
|
|
||
| from vcs_versioning import PyProjectData, infer_version_string | ||
| from vcs_versioning.overrides import GlobalOverrides | ||
|
|
||
| __all__ = ["dynamic_metadata"] | ||
|
|
||
|
|
||
| def __dir__() -> list[str]: | ||
| return __all__ | ||
|
|
||
|
|
||
| def dynamic_metadata( | ||
| settings: Mapping[str, Any], | ||
| project: Mapping[str, Any], | ||
| ) -> dict[str, Any]: | ||
| """Return the ``version`` field for a dynamic-metadata consumer.""" | ||
| dist_name = project.get("name") | ||
| # dynamic-metadata runs hooks with cwd at the project root. | ||
| with GlobalOverrides.from_env("VCS_VERSIONING", dist_name=dist_name): | ||
| pyproject = PyProjectData.from_file("pyproject.toml") | ||
| version = infer_version_string( | ||
| dist_name=dist_name, | ||
| pyproject_data=pyproject, | ||
| overrides=dict(settings) or None, | ||
| force_write_version_files=True, | ||
| ) | ||
| return {"version": version} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| """Tests for the scikit-build dynamic-metadata provider.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from vcs_versioning import test_api | ||
| from vcs_versioning.dynamic_metadata import dynamic_metadata | ||
|
|
||
|
|
||
| def test_pretend_version(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| (tmp_path / "pyproject.toml").write_text( | ||
| """ | ||
| [project] | ||
| name = "test-package" | ||
| dynamic = ["version"] | ||
|
|
||
| [tool.vcs-versioning] | ||
| """, | ||
| encoding="utf-8", | ||
| ) | ||
| monkeypatch.chdir(tmp_path) | ||
| monkeypatch.setenv("VCS_VERSIONING_PRETEND_VERSION_FOR_TEST_PACKAGE", "1.2.3") | ||
|
|
||
| assert dynamic_metadata({}, {"name": "test-package"}) == {"version": "1.2.3"} | ||
|
|
||
|
|
||
| def test_inline_override_drops_local_segment( | ||
| wd: test_api.WorkDir, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| wd.setup_git(monkeypatch) | ||
| wd.create_basic_pyproject_toml(name="test-package") | ||
| wd.add_and_commit() | ||
| wd.create_tag("1.0.0") | ||
| wd.commit_testfile() | ||
| monkeypatch.chdir(wd.cwd) | ||
|
|
||
| # Default local scheme adds a +g<node> local segment. | ||
| default = dynamic_metadata({}, {"name": "test-package"}) | ||
| assert "+" in default["version"] | ||
|
|
||
| # Inline settings are forwarded to infer_version_string as overrides. | ||
| overridden = dynamic_metadata( | ||
| {"local_scheme": "no-local-version"}, | ||
| {"name": "test-package"}, | ||
| ) | ||
| assert "+" not in overridden["version"] | ||
| assert overridden["version"].startswith("1.0.1.dev1") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imho dynamic metadata should have a wy to pass in the root pyproject directly - and the vcs-versioning provider should use its own tool section for the configuration - creating additional placees for putting the same thing is against the zen of python as far as im concerned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, hooks run in the same directory as build-system.build-backend so it's fine to read it. That's why the docs say both work. You can disable this (don't pass through config, require to be empty), but users will likely expect to have all the config in each tool.dynamic-metadata section. And if you use it multiple times (like building readme's out of fragments), you have to have it in each entry.