Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion python/private/py_wheel.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ be moved under that directory.
doc = "A string specifying the license of the package.",
default = "",
),
"license_expression": attr.string(
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

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.

allow_files = True,
),
"project_urls": attr.string_dict(
doc = ("A string dict specifying additional browsable URLs for the project and corresponding labels, " +
"where label is the key and url is the value. " +
Expand Down Expand Up @@ -419,7 +427,17 @@ def _py_wheel_impl(ctx):
# Note: Description file and version are not embedded into metadata.txt yet,
# it will be done later by wheelmaker script.
metadata_file = ctx.actions.declare_file(ctx.attr.name + ".metadata.txt")
metadata_contents = ["Metadata-Version: 2.1"]
if ctx.attr.license and ctx.attr.license_expression:
fail(
"`license` and `license_expression` are mutually exclusive. "
+ "Please use only one of them."
)

metadata_version = "2.4" if (
ctx.attr.license_expression or ctx.attr.license_files
) else "2.1"

metadata_contents = ["Metadata-Version: %s" % metadata_version]
metadata_contents.append("Name: %s" % ctx.attr.distribution)

if ctx.attr.author:
Expand All @@ -430,6 +448,12 @@ def _py_wheel_impl(ctx):
metadata_contents.append("Home-page: %s" % ctx.attr.homepage)
if ctx.attr.license:
metadata_contents.append("License: %s" % ctx.attr.license)
if ctx.attr.license_expression:
metadata_contents.append(
"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/

if ctx.attr.description_content_type:
metadata_contents.append("Description-Content-Type: %s" % ctx.attr.description_content_type)
elif ctx.attr.description_file:
Expand Down
Loading