Skip to content
Open
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
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ sphinxdocs
tests/integration/compile_pip_requirements/bazel-compile_pip_requirements
tests/integration/local_toolchains/bazel-local_toolchains
tests/integration/py_cc_toolchain_registered/bazel-py_cc_toolchain_registered
tests/integration/sys_executable_cross_runtime/bazel-module_under_test
tests/integration/toolchain_target_settings/bazel-module_under_test
1 change: 1 addition & 0 deletions .bazelrc.deleted_packages
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ common --deleted_packages=tests/integration/pip_parse
common --deleted_packages=tests/integration/pip_parse/empty
common --deleted_packages=tests/integration/pip_parse_isolated
common --deleted_packages=tests/integration/py_cc_toolchain_registered
common --deleted_packages=tests/integration/sys_executable_cross_runtime
common --deleted_packages=tests/integration/toolchain_target_settings
common --deleted_packages=tests/modules/another_module
common --deleted_packages=tests/modules/other
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ rules_python_integration_test(
py_main = "toolchain_target_settings_test.py",
)

rules_python_integration_test(
name = "sys_executable_cross_runtime_test",
)

py_library(
name = "runner_lib",
srcs = ["runner.py"],
Expand Down
38 changes: 38 additions & 0 deletions tests/integration/sys_executable_cross_runtime/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
load("@rules_python//python:py_binary.bzl", "py_binary")
load("@rules_shell//shell:sh_test.bzl", "sh_test")

py_binary(
name = "child",
srcs = ["child.py"],
main = "child.py",
python_version = "3.11",
)

py_binary(
name = "parent",
srcs = ["parent.py"],
data = [":child"],
deps = ["@rules_python//python/runfiles"],
main = "parent.py",
python_version = "3.12",
)

sh_test(
name = "child_direct_test",
srcs = ["run_parent.sh"],
data = [":parent"],
env = {
"MODE": "direct",
"PARENT_BINARY": "$(rootpath :parent)",
},
)

sh_test(
name = "child_sys_executable_test",
srcs = ["run_parent.sh"],
data = [":parent"],
env = {
"MODE": "sys_executable",
"PARENT_BINARY": "$(rootpath :parent)",
},
)
20 changes: 20 additions & 0 deletions tests/integration/sys_executable_cross_runtime/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module(name = "module_under_test")

bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "rules_python", version = "0.0.0")
local_path_override(
module_name = "rules_python",
path = "../../..",
)

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.defaults(python_version = "3.12")
python.toolchain(
configure_coverage_tool = True,
python_version = "3.11",
)
python.toolchain(
configure_coverage_tool = True,
python_version = "3.12",
)
use_repo(python, "python_3_11", "python_3_12", "python_versions", "pythons_hub")
Empty file.
Empty file.
10 changes: 10 additions & 0 deletions tests/integration/sys_executable_cross_runtime/child.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import re


def main() -> None:
re.compile("child")
print("child completed")


if __name__ == "__main__":
main()
36 changes: 36 additions & 0 deletions tests/integration/sys_executable_cross_runtime/parent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import subprocess
import sys

from python.runfiles import Runfiles


def main() -> int:
assert len(sys.argv) == 2
mode = sys.argv[1]
runfiles = Runfiles.Create()
child = runfiles.Rlocation("_main/child")
assert child is not None

# Reproduce the broken contract: the parent exports its own runtime import
# paths, then starts the child launcher with sys.executable. The child
# launcher re-execs into its own interpreter, but the inherited PYTHONPATH
# still points at the parent's stdlib and site-packages.
os.environ["PYTHONPATH"] = os.pathsep.join(sys.path)

if mode == "sys_executable":
argv = [sys.executable, child]
elif mode == "direct":
argv = [child]
else:
raise RuntimeError(f"unknown launch mode: {mode}")

proc = subprocess.run(
argv,
check=False,
)
return proc.returncode


if __name__ == "__main__":
raise SystemExit(main())
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail

"${PARENT_BINARY}" "${MODE}"