From cd7edd71c11ad437bceda117e430c71eeb5c6122 Mon Sep 17 00:00:00 2001 From: weixiao huang Date: Wed, 12 Oct 2022 23:02:55 +0800 Subject: [PATCH] fix: make requires_file additive and fix Requires-Dist bug --- docs/packaging.md | 2 +- python/packaging.bzl | 4 ++-- tools/wheelmaker.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/packaging.md b/docs/packaging.md index 81e8bbc861..c62a91da83 100755 --- a/docs/packaging.md +++ b/docs/packaging.md @@ -102,7 +102,7 @@ py_wheel( | python_requires | Python versions required by this distribution, e.g. '>=3.5,<3.7' | String | optional | "" | | python_tag | Supported Python version(s), eg py3, cp35.cp36, etc | String | optional | "py3" | | requires | 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. | List of strings | optional | [] | -| requires_file | Requirements file for list of requirements for this package. If set `requires`, this flag will be ignored. | Label | optional | None | +| requires_file | Requirements file for list of requirements for this package. which will be additive after `requires` | Label | optional | None | | stamp | Whether to encode build information into the wheel. Possible values:

- stamp = 1: Always stamp the build information into the wheel, even in [--nostamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.

- stamp = 0: Always replace build information by constant values. This gives good build result caching.

- stamp = -1: Embedding of build information is controlled by the [--[no]stamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) flag.

Stamped targets are not rebuilt unless their dependencies change. | Integer | optional | -1 | | strip_path_prefixes | path prefixes to strip from files added to the generated package | List of strings | optional | [] | | version | Version number of the package. Note that this attribute supports stamp format strings (eg. 1.2.3-{BUILD_TIMESTAMP}) as well as 'make variables' (e.g. 1.2.3-$(VERSION)). | String | required | | diff --git a/python/packaging.bzl b/python/packaging.bzl index f5993f9aa5..6a9dd5d133 100644 --- a/python/packaging.bzl +++ b/python/packaging.bzl @@ -189,7 +189,7 @@ def _py_wheel_impl(ctx): if ctx.attr.python_requires: metadata_contents.append("Requires-Python: %s" % ctx.attr.python_requires) - if len(ctx.attr.requires) == 0 and ctx.attr.requires_file: + if ctx.attr.requires_file: requires_file = ctx.file.requires_file args.add("--requires_file", requires_file) other_inputs.append(requires_file) @@ -358,7 +358,7 @@ _requirement_attrs = { "for details and examples of the format of this argument."), ), "requires_file": attr.label( - doc = "Requirements file for list of requirements for this package. If set `requires`, this flag will be ignored.", + doc = "Requirements file for list of requirements for this package, which will be additive after `requires`", allow_single_file = True, ), } diff --git a/tools/wheelmaker.py b/tools/wheelmaker.py index 63efca5ab0..d8231dced5 100644 --- a/tools/wheelmaker.py +++ b/tools/wheelmaker.py @@ -261,8 +261,7 @@ def parse_args() -> argparse.Namespace: metadata_group.add_argument( "--requires_file", type=Path, - default="", - help="Requirements file for list of requirements for this package", + help="Requirements file for list of requirements for this package, which will be additive after `requires`", ) output_group = parser.add_argument_group("Output file location") @@ -406,7 +405,8 @@ def main() -> None: if arguments.requires_file: with open(arguments.requires_file) as fp: - metadata += "\n" + fp.read().strip().split("\n") + additive_requires_list = ["Requires-Dist: {}".format(line) for line in fp.read().strip().split("\n")] + metadata += "\n" + "\n".join(additive_requires_list) maker.add_metadata(metadata=metadata, description=description) if arguments.entry_points_file: