Skip to content
Merged
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
11 changes: 11 additions & 0 deletions e2e/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,17 @@ uv.project(
)
# }}}

# For cases/uv-console-script-binary
# Regression: py_console_script_binary should work with an explicit script and
# when the script defaults to the target name.
# {{{
uv.project(
hub_name = "pypi",
lock = "//cases/uv-console-script-binary:uv.lock",
pyproject = "//cases/uv-console-script-binary:pyproject.toml",
)
# }}}

# For cases/uv-include-group (PEP 735 include-group syntax)
# {{{
uv.project(
Expand Down
22 changes: 22 additions & 0 deletions e2e/cases/uv-console-script-binary/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@aspect_rules_py//uv/unstable:defs.bzl", "py_console_script_binary")
load("@rules_shell//shell:sh_test.bzl", "sh_test")

py_console_script_binary(
name = "whoowns",
pkg = "@pypi//whoowns",
)

py_console_script_binary(
name = "whoowns_explicit",
pkg = "@pypi//whoowns",
script = "whoowns",
)

sh_test(
name = "test",
srcs = ["test.sh"],
data = [
":whoowns",
":whoowns_explicit",
],
)
8 changes: 8 additions & 0 deletions e2e/cases/uv-console-script-binary/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[project]
name = "uv-console-script-binary"
version = "0.0.0"
requires-python = ">=3.11"
authors = []
dependencies = [
"whoowns",
]
28 changes: 28 additions & 0 deletions e2e/cases/uv-console-script-binary/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail

DIR="$(cd "$TEST_SRCDIR/_main/cases/uv-console-script-binary" && pwd)"
DEFAULT_BIN="${DIR}/whoowns"
EXPLICIT_BIN="${DIR}/whoowns_explicit"

for bin in "${DEFAULT_BIN}" "${EXPLICIT_BIN}"; do
if [[ ! -x "${bin}" ]]; then
echo "FAIL: expected executable binary at ${bin}" >&2
exit 1
fi
done

default_out="$("${DEFAULT_BIN}" --help 2>&1)"
explicit_out="$("${EXPLICIT_BIN}" --help 2>&1)"

if [[ -z "${default_out}" ]]; then
echo "FAIL: default-name console script produced no help output" >&2
exit 1
fi

if [[ -z "${explicit_out}" ]]; then
echo "FAIL: explicit-script console script produced no help output" >&2
exit 1
fi

echo "PASS: both console script binaries executed"
23 changes: 23 additions & 0 deletions e2e/cases/uv-console-script-binary/uv.lock

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

4 changes: 4 additions & 0 deletions uv/private/py_entrypoint_binary/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
load(":test.bzl", "py_entrypoint_binary_test_suite")

exports_files([
"entrypoint.tmpl",
"search.py",
])

py_entrypoint_binary_test_suite()
7 changes: 5 additions & 2 deletions uv/private/py_entrypoint_binary/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
load("@bazel_lib//lib:expand_template.bzl", "expand_template")
load("//py/unstable:defs.bzl", "py_venv_binary")

def console_script_name(name, script):
return script or name

def py_entrypoint_binary(
name,
entrypoint,
Expand Down Expand Up @@ -44,8 +47,8 @@ def py_entrypoint_binary(

def py_console_script_binary(
name,
script,
pkg,
script = None,
visibility = ["//visibility:public"]):
main = "_{}_entrypoint".format(name)
tmpl = Label("@aspect_rules_py//uv/private/py_entrypoint_binary:entrypoint.tmpl")
Expand All @@ -72,7 +75,7 @@ def py_console_script_binary(
srcs = [
tmpl,
],
cmd = "$(location {}) --template=\"$(location {})\" --script=\"{}\" >\"$@\"".format(search_tool, tmpl, script),
cmd = "$(location {}) --template=\"$(location {})\" --script=\"{}\" >\"$@\"".format(search_tool, tmpl, console_script_name(name, script)),
)

py_venv_binary(
Expand Down
23 changes: 23 additions & 0 deletions uv/private/py_entrypoint_binary/test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
load(":defs.bzl", "console_script_name")

def _uses_explicit_script_name_test_impl(ctx):
env = unittest.begin(ctx)
asserts.equals(env, "custom-script", console_script_name("binary_name", "custom-script"))
return unittest.end(env)

uses_explicit_script_name_test = unittest.make(_uses_explicit_script_name_test_impl)

def _defaults_to_target_name_test_impl(ctx):
env = unittest.begin(ctx)
asserts.equals(env, "binary_name", console_script_name("binary_name", None))
return unittest.end(env)

defaults_to_target_name_test = unittest.make(_defaults_to_target_name_test_impl)

def py_entrypoint_binary_test_suite():
unittest.suite(
"py_entrypoint_binary_tests",
uses_explicit_script_name_test,
defaults_to_target_name_test,
)
Loading