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 2 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 len(ctx.attr.requires) == 0 and ctx.attr.requires_file:
weixiao-huang marked this conversation as resolved.
Show resolved Hide resolved
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. 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="",
weixiao-huang marked this conversation as resolved.
Show resolved Hide resolved
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:
weixiao-huang marked this conversation as resolved.
Show resolved Hide resolved
metadata += "\n" + fp.read().strip().split("\n")
maker.add_metadata(metadata=metadata, description=description)

if arguments.entry_points_file:
Expand Down