API reference¶
Loader¶
The driver consumed by build backends.
- class dynamic_metadata.loader.Resolved(project, dynamic_fields=frozenset({}))¶
The result of
resolve().- dynamic_fields: frozenset[str] = frozenset({})¶
For an SDist build, the fields whose value may differ in a wheel built from it (METADATA 2.2
Dynamic); empty for every other build state.
- dynamic_metadata.loader.dynamic_wheel_fields(entries)¶
Collect the fields to mark
Dynamicin SDist metadata (METADATA 2.2).Asks each provider’s optional
dynamic_wheelhook which fields may legitimately differ between the SDist and a wheel built from it. A field is dynamic if any provider reports itTrue: contributions to a field merge, so one dynamic part makes the merged value dynamic (PEP 643 permits marking a fieldDynamiceven when its value is also given). A field no provider mentions is not dynamic, andversionmay never be.Providers are loaded fresh here, so
dynamic_wheelcannot rely on state from adynamic_metadatacall.
- dynamic_metadata.loader.entries_from_pyproject(pyproject)¶
Return the validated
[[tool.dynamic-metadata]]entries of a parsedpyproject.toml.Returns
[]if the table is absent. RaisesConfigErrorif it is not an array of tables or an entry lacksprovider.
- dynamic_metadata.loader.get_requires_for_dynamic_metadata(entries)¶
Collect every provider’s extra build requirements, in entry order.
Call this from each PEP 517
get_requires_for_build_*hook. A provider without the optionalget_requires_for_dynamic_metadatahook contributes nothing.A provider that is found but fails to import — typically because it imports at module level a package it would have declared as its own requirement — is skipped, since its hook cannot be asked; the import error surfaces later, when the metadata is resolved. An unknown provider name or a missing local module still raises.
- dynamic_metadata.loader.load_dynamic_metadata(entries)¶
Load each entry’s provider, yielding it with its plugin settings.
Entries are processed in order;
provideris consumed here and the remaining keys are returned as plugin settings.
- dynamic_metadata.loader.load_provider(provider)¶
Load a provider from its config value, returning the object whose hooks are called.
provideris the value of theproviderkey in a[[tool.dynamic-metadata]]entry, in one of two forms:a string — a name registered in the
PROVIDER_GROUPentry-point group. Installed plugins are only reachable this way; a raw import path is not accepted.an inline table
{path, module}— a local plugin imported from thepathdirectory as a module path ("pkg.mod"or"pkg.mod:Class"), for a plugin living inside the project being built. Entry points are not consulted.
A bare module is returned as-is (hooks are module-level functions); a class is instantiated with no arguments so its hooks are bound methods sharing state through
self; an already-instantiated object is used directly.- Parameters:
provider (
object)- Return type:
- dynamic_metadata.loader.process_dynamic_metadata(project, entries, build_state)¶
Process dynamic metadata.
Takes the original
[project]table and an ordered list of[[tool.dynamic-metadata]]entries, and returns a new project table. Entries run in list order: each provider is called with a read-only snapshot of the project as resolved so far, so a later entry can read a field an earlier one produced viaproject[...]. A provider returns adictfragment of the project table ({field: value, ...}) which is merged in.build_stateis the backend’s description of the current build. It must be one of these build states (BUILD_STATES):"sdist","wheel","editable","metadata_wheel", or"metadata_editable". A provider that cares about it implements an optionalbuild_statehook, called with this value beforedynamic_metadata; providers that ignore it simply omit the hook.
- dynamic_metadata.loader.resolve(pyproject, build_state, *, backend_fields=(), strict=True)¶
Resolve a whole parsed
pyproject.toml, handling thedynamicbookkeeping.This is
entries_from_pyproject(),process_dynamic_metadata(), and (for"sdist")dynamic_wheel_fields()in one call. If there are no entries the[project]table is returned unchanged ({}if absent); if there are entries but no[project]table,ConfigErroris raised.For an SDist build, the fields the providers report as wheel-dynamic are removed from
dynamic(so thePKG-INFOis valid) and returned asdynamic_fieldsfor the backend to write asDynamic:headers.With
strict(the default), a field still listed indynamicafter that — declared dynamic but produced by no provider — raisesConfigError, unless it is inbackend_fields, the fields the backend fills in itself (for exampleversionread from a build file).
Errors¶
Exceptions raised by dynamic_metadata.loader.
Every error the loader raises itself derives from DynamicMetadataError,
so a backend can translate them all with one except clause. The subclasses
also keep a standard base (ValueError, ImportError, …) so existing
handlers keep working. An exception raised inside a provider’s hook is not
wrapped and propagates unchanged.
- exception dynamic_metadata.errors.ConfigError¶
Bases:
DynamicMetadataError,ValueErrorThe
[[tool.dynamic-metadata]]configuration (or a loader argument) is invalid.
- exception dynamic_metadata.errors.DynamicMetadataError¶
Bases:
ExceptionBase class for every error the loader raises.
- exception dynamic_metadata.errors.InvalidFieldError¶
Bases:
DynamicMetadataError,ValueErrorA provider returned a field that cannot be set, or set it in an invalid way.
- exception dynamic_metadata.errors.ProviderLoadError¶
Bases:
DynamicMetadataError,ImportErrorThe provider was found but importing it failed (for example a missing dependency).
- exception dynamic_metadata.errors.ProviderNotFoundError¶
Bases:
DynamicMetadataError,ModuleNotFoundErrorNo provider is registered under the given name, or the local module is missing.
Plugin protocols¶
The protocols a provider may implement. Every provider satisfies
DynamicMetadataProtocol; the others add optional hooks.
- class dynamic_metadata.protocols.DynamicMetadataProtocol(*args, **kwargs)¶
- class dynamic_metadata.protocols.DynamicMetadataBuildStateProtocol(*args, **kwargs)¶
- class dynamic_metadata.protocols.DynamicMetadataRequirementsProtocol(*args, **kwargs)¶
- class dynamic_metadata.protocols.DynamicMetadataWheelProtocol(*args, **kwargs)¶
Field taxonomy¶
The single source of truth for which [project] fields can be dynamic and what
shape their value has.
Plugin helpers¶
Shared helpers that bundled and third-party plugins can reuse.