wads.toml_util

Utilities for reading and writing pyproject.toml files.

Functions

get_project_metadata(pkg_dir)

Get the [project] section from pyproject.toml.

get_project_name(pkg_dir)

Get the project name from pyproject.toml.

get_project_version(pkg_dir)

Get the version from pyproject.toml.

pep639_license(license_name)

The [project].license value for license_name, PEP 639 when possible.

read_pyproject_toml(pkg_dir)

Read pyproject.toml from the specified package directory.

set_project_version(pkg_dir, version)

Set the version in pyproject.toml.

update_project_metadata(pkg_dir, **kwargs)

Update project metadata in pyproject.toml.

update_project_url(pkg_dir, url[, url_key])

Update or add a URL in the [project.urls] section of pyproject.toml.

write_pyproject_toml(pkg_dir, data)

Write data to pyproject.toml in the specified package directory.

wads.toml_util.get_project_metadata(pkg_dir)[source]

Get the [project] section from pyproject.toml.

Parameters:

pkg_dir (str) – Path to the package directory

Return type:

dict[str, Any]

Returns:

Dictionary containing project metadata

wads.toml_util.get_project_name(pkg_dir)[source]

Get the project name from pyproject.toml.

Parameters:

pkg_dir (str) – Path to the package directory

Return type:

Optional[str]

Returns:

Project name or None if not found

wads.toml_util.get_project_version(pkg_dir)[source]

Get the version from pyproject.toml.

Parameters:

pkg_dir (str) – Path to the package directory

Return type:

Optional[str]

Returns:

Version string or None if not found

wads.toml_util.pep639_license(license_name)[source]

The [project].license value for license_name, PEP 639 when possible.

A name that canonicalizes to a valid SPDX expression becomes that string (license = "MIT"). Anything else keeps the deprecated {"text": ...} table, because Hatchling rejects a license string that is not valid SPDX – so this never produces an unbuildable project. Needs packaging>=24.2 for SPDX support and falls back to the table without it.

>>> pep639_license("mit")
'MIT'
>>> pep639_license("Apache Software License")
'Apache-2.0'
>>> pep639_license("Proprietary")
{'text': 'Proprietary'}
wads.toml_util.read_pyproject_toml(pkg_dir)[source]

Read pyproject.toml from the specified package directory.

Parameters:

pkg_dir (str) – Path to the package directory

Return type:

dict[str, Any]

Returns:

Dictionary containing the parsed TOML data

Raises:
wads.toml_util.set_project_version(pkg_dir, version)[source]

Set the version in pyproject.toml.

Parameters:
  • pkg_dir (str) – Path to the package directory

  • version (str) – New version string

Return type:

None

wads.toml_util.update_project_metadata(pkg_dir, **kwargs)[source]

Update project metadata in pyproject.toml.

Parameters:
  • pkg_dir (str) – Path to the package directory

  • **kwargs – Metadata fields to update

Return type:

None

wads.toml_util.update_project_url(pkg_dir, url, url_key='Homepage')[source]

Update or add a URL in the [project.urls] section of pyproject.toml.

Parameters:
  • pkg_dir (str) – Path to the package directory

  • url (str) – The URL to set

  • url_key (str) – The key to use in the urls dict (default: “Homepage”)

Return type:

None

wads.toml_util.write_pyproject_toml(pkg_dir, data)[source]

Write data to pyproject.toml in the specified package directory.

Parameters:
  • pkg_dir (str) – Path to the package directory

  • data (dict[str, Any]) – Dictionary to write as TOML

Raises:

ImportError – If tomli_w is not available

Return type:

None