diff --git a/docs/packaging.md b/docs/packaging.md index af822b07eb..c62a91da83 100755 --- a/docs/packaging.md +++ b/docs/packaging.md @@ -31,7 +31,7 @@ This rule is intended to be used as data dependency to py_wheel rule
py_wheel(name, abi, author, author_email, classifiers, console_scripts, deps, description_file, distribution, entry_points, extra_distinfo_files, extra_requires, homepage, license, - platform, python_requires, python_tag, requires, stamp, strip_path_prefixes, version) + platform, python_requires, python_tag, requires, requires_file, stamp, strip_path_prefixes, version)@@ -102,6 +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. 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.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 6d7a901f53..6a9dd5d133 100644
--- a/python/packaging.bzl
+++ b/python/packaging.bzl
@@ -188,6 +188,12 @@ def _py_wheel_impl(ctx):
if ctx.attr.python_requires:
metadata_contents.append("Requires-Python: %s" % ctx.attr.python_requires)
+
+ if ctx.attr.requires_file:
+ requires_file = ctx.file.requires_file
+ args.add("--requires_file", requires_file)
+ other_inputs.append(requires_file)
+
for requirement in ctx.attr.requires:
metadata_contents.append("Requires-Dist: %s" % requirement)
@@ -351,6 +357,10 @@ _requirement_attrs = {
"[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."),
),
+ "requires_file": attr.label(
+ doc = "Requirements file for list of requirements for this package, which will be additive after `requires`",
+ allow_single_file = True,
+ ),
}
_entrypoint_attrs = {
diff --git a/tools/wheelmaker.py b/tools/wheelmaker.py
index d5179001a6..d8231dced5 100644
--- a/tools/wheelmaker.py
+++ b/tools/wheelmaker.py
@@ -258,6 +258,11 @@ def parse_args() -> argparse.Namespace:
metadata_group.add_argument(
"--platform", type=str, default="any", help="Target platform. "
)
+ metadata_group.add_argument(
+ "--requires_file",
+ type=Path,
+ 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")
output_group.add_argument(
@@ -398,6 +403,10 @@ def main() -> None:
encoding="utf-8") as metadata_file:
metadata = metadata_file.read()
+ if arguments.requires_file:
+ with open(arguments.requires_file) as fp:
+ 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: