Skip to content

feat: add PEP 639 license metadata support - #4070

Open
sanchiagarwal0 wants to merge 1 commit into
bazel-contrib:mainfrom
sanchiagarwal0:feat/pep639-license-metadata
Open

feat: add PEP 639 license metadata support#4070
sanchiagarwal0 wants to merge 1 commit into
bazel-contrib:mainfrom
sanchiagarwal0:feat/pep639-license-metadata

Conversation

@sanchiagarwal0

Copy link
Copy Markdown

What does this PR do?

Adds support for PEP 639 license metadata in the py_wheel rule.

Changes

  • Adds the license_expression attribute for SPDX license expressions.
  • Adds the license_files attribute for license files.
  • Uses Metadata-Version 2.4 when PEP 639 license metadata is provided.
  • Adds License-Expression and License-File metadata fields.
  • Prevents license and license_expression from being used together.

Testing

  • git diff --check passes.
  • Bazel tests were attempted, but dependency downloads from GitHub timed out in the local environment.

Related issue

N/A

@sanchiagarwal0 sanchiagarwal0 changed the title add PEP 639 license metadata support feat: add PEP 639 license metadata support Aug 17, 2026

@rickeylev rickeylev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

  • PR description needs to be rewritten to be an appropriate commit message.
  • Needs tests.

doc = "An SPDX license expression for the package.",
default = "",
),
"license_files": attr.label_keyed_string_dict(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The license file paths are used, but the files themselves aren't being included in the output

default = "",
),
"license_files": attr.label_keyed_string_dict(
doc = "License files to include under the .dist-info/licenses/ directory.",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the value for this dict? the path under licenses to put the files under? The behavior needs to be documented.

How are files mapped under the licenses directory? Files could come from elsewhere in the repo

This attribute mostly redundant with the extra_distinfo_files attribute. The only differnce is where in dist-info files go (this puts them under licenses)

Given all this, I think we should just remove this field.

"License-Expression: %s" % ctx.attr.license_expression
)
for _, license_file in sorted(ctx.attr.license_files.items()):
metadata_contents.append("License-File: %s" % license_file)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is every license file supposed to be listed as a License-File header? I'm guessing a PEP specifies this? Which one?

Because extra_distinfo_files could add license files, I'm thinking the population of License-File should move to the execution phase.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This is specified by PEP 639. In the license-files section, it says build tools MUST include all files matched by the configured patterns and MUST list each matched file path under a License-File field in the Core Metadata.

The License-File field itself is also defined in the Core Metadata section of PEP 639 as a multi-use field, where each instance lists one license-related file.

https://peps.python.org/pep-0639/

@rickeylev

Copy link
Copy Markdown
Collaborator

@sanchiagarwal0 I get the sense you want to see this PR through on your own? I just ask because normally I would throw my agent at a PR and have it address most things. However, if you'd rather work on it yourself, I can hold off on that

@sanchiagarwal0

Copy link
Copy Markdown
Author

Yes, I'd like to work on it myself. Thanks for offering to have your agent handle it — I appreciate it! I'll look into the extra_distinfo_files handling and the execution phase and make the necessary changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants