Metadata Utilities

Utilities for reading, writing, and validating pyproject.toml metadata.

pypreset.metadata_utils.read_pyproject_metadata(project_dir)[source]

Read metadata from an existing pyproject.toml.

Returns a flat dict with keys matching the Metadata model fields. Works with both Poetry ([tool.poetry]) and PEP 621 ([project]) layouts.

Parameters:

project_dir (Path)

Return type:

dict[str, Any]

pypreset.metadata_utils.set_pyproject_metadata(project_dir, updates, *, overwrite=False)[source]

Update metadata fields in an existing pyproject.toml.

Parameters:
  • project_dir (Path) – Path to the project directory.

  • updates (dict[str, Any]) – Dict of metadata field names to values.

  • overwrite (bool) – If True, overwrite existing non-empty values. If False, only set fields that are currently empty/unset.

Return type:

list[str]

Returns:

List of warnings about fields that remain empty.

pypreset.metadata_utils.check_publish_readiness(data)[source]

Check if metadata is sufficient for PyPI publishing.

Returns a list of warning strings for empty/default fields.

Parameters:

data (dict[str, Any])

Return type:

list[str]

pypreset.metadata_utils.generate_default_urls(project_name, github_owner=None)[source]

Generate sensible default URLs from the project name and optional GitHub owner.

If github_owner is provided, generates GitHub-based URLs.

Parameters:
Return type:

dict[str, str]