Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Dynamic Metadata

Slides

A method to handle project.dynamic fields generically. The specification is generic, but currently, it is a feature used only in scikit-build-core. I.e. for now you must use

pyproject.toml
[build-system]
requires = ["scikit-build-core"]
build-backend = "scikit_build_core.build"

Example

Generic (recommended)
scikit-build
pyproject.toml
[project]
name = "mypackage"
dynamic = ["version"]

[tool.scikit-build]
sdist.include = ["src/package/_version.py"]

[[tool.dynamic-metadata]]
provider = "scikit_build_core.metadata.setuptools_scm"

[tool.setuptools_scm]  # Section required
version_file = "src/package/_version.py"

From the user side

Pre-defined plugins

There are some pre-defined plugins to get you started both in scikit-build-core or dynamic-metadata. To use the latter, make sure dynamic-metadata is in the build-system.requires. For an updated documentation check the relevant documentation section in scikit-build-core and dynamic-metadata.

`scikit_build_core.metadata.setuptools_scm`
`(scikit_build_core.metadata|dynamic_metadata).regex`
`(scikit_build_core.metadata|dynamic_metadata).template`
`scikit_build_core.metadata.fancy_pypi_readme`
`dynamic_metadata.ast`
`dynamic_metadata.from_file`
`dynamic_metadata.static`
`dynamic_metadata.readme_fragment`
`dynamic_metadata.pin_installed`
`dynamic_metadata.substitute`

Get version from git metadata

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

[[tool.dynamic-metadata]]
provider = "scikit_build_core.metadata.setuptools_scm"

[tool.setuptools_scm]
  • dynamic field: version

  • inputs: tool.setuptools_scm

See setuptools-scm

Order matters

The tool.dynamic-metadata are processed in the order they appear in pyproject.toml. If a provider expects a dynamic field to have been resolved, make sure you order them appropriately.

pyproject.toml
1
2
3
4
5
6
7
8
9
10
11
12
13
[project]
name = "mypackage"
dynamic = ["version", "dependencies"]

[[tool.dynamic-metadata]]
provider = "scikit_build_core.metadata.setuptools_scm"

[[tool.dynamic-metadata]]
provider = "scikit_build_core.metadata.template"
field = "dependencies"
result = ["mypackage-core == {project[version]}"]

[tool.setuptools_scm]

Want more? Custom plugins

You can write your own plugin and use it locally or distribute it via dynamic_metadata.provider entry-point.

[[tool.dynamic-metadata]]
provider = {path = "helpers/plugins", module = "my_plugin"}

The referenced module/class must have at least the function

def dynamic_metadata(
    settings: Mapping[str, Any],
    project: Mapping[str, Any],
) -> dict[str, Any]:
    """
    :param settings: all the additional fields defined in the ``[[tool.dynamic-metadata]]``
    :param project: current view of the ``[project]``
    :return: a ``[project]`` snippet to be merged
    """
Footnotes
  1. With PEP 808 you can have mixed static and dynamic fields for table and array fields like dependencies, scripts