Skip to content

Simplify transforming license = { file = "..." } into an entry for license-files #284

@pradyunsg

Description

@pradyunsg

PEP 639 states in https://peps.python.org/pep-0639/#deprecate-license-key-table-subkeys:

If the specified license file is present in the source tree, build tools SHOULD use it to fill the License-File field in the core metadata, and MUST include the specified file as if it were specified in a license-file field. If the file does not exist at the specified path, tools MUST raise an informative error as previously specified.

Currently, to do this, I need to have custom logic in my build backend to coerce things according to that section:

metadata: pyproject_metadata.StandardMetadata

if (
    metadata.license is not None
    and not isinstance(metadata.license, str)
    and metadata.license.file is not None
):
    license_file = metadata.license.file
    if not license_file.exists():
        raise ImproperProjectMetadata(
            message="Declared license file does not exist.",
            causes=[
                f"Looked at {license_file}",
                "Specified in pyproject.toml -> [project] -> license -> file",
            ],
            hint_stmt="Did you specify the correct path?",
            code="license-file-missing",
        )
    if metadata.license_files is None:
        metadata.license_files = [license_file]
    elif license_file not in metadata.license_files:
        metadata.license_files.append(license_file)

It would be good to have pyproject-metadata handle this, via some mechanism. For backwards-compatibility reasons, this might need to be an opt-in -- but that's fine, I'd be happy to adopt that in sphinx-theme-builder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions