GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing peps.python.org — PEP 808 – Including static values in dynamic metadata | peps.python.org
PEP 808 – Including static values in dynamic metadata
PEP 808 – Including static values in dynamic metadata
AbstractThis PEP relaxes the constraint on dynamic metadata listed in the This allows users to opt into allowing a backend to extend metadata while still
keeping the static portions of the metadata defined in the standard location in
MotivationIn the core metadata specification originally set out in PEP 621, metadata
can be specified in three ways. First, it can be listed in the This system provided two important benefits to Python packaging. A standard specification that all major backends have now adopted makes teaching much easier; a single tutorial is now sufficient to cover the metadata portion of configuring any backend. Users can now switch from a general purpose backend to a specialized backend without changing their static metadata. Tooling like schema validation tools can verify and catch configuration mistakes. The second benefit is improved support for static tools that read the source
files looking for metadata. This is useful for dependency chain analysis, such
as creating “used by” and “uses” graphs. It is used for code quality tooling to
detect the minimum supported version of Python. It is used by cibuildwheel to
automatically avoid building wheels that are not supported. It is not used,
however, to avoid wheel builds when the SDist is available; that was addressed
by METADATA 2.2, which added a Due to the rapidly increasing popularity of the project table, support from all
major backends, and a rise of backends supporting complex compiled extensions,
an issue with the restrictions applied in PEP 621 is becoming more apparent.
In PEP 621, the metadata choice is all-or-nothing; metadata must be completely
static, or listed in the dynamic field and completely absent from the static
definition. For the most common use cases, this is fine; there is little
benefit to set the RationalePEP 621 includes the following statement:
In this PEP, we are proposing a limited and explicit loosening of the
restrictions on the Every list and every table with arbitrary keys will now be allowed to be
specified both statically, in the Use CasesThere is an entire class of metadata fields where advanced use cases would really benefit from a relaxation of this rule. Here are some use cases that have come up:
All of these use cases have a similar feature: they are adding something dynamically to a fixed list (possibly a narrower pin for the dependency case). You can implement these today, but it requires providing a completely separate configuration location for the non-extended portion, and static analysis tools lose the ability to detect anything. Since the current solution is to move all the metadata out of the standard field, this proposal will increase the availability of metadata for static tooling. Example: pinningFor example, say you want to allow an imaginary build backend
( [project] dynamic = ["dependencies"] [tool.my-build-backend] original-dependencies = ["torch", "packaging"] pin-to-build-versions = ["torch=={exact}"] Which would effectively expand to the following SDist metadata: Dynamic: Requires-Dist Requires-Dist: packaging Requires-Dist: torch Which could then make a wheel with this: Requires-Dist: packaging Requires-Dist: torch Requires-Dist: torch==2.8.0 Static tooling can no longer tell that With this PEP, this could now be specified like this: [project] dependencies = ["torch", "packaging"] dynamic = ["dependencies"] [tool.my-build-backend] pin-to-build-versions = ["torch=={exact}"] Static tooling can now detect the static dependencies, and the build backend no
longer needs to create and document a new location for the standard
Future UpdatesLoosening this rule to allow purely additive metadata should address many of the use cases that have been seen in practice. If further changes are needed, this can be revisited in a future PEP; this PEP neither recommends nor precludes future updates like this. TerminologyThe keywords “MUST”, “MUST NOT”, “REQUIRED”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119. SpecificationAny field that is comprised of a list or a table with arbitrary entries will
now be allowed to be present in both the The fields that are arrays or tables with arbitrary entries are:
To add items, users must opt in by listing the field in A backend SHOULD error if a field is specified and it does not support
extending that field, to protect against possible user error. We recommend
being as strict as possible to avoid unnecessary entries in the Static analysis tools, when detecting a field is both specified and in the
The In METADATA 2.2 to 2.5, there are no constraints on entries listed as
Dynamic: Requires-Dist Requires-Dist: packaging Before METADATA 2.6, there are no constraints on a field if it appeared in
This new point will be added to the guidelines:
Reference ImplementationThe choice to support dynamic metadata for each field is already left up to backends, and this PEP simply relaxes restrictions on what a backend is allowed to do with dynamic metadata. The pyproject-metadata project, which is used by several build backends, will need to modify the correctness check to account for the possible extensions; this is in a draft PR. The dynamic-metadata project, which provides a plugin system that backends can use to share dynamic metadata plugins, was designed to allow this possibility, and a similar PR to the one above will allow additive metadata. Backwards CompatibilityThis does not affect any existing When users adopt this in a Static analysis tools may require updating to handle this change. Tools should check the dynamic table first, like this: match pyproject["project"]: # New in PEP 808 case {my.key: value, "dynamic": dyn} if my.key in dyn: print(f"Partial {my.key}: {value}") case {"dynamic": dyn} if my.key in dyn: print(f"Fully dynamic {my.key}") case {my.key: value}: print(f"Fully static {my.key}: {value}") case _: print(f"No metadata for {my.key}") Before this PEP, tools could reverse the order of the dynamic and static blocks, assuming that an entry in the project table meant it could not be dynamic. If they do this, they will now incorrectly assume they have all the metadata for a field, when they in fact only have part of it. Security ImplicationsThere are no security concerns that are not already present, as this just adds a static component to existing dynamic metadata support. How to Teach ThisIf you currently have dynamic metadata, but some list or table entries are
known statically, you can now make that explicit by adding the static entry in
the The current guides that state metadata must not be listed in both The It should also be noted that specifying something in Rejected IdeasSpecial case some fields without adding dynamicThis has come up specifically for the pinning build dependency use case, but could also be applied to more of the use cases listed. This would not cover all the use cases seen, though, and an explicit, opt-in approach is better for static tooling. Include string fieldsSome string fields could also be extended. Most notably, the The other string fields, namely Fully remove restrictions on backendsAnother option would be to simply allow backends to do whatever they wanted if a field is statically defined and in the dynamic array. This would sacrifice the ability for static tooling to infer anything about the field, and could potentially confuse users by allowing the backend to ignore or change what they entered. This is not worse than the status quo for static tooling and dynamic metadata, but the current proposal improves the ability of static tooling to infer some things about dynamic fields. Knowing some of the dependencies is better for most applications than not knowing anything about the dependencies, for example. Allow simplificationsAn earlier draft of this PEP had a clause allowing backends to simplify some
types of fields; most notably dependency specifiers would have allowed
“tightening”, such as Add a general mechanism to specify dynamic-metadataThis PEP does not cover methods to specify dynamic metadata; that continues to be entirely up to the backend. An earlier draft proposal did this, but it was deemed better to develop that as a library (dynamic-metadata, for the curious) instead. This may be revisited in the future. CopyrightThis document is placed in the public domain or under the CC0-1.0-Universal license, whichever is more permissive. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |