Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions docs/packaging.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 10 additions & 89 deletions examples/wheel/wheel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,40 +94,11 @@ def test_customized_wheel(self):
entry_point_contents = zf.read(
"example_customized-0.0.1.dist-info/entry_points.txt"
)
# The entries are guaranteed to be sorted.
if platform.system() == "Windows":
self.assertEqual(
record_contents,
b"""\
example_customized-0.0.1.dist-info/METADATA,sha256=pzE96o3Sp63TDzxAZgl0F42EFevm8x15vpDLqDVp_EQ,378
example_customized-0.0.1.dist-info/NOTICE,sha256=Xpdw-FXET1IRgZ_wTkx1YQfo1-alET0FVf6V1LXO4js,76
example_customized-0.0.1.dist-info/README,sha256=WmOFwZ3Jga1bHG3JiGRsUheb4UbLffUxyTdHczS27-o,40
example_customized-0.0.1.dist-info/RECORD,,
example_customized-0.0.1.dist-info/WHEEL,sha256=sobxWSyDDkdg_rinUth-jxhXHqoNqlmNMJY3aTZn2Us,91
example_customized-0.0.1.dist-info/entry_points.txt,sha256=pqzpbQ8MMorrJ3Jp0ntmpZcuvfByyqzMXXi2UujuXD0,137
examples/wheel/lib/data.txt,sha256=9vJKEdfLu8bZRArKLroPZJh1XKkK3qFMXiM79MBL2Sg,12
examples/wheel/lib/module_with_data.py,sha256=8s0Khhcqz3yVsBKv2IB5u4l4TMKh7-c_V6p65WVHPms,637
examples/wheel/lib/simple_module.py,sha256=z2hwciab_XPNIBNH8B1Q5fYgnJvQTeYf0ZQJpY8yLLY,637
examples/wheel/main.py,sha256=sgg5iWN_9inYBjm6_Zw27hYdmo-l24fA-2rfphT-IlY,909
""",
)
else:
# TODO: The non-ascii characters in the METADATA file are interpreted differently on the
# ubuntu16_rbe hosts in comparison to other unix platforms. This should not be the case
# and the code should be updated to account for this.
rbe_expected_contents = b"""\
example_customized-0.0.1.dist-info/METADATA,sha256=pzE96o3Sp63TDzxAZgl0F42EFevm8x15vpDLqDVp_EQ,378
example_customized-0.0.1.dist-info/NOTICE,sha256=Xpdw-FXET1IRgZ_wTkx1YQfo1-alET0FVf6V1LXO4js,76
example_customized-0.0.1.dist-info/README,sha256=WmOFwZ3Jga1bHG3JiGRsUheb4UbLffUxyTdHczS27-o,40
example_customized-0.0.1.dist-info/RECORD,,
example_customized-0.0.1.dist-info/WHEEL,sha256=sobxWSyDDkdg_rinUth-jxhXHqoNqlmNMJY3aTZn2Us,91
example_customized-0.0.1.dist-info/entry_points.txt,sha256=pqzpbQ8MMorrJ3Jp0ntmpZcuvfByyqzMXXi2UujuXD0,137
examples/wheel/lib/data.txt,sha256=9vJKEdfLu8bZRArKLroPZJh1XKkK3qFMXiM79MBL2Sg,12
examples/wheel/lib/module_with_data.py,sha256=8s0Khhcqz3yVsBKv2IB5u4l4TMKh7-c_V6p65WVHPms,637
examples/wheel/lib/simple_module.py,sha256=z2hwciab_XPNIBNH8B1Q5fYgnJvQTeYf0ZQJpY8yLLY,637
examples/wheel/main.py,sha256=sgg5iWN_9inYBjm6_Zw27hYdmo-l24fA-2rfphT-IlY,909
"""
unix_expected_contents = b"""\

self.assertEqual(
record_contents,
# The entries are guaranteed to be sorted.
b"""\
example_customized-0.0.1.dist-info/METADATA,sha256=TeeEmokHE2NWjkaMcVJuSAq4_AXUoIad2-SLuquRmbg,372
example_customized-0.0.1.dist-info/NOTICE,sha256=Xpdw-FXET1IRgZ_wTkx1YQfo1-alET0FVf6V1LXO4js,76
example_customized-0.0.1.dist-info/README,sha256=WmOFwZ3Jga1bHG3JiGRsUheb4UbLffUxyTdHczS27-o,40
Expand All @@ -138,15 +109,7 @@ def test_customized_wheel(self):
examples/wheel/lib/module_with_data.py,sha256=8s0Khhcqz3yVsBKv2IB5u4l4TMKh7-c_V6p65WVHPms,637
examples/wheel/lib/simple_module.py,sha256=z2hwciab_XPNIBNH8B1Q5fYgnJvQTeYf0ZQJpY8yLLY,637
examples/wheel/main.py,sha256=sgg5iWN_9inYBjm6_Zw27hYdmo-l24fA-2rfphT-IlY,909
"""
self.assertIn(
record_contents,
[
rbe_expected_contents,
unix_expected_contents,
],
)

""")
self.assertEqual(
wheel_contents,
b"""\
Expand All @@ -156,44 +119,9 @@ def test_customized_wheel(self):
Tag: py3-none-any
""",
)
if platform.system() == "Windows":
self.assertEqual(
metadata_contents,
b"""\
Metadata-Version: 2.1
Name: example_customized
Version: 0.0.1
Author: Example Author with non-ascii characters: \xc3\x85\xc2\xbc\xc3\x83\xc2\xb3\xc3\x85\xc2\x82w
Author-email: example@example.com
Home-page: www.example.com
License: Apache 2.0
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Intended Audience :: Developers
Requires-Dist: pytest

This is a sample description of a wheel.
""",
)
else:
# TODO: The non-ascii characters in the METADATA file are interpreted differently on the
# ubuntu16_rbe hosts in comparison to other unix platforms. This should not be the case
# and the code should be updated to account for this.
rbe_expected_contents = b"""\
Metadata-Version: 2.1
Name: example_customized
Version: 0.0.1
Author: Example Author with non-ascii characters: \xc3\x85\xc2\xbc\xc3\x83\xc2\xb3\xc3\x85\xc2\x82w
Author-email: example@example.com
Home-page: www.example.com
License: Apache 2.0
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Intended Audience :: Developers
Requires-Dist: pytest

This is a sample description of a wheel.
"""

unix_expected_contents = b"""\
self.assertEqual(
metadata_contents,
b"""\
Metadata-Version: 2.1
Name: example_customized
Version: 0.0.1
Expand All @@ -206,14 +134,7 @@ def test_customized_wheel(self):
Requires-Dist: pytest

This is a sample description of a wheel.
"""
self.assertIn(
metadata_contents,
[
rbe_expected_contents,
unix_expected_contents,
],
)
""")
self.assertEqual(
entry_point_contents,
b"""\
Expand Down
58 changes: 35 additions & 23 deletions python/packaging.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ def _py_wheel_impl(ctx):
args.add("--name", ctx.attr.distribution)
args.add("--version", version)
args.add("--python_tag", ctx.attr.python_tag)
args.add("--python_requires", ctx.attr.python_requires)
args.add("--abi", ctx.attr.abi)
args.add("--platform", ctx.attr.platform)
args.add("--out", outfile)
Expand All @@ -168,28 +167,42 @@ def _py_wheel_impl(ctx):

args.add("--input_file_list", packageinputfile)

extra_headers = []
# Note: Description file is 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"]
metadata_contents.append("Name: %s" % ctx.attr.distribution)
metadata_contents.append("Version: %s" % version)

if ctx.attr.author:
extra_headers.append("Author: %s" % ctx.attr.author)
metadata_contents.append("Author: %s" % ctx.attr.author)
if ctx.attr.author_email:
extra_headers.append("Author-email: %s" % ctx.attr.author_email)
metadata_contents.append("Author-email: %s" % ctx.attr.author_email)
if ctx.attr.homepage:
extra_headers.append("Home-page: %s" % ctx.attr.homepage)
metadata_contents.append("Home-page: %s" % ctx.attr.homepage)
if ctx.attr.license:
extra_headers.append("License: %s" % ctx.attr.license)

for h in extra_headers:
args.add("--header", h)
metadata_contents.append("License: %s" % ctx.attr.license)

for c in ctx.attr.classifiers:
args.add("--classifier", c)

for r in ctx.attr.requires:
args.add("--requires", r)

for option, requirements in ctx.attr.extra_requires.items():
for r in requirements:
args.add("--extra_requires", r + ";" + option)
metadata_contents.append("Classifier: %s" % c)

if ctx.attr.python_requires:
metadata_contents.append("Requires-Python: %s" % ctx.attr.python_requires)
for requirement in ctx.attr.requires:
metadata_contents.append("Requires-Dist: %s" % requirement)

for option, option_requirements in sorted(ctx.attr.extra_requires.items()):
metadata_contents.append("Provides-Extra: %s" % option)
for requirement in option_requirements:
metadata_contents.append(
"Requires-Dist: %s; extra == '%s'" % (requirement, option),
)
ctx.actions.write(
output = metadata_file,
content = "\n".join(metadata_contents) + "\n",
)
other_inputs.append(metadata_file)
args.add("--metadata_file", metadata_file)

# Merge console_scripts into entry_points.
entrypoints = dict(ctx.attr.entry_points) # Copy so we can mutate it
Expand Down Expand Up @@ -334,7 +347,9 @@ _requirement_attrs = {
doc = "List of optional requirements for this package",
),
"requires": attr.string_list(
doc = "List of requirements for this package",
doc = ("List of requirements for this package. See the section on " +
"[Declaring required dependency](https://setuptools.readthedocs.io/en/latest/userguide/dependency_management.html#declaring-dependencies) " +
"for details and examples of the format of this argument."),
),
}

Expand Down Expand Up @@ -366,7 +381,7 @@ _other_attrs = {
doc = "A list of strings describing the categories for the package. For valid classifiers see https://pypi.org/classifiers",
),
"description_file": attr.label(
doc = "A file containing text describing the package in a single line.",
doc = "A file containing text describing the package.",
allow_single_file = True,
),
"extra_distinfo_files": attr.label_keyed_string_dict(
Expand All @@ -383,10 +398,7 @@ _other_attrs = {
),
"python_requires": attr.string(
doc = (
"A string specifying what other distributions need to be installed " +
"when this one is. See the section on " +
"[Declaring required dependency](https://setuptools.readthedocs.io/en/latest/userguide/dependency_management.html#declaring-dependencies) " +
"for details and examples of the format of this argument."
"Python versions required by this distribution, e.g. '>=3.5,<3.7'"
),
default = "",
),
Expand Down
Loading