Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add requires_file attr for py_wheel #644

Closed
Closed
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
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.

10 changes: 10 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 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,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 = {
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,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(
Expand Down Expand Up @@ -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:
weixiao-huang marked this conversation as resolved.
Show resolved Hide resolved
additive_requires_list = ["Requires-Dist: {}".format(line) for line in fp.read().strip().split("\n")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why read().strip().split() and not readlines()?

metadata += "\n" + "\n".join(additive_requires_list)
Copy link
Collaborator

@pstradomski pstradomski Oct 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't that leave you with two \n in a row, so everything below will be interpreted as a description?

Can we have a test?

maker.add_metadata(metadata=metadata, description=description)

if arguments.entry_points_file:
Expand Down