I have projects with (some) PEP 621 metadata fields populated by Setuptools entry points. How can I satisfy the (looming) hard requirement to declare these as dynamic, and that they are populated by an entry-point function?
I am busily migrating projects from executable ‘setup.py’-based configuration to PEP 621, and some of the metadata is dynamically generated.
This is working fine, until the PEP 517 conformant build tool wants to know how these fields are defined; I don’t know what is needed in ‘pyproject.toml’ to tell it the situation.
Examples:
- The distribution
version
field is derived from the ChangeLog document as a single point of truth. After migrating from a function called from ‘setup.py’, this is now done with an entry-point, declared in ‘pyproject.toml’:
[project.entry-points."setuptools.finalize_distribution_options"]
# Set the distribution version.
version = "util.packaging:derive_version"
The function util.packaging.derive_version(distribution)
correctly determines the version string, and sets it on distribution.metadata.version
. This works great.
- The distribution
description
andreadme
fields are derived from the main package’s docstring, as a single point of truth for that information. (This is done so that in order to update the project description, one updates the docstring, which ensures that aligns with the description.)
[project.entry-points."setuptools.finalize_distribution_options"]
# Set the description fields ‘description’, ‘readme’.
description_fields = "util.packaging:derive_dist_description"
Again, this works great and the correct metadata is generated in the distribution files. But:
##########################################################################
# configuration would be ignored/result in error due to `pyproject.toml` #
##########################################################################
The following seems to be defined outside of `pyproject.toml`:
`description = 'Lorem ipsum, dolor sit amet.'`
According to the spec (see the link below), however, setuptools CANNOT
consider this value unless `description` is listed as `dynamic`.
https://packaging.python.org/en/latest/specifications/declaring-project-metadata/
However, when I follow that instruction and set the fields in project.dynamic
:
dynamic = [
"version",
"description",
"readme",
]
then setuptools.build_meta
crashes:
distutils.errors.DistutilsOptionError: No configuration found for dynamic 'description'.
Some dynamic fields need to be specified via `tool.setuptools.dynamic`
others must be specified via the equivalent attribute in `setup.py`.
Since it’s satisfied in a project.entry-points."setuptools.finalize_distribution_options"
entry point, how do I inform the build system of this so builds will succeed?