Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 643a14b

Browse filesBrowse files
feat(py_wheel): Add support for specifying Description-Content-Type and Summary in METADATA (bazel-contrib#1274)
`py_wheel` allows to supply a description file, but it does not allow specifying the content type of that file. By default, the type is "text/x-rst", but many packages are using a markdown description. https://packaging.python.org/en/latest/specifications/core-metadata/#description-content-type This change added the support. --------- Co-authored-by: Richard Levasseur <richardlev@gmail.com>
1 parent 0cd6c25 commit 643a14b
Copy full SHA for 643a14b

File tree

5 files changed

+38
-4
lines changed
Filter options

5 files changed

+38
-4
lines changed

‎docs/packaging.md

Copy file name to clipboardExpand all lines: docs/packaging.md
+6-3Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/wheel/BUILD.bazel

Copy file name to clipboardExpand all lines: examples/wheel/BUILD.bazel
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ py_wheel(
160160
python_tag = "py3",
161161
# Requirements embedded into the wheel metadata.
162162
requires = ["pytest"],
163+
summary = "A one-line summary of this test package",
163164
version = "0.0.1",
164165
deps = [":example_pkg"],
165166
)

‎examples/wheel/wheel_test.py

Copy file name to clipboardExpand all lines: examples/wheel/wheel_test.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_customized_wheel(self):
9999
record_contents,
100100
# The entries are guaranteed to be sorted.
101101
b"""\
102-
example_customized-0.0.1.dist-info/METADATA,sha256=YUnzQ9gTMXspIBURe90Ct3aL_CCn8fwC3SiZe6MMTs8,372
102+
example_customized-0.0.1.dist-info/METADATA,sha256=vRiyyV45PC5fzK_40nSTtIn3yYzDdsbBAbUvkZiRyc8,461
103103
example_customized-0.0.1.dist-info/NOTICE,sha256=Xpdw-FXET1IRgZ_wTkx1YQfo1-alET0FVf6V1LXO4js,76
104104
example_customized-0.0.1.dist-info/README,sha256=WmOFwZ3Jga1bHG3JiGRsUheb4UbLffUxyTdHczS27-o,40
105105
example_customized-0.0.1.dist-info/RECORD,,
@@ -129,6 +129,8 @@ def test_customized_wheel(self):
129129
Author-email: example@example.com
130130
Home-page: www.example.com
131131
License: Apache 2.0
132+
Description-Content-Type: text/markdown
133+
Summary: A one-line summary of this test package
132134
Classifier: License :: OSI Approved :: Apache Software License
133135
Classifier: Intended Audience :: Developers
134136
Requires-Dist: pytest

‎python/private/py_wheel.bzl

Copy file name to clipboardExpand all lines: python/private/py_wheel.bzl
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ _other_attrs = {
155155
"classifiers": attr.string_list(
156156
doc = "A list of strings describing the categories for the package. For valid classifiers see https://pypi.org/classifiers",
157157
),
158+
"description_content_type": attr.string(
159+
doc = ("The type of contents in description_file. " +
160+
"If not provided, the type will be inferred from the extension of description_file. " +
161+
"Also see https://packaging.python.org/en/latest/specifications/core-metadata/#description-content-type"),
162+
),
158163
"description_file": attr.label(
159164
doc = "A file containing text describing the package.",
160165
allow_single_file = True,
@@ -181,8 +186,17 @@ _other_attrs = {
181186
default = [],
182187
doc = "path prefixes to strip from files added to the generated package",
183188
),
189+
"summary": attr.string(
190+
doc = "A one-line summary of what the distribution does",
191+
),
184192
}
185193

194+
_DESCRIPTION_FILE_EXTENSION_TO_TYPE = {
195+
"md": "text/markdown",
196+
"rst": "text/x-rst",
197+
}
198+
_DEFAULT_DESCRIPTION_FILE_TYPE = "text/plain"
199+
186200
def _escape_filename_segment(segment):
187201
"""Escape a segment of the wheel filename.
188202
@@ -275,6 +289,17 @@ def _py_wheel_impl(ctx):
275289
metadata_contents.append("Home-page: %s" % ctx.attr.homepage)
276290
if ctx.attr.license:
277291
metadata_contents.append("License: %s" % ctx.attr.license)
292+
if ctx.attr.description_content_type:
293+
metadata_contents.append("Description-Content-Type: %s" % ctx.attr.description_content_type)
294+
elif ctx.attr.description_file:
295+
# infer the content type from description file extension.
296+
description_file_type = _DESCRIPTION_FILE_EXTENSION_TO_TYPE.get(
297+
ctx.file.description_file.extension,
298+
_DEFAULT_DESCRIPTION_FILE_TYPE,
299+
)
300+
metadata_contents.append("Description-Content-Type: %s" % description_file_type)
301+
if ctx.attr.summary:
302+
metadata_contents.append("Summary: %s" % ctx.attr.summary)
278303

279304
for c in ctx.attr.classifiers:
280305
metadata_contents.append("Classifier: %s" % c)

‎tools/wheelmaker.py

Copy file name to clipboardExpand all lines: tools/wheelmaker.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ def parse_args() -> argparse.Namespace:
289289
wheel_group.add_argument(
290290
"--description_file", help="Path to the file with package description"
291291
)
292+
wheel_group.add_argument(
293+
"--description_content_type", help="Content type of the package description"
294+
)
292295
wheel_group.add_argument(
293296
"--entry_points_file",
294297
help="Path to a correctly-formatted entry_points.txt file",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.