Skip to content

Commit

Permalink
feat: add requires_file for py_wheel and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
huangweixiao committed Oct 11, 2022
1 parent 2cdad9e commit 35abc61
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/packaging.md

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

13 changes: 13 additions & 0 deletions python/packaging.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 len(ctx.attr.requires) == 0 and 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)

Expand Down Expand Up @@ -351,6 +357,13 @@ _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." +
"If set `requires`, this flag will be ignored.",
)
allow_single_file = True,
),
}

_entrypoint_attrs = {
Expand Down
9 changes: 9 additions & 0 deletions tools/wheelmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ 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,
default="",
help="Requirements file for list of requirements for this package",
)

output_group = parser.add_argument_group("Output file location")
output_group.add_argument(
Expand Down Expand Up @@ -398,6 +404,9 @@ def main() -> None:
encoding="utf-8") as metadata_file:
metadata = metadata_file.read()

if arguments.requires_file:
with open(arguments.requires_file) as fp:
metadata += "\n" + fp.read().strip().split("\n")
maker.add_metadata(metadata=metadata, description=description)

if arguments.entry_points_file:
Expand Down

0 comments on commit 35abc61

Please sign in to comment.