Skip to content

Commit 1b6fe66

Browse files
author
Shayan Hoshyari
committed
Add an actual test
1 parent b12c201 commit 1b6fe66

6 files changed

Lines changed: 60 additions & 4 deletions

File tree

python/private/py_executable.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,6 @@ def _create_venv(ctx, output_prefix, imports, runtime_details, add_runfiles_root
633633
# to `_main` prefix, and binaries from non-root module become broken.
634634
lib_runfiles = ctx.runfiles(
635635
root_symlinks = venv_app_files.runfiles_symlinks,
636-
##symlinks = venv_app_files.runfiles_symlinks,
637636
),
638637
)
639638

python/private/venv_runfiles.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def create_venv_app_files(ctx, deps, venv_dir_map):
6868
# runfile_prefix should be prepended as we use runfiles.root_symlinks
6969
runfile_prefix = ctx.label.repo_name or ctx.workspace_name
7070
symlink_from = paths.join(runfile_prefix, ctx.label.package, bin_venv_path)
71-
##symlink_from = paths.join(ctx.label.package, bin_venv_path)
7271

7372
runfiles_symlinks[symlink_from] = link_to
7473
else:

tests/modules/other/BUILD.bazel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ py_binary(
1818
name = "venv_bin",
1919
srcs = ["venv_bin.py"],
2020
config_settings = {
21-
"@rules_python//python/config_settings:venvs_site_packages": "yes",
2221
"@rules_python//python/config_settings:bootstrap_impl": "script",
22+
# To make paths we are using in the test deterministic
23+
"@rules_python//python/config_settings:python_version": "3.13",
24+
"@rules_python//python/config_settings:venvs_site_packages": "yes",
2325
},
2426
deps = [
2527
# Add two packages that install into the same directory. This is

tests/modules/other/venv_bin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
import nspkg.subnspkg.delta
44
import nspkg.subnspkg.gamma
55

6-
print("hi")
6+
print("@other//:venv_bin ran successfully.")

tests/venv_site_packages_libs/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@rules_shell//shell:sh_test.bzl", "sh_test")
12
load("//python:py_library.bzl", "py_library")
23
load("//tests/support:py_reconfig.bzl", "py_reconfig_test")
34
load(
@@ -19,6 +20,17 @@ py_library(
1920
],
2021
)
2122

23+
sh_test(
24+
name = "py_binary_other_module_test",
25+
srcs = [
26+
"py_binary_other_module_test.sh",
27+
],
28+
data = [
29+
"@other//:venv_bin",
30+
],
31+
target_compatible_with = NOT_WINDOWS,
32+
)
33+
2234
py_reconfig_test(
2335
name = "venvs_site_packages_libs_test",
2436
srcs = ["bin.py"],
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#
2+
# Test that for a py_binary from a dependency module, we place links created via runfiles(...)
3+
# in the right place. This tests the fix made for issues/3503
4+
#
5+
6+
set -eu
7+
8+
# Helper to check links exist and where they point to
9+
check_link() {
10+
link=$1
11+
12+
# 1) Must exist
13+
if [ ! -e "$link" ]; then
14+
return 1
15+
fi
16+
17+
# 2) Must be a symlink
18+
if [ ! -L "$link" ]; then
19+
return 1
20+
fi
21+
}
22+
23+
ensure_link() {
24+
if ! check_link $1; then
25+
echo "ERROR: $link does not exist"
26+
return 1
27+
fi
28+
}
29+
30+
# Sanity check that invalid files don't exist.
31+
echo "[*] Sanity check our ensure_link function"
32+
if check_link ${RUNFILES_DIR}/__I_DO_NOT_EXIST__; then
33+
echo "Check link function is broken"
34+
exit 1
35+
fi
36+
37+
# Check the links exist in the correct place.
38+
echo "[*] Testing existence of symlinks in the right place"
39+
ensure_link ${RUNFILES_DIR}/other+/_venv_bin.venv/lib/python3.13/site-packages/nspkg/subnspkg/delta/__init__.py
40+
ensure_link ${RUNFILES_DIR}/other+/_venv_bin.venv/lib/python3.13/site-packages/nspkg/subnspkg/gamma/__init__.py
41+
42+
# Finally, test that running the binary works, i.e imports are resolved.
43+
echo "[*] Testing running the binary"
44+
${RUNFILES_DIR}/other+/venv_bin

0 commit comments

Comments
 (0)