rules_python
rules_python copied to clipboard
Add targets for wheel scripts
#523 added py_binary targets for console_scripts, (Python entry points), but scripts (arbitrary executables) are omitted.
Moreoever, scripts (under the scripts/ directory in the wheel) are not exposed in any way.
Examples: ansible-test from the ansible-core package, aws from the awscli package. Currently, these cannot be run.
Suggestion: Add sh_binary target for these scripts.
In many cases these scripts are in fact Python, and use a system Python runtime, so you may or may not want to actually invoke the executable target.
However, even then it would still at least be available as a file via DefaultInfo. So you could create your own py_binary, using the toolchain python.
This comes up from time to time. Isn't python packaging "fun". 😂
Setuptools "scripts" have been replaced by entry_points in setuptools and it's generally only legacy or old packages that still use them (anything of a python2 heritage).
ansible-test is very old and appears unmaintained. Do you think they would accept an upstream patch to switch to entry_points?
awscli is an interesting one. There's an issue about switching to entry_points but it was closed due to inactivity. In awscli-v2, they've removed them (not published to PyPI yet).
As a workaround for now, can you add your own py_binary with that small snippet to launch the awscli driver?
ansible-test is very old and appears unmaintained.
Sorry, I meant the (very much alive) ansible package, which has the ansible-test executable. Oddly, it has several executables that use console_scripts, but ansible-test does not.
As a workaround for now, can you add your own py_binary with that small snippet to launch the awscli driver?
Yes, a workaround is to simply copy that script.
Or use the following macro to pull the script out:
load("@rules_python//python:defs.bzl", "py_binary")
def py_wheel_script(name, script, pkg, whl, prefix, visibility = None):
entrypoint = "%s.py" % name
native.genrule(
name = "%s.entrypoint" % name,
cmd = "unzip -p $< %s.data/scripts/%s > $@" % (prefix, script),
outs = [entrypoint],
srcs = [whl],
visibility = ["//visibility:private"],
)
py_binary(
name = name,
deps = [pkg],
srcs = [entrypoint],
visibility = visibility,
)
py_wheel_script(
name = "aws",
pkg = "@pypi_awscli//:pkg",
prefix = "awscli-1.25.58",
script = "aws",
whl = "@pypi_awscli//:whl",
)
Which version of ansible are you using? It seems they migrated to entry_points in October 2021 https://github.com/ansible/ansible/pull/76021
Maybe they've just missed that entry_point and a small upstream PR could be submitted? Are you using a version of ansible that includes that PR?
Maybe they've just missed that entry_point and a small upstream PR could be submitted?
Probably. Like I said, that the only entry point that works that way.
This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_python!
This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"