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
7 changes: 7 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,10 @@ oci.pull(
tag = "latest",
)
use_repo(oci, "ubuntu", "ubuntu_linux_amd64", "ubuntu_linux_arm64_v8")

local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")

local_repository(
name = "rpy610_test",
path = "./py/tests/rpy610/subrepo",
)
5 changes: 5 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,8 @@ oci_pull(
load("@container_structure_test//:repositories.bzl", "container_structure_test_register_toolchain")

container_structure_test_register_toolchain(name = "cst")

local_repository(
name = "rpy610_test",
path = "./py/tests/rpy610/subrepo",
)
2 changes: 1 addition & 1 deletion py/tests/py-venv-standalone-interpreter/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -ex

ROOT="$(dirname $0)"

"$ROOT"/.ex/bin/python --help
"$ROOT"/.ex/bin/python --help >/dev/null 2>&1

if [ "Hello, world!" != "$($ROOT/.ex/bin/python -c 'from ex import hello; print(hello())')" ]; then
exit 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2442,7 +2442,9 @@ files:
layer: 1
files:
- drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_venv_image_layer/.my_app_bin/lib/python3.9/site-packages/
- -rwxr-xr-x 0 0 0 328 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_venv_image_layer/.my_app_bin/lib/python3.9/site-packages/_aspect.pth
- -rwxr-xr-x 0 0 0 416 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_venv_image_layer/.my_app_bin/lib/python3.9/site-packages/_aspect.bzlpth
- -rwxr-xr-x 0 0 0 15 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_venv_image_layer/.my_app_bin/lib/python3.9/site-packages/_aspect.pth
- -rwxr-xr-x 0 0 0 1151 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_venv_image_layer/.my_app_bin/lib/python3.9/site-packages/_aspect.py
- -rwxr-xr-x 0 0 0 19 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_venv_image_layer/.my_app_bin/lib/python3.9/site-packages/_virtualenv.pth
- -rwxr-xr-x 0 0 0 4342 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_venv_image_layer/.my_app_bin/lib/python3.9/site-packages/_virtualenv.py
- drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_venv_image_layer/.my_app_bin/lib/python3.9/site-packages/colorama-0.4.6.dist-info/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2423,7 +2423,9 @@ files:
layer: 1
files:
- drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_venv_image_layer/.my_app_bin/lib/python3.9/site-packages/
- -rwxr-xr-x 0 0 0 328 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_venv_image_layer/.my_app_bin/lib/python3.9/site-packages/_aspect.pth
- -rwxr-xr-x 0 0 0 416 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_venv_image_layer/.my_app_bin/lib/python3.9/site-packages/_aspect.bzlpth
- -rwxr-xr-x 0 0 0 15 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_venv_image_layer/.my_app_bin/lib/python3.9/site-packages/_aspect.pth
- -rwxr-xr-x 0 0 0 1151 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_venv_image_layer/.my_app_bin/lib/python3.9/site-packages/_aspect.py
- -rwxr-xr-x 0 0 0 19 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_venv_image_layer/.my_app_bin/lib/python3.9/site-packages/_virtualenv.pth
- -rwxr-xr-x 0 0 0 4342 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_venv_image_layer/.my_app_bin/lib/python3.9/site-packages/_virtualenv.py
- drwxr-xr-x 0 0 0 0 Jan 1 2023 ./py/tests/py_venv_image_layer/my_app_bin.runfiles/aspect_rules_py/py/tests/py_venv_image_layer/.my_app_bin/lib/python3.9/site-packages/colorama-0.4.6.dist-info/
Expand Down
16 changes: 16 additions & 0 deletions py/tests/rpy610/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("//py/private/py_venv:defs.bzl", "py_venv_test")

py_venv_test(
name = "test",
srcs = [
"test.py",
],
imports = [
".",
],
main = "test.py",
deps = [
"@pypi_cowsay//:pkg",
"@rpy610_test//:foo",
],
)
10 changes: 10 additions & 0 deletions py/tests/rpy610/subrepo/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@aspect_rules_py//py:defs.bzl", "py_library")

py_library(
name = "foo",
srcs = [
"foo.py",
],
imports = ["."],
visibility = ["//visibility:public"],
)
Empty file.
2 changes: 2 additions & 0 deletions py/tests/rpy610/subrepo/foo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def foo(x):
return x ** 3.15
32 changes: 32 additions & 0 deletions py/tests/rpy610/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3

import os
import sys
import site

print("---")
print("__file__:", __file__)
print("sys.prefix:", sys.prefix)
print("sys.executable:", sys.executable)
print("site.PREFIXES:")
for p in site.PREFIXES:
print(" -", p)

# The virtualenv module should have already been loaded at interpreter startup
assert "_virtualenv" in sys.modules

# Note that we can't assume that a `.runfiles` tree has been created as CI may
# use a different layout.

# The virtualenv changes the sys.prefix, which should be in our runfiles
assert sys.prefix.endswith("/py/tests/rpy610/.test")

# That prefix should also be "the" prefix per site.PREFIXES
assert site.PREFIXES[0].endswith("/py/tests/rpy610/.test")

# The virtualenv also changes the sys.executable (if we've done this right)
assert sys.executable.find("/py/tests/rpy610/.test/bin/python") != -1

# aspect-build/rules_py#610, these imports aren't quite right
import foo
print(foo.__file__)
1 change: 1 addition & 0 deletions py/tools/py/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ rust_library(
"src/venv.rs",
],
data = [
"src/_aspect.py",
"src/_virtualenv.py",
"src/activate.tmpl",
"src/pyvenv.cfg.tmpl",
Expand Down
34 changes: 34 additions & 0 deletions py/tools/py/src/_aspect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Bazel runfiles appropriate pth extensions.

Very carefully avoids resolving symlink path parts as doing so can result in
unintended escapes from runfiles sandbox trees.

"""

import os
import site

site_dir = os.path.dirname(__file__)

# FIXME: Are there other runfiles dir identification strategies that matter?
runfiles_dir = os.getenv("RUNFILES_DIR")
if not runfiles_dir:
p = site_dir
while p != "/":
if p.endswith(".runfiles"):
break
p = os.path.dirname(p)
else:
raise RuntimeError("Failed to identify the runfiles root by path traversal!")
runfiles_dir = p

# Now that we have the runfiles root, the required additional site paths are
# just the join of the runfiles root and the already bzlmod-transformed roots
# provided by the `rules_py` venv creation code. Join them and add them.
with open(os.path.join(site_dir, "_aspect.bzlpth")) as fp:
for line in fp:
line = line.strip()
p = os.path.normpath(os.path.join(site_dir, line))
# FIXME: Do we want to process embedded pth files? Or just insert
# the paths into the sys.path
site.addsitedir(p)
Loading
Loading