In certain situations, particularly when working with native code, there is a need to add dependency constraints based on the build environment.
PEP 621 prohibits this, unless the field is marked as dynamic
.
Data specified using this PEP is considered canonical. Tools CANNOT remove, add or change data that has been statically specified. Only when a field is marked as
dynamic
may a tool provide a “new” value.
And marking a field as dynamic
, means it can’t be present on the project
table.
- Build back-ends MUST raise an error if the metadata specifies a field statically as well as being listed in
dynamic
.
This is a bit problematic, and I think it could be argued that in some way, it kind of defeats the purpose of the PEP. The PEP aims to allow metadata, such as dependencies, to be read from a standardized (static) place — pyproject.toml
.
This feature is great, and enables tools such as Github’s repository dependency graph to exist. Requiring projects to stop providing its dependency in project.dependencies
if some of its binary artifacts happen to depend on the version of one of its build dependencies, for eg., unnecessarily breaks tooling support.
In the rejected ideas section, the PEP shares the motivation:
Allow tools to add/extend data
In an earlier version of this PEP, tools were allowed to extend data for fields. For instance, build back-ends could take the version number and add a local version for when they built the wheel. Tools could also add more trove classifiers for things like the license or supported Python versions.
In the end, though, it was thought better to start out stricter and contemplate loosening how static the data could be considered based on real-world usage.
In accordance to this, I think we should consider loosening the static metadata requirements as follows:
- Tools MAY add additional
Requires-Dist
entries to artifact metadata, as long as they FURTHER CONSTRAINT existing entries.- Eg. when a
Requires-Dist: numpy
entry is present, the build-backend may add aRequires-Dist: numpy == 2.*
entry to the wheel metadata.
- Eg. when a