Skip to content

Commit 5ec374e

Browse files
committed
chore(#610): Create a test case
1 parent d11acb4 commit 5ec374e

File tree

7 files changed

+74
-2
lines changed

7 files changed

+74
-2
lines changed

MODULE.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,9 @@ oci.pull(
114114
tag = "latest",
115115
)
116116
use_repo(oci, "ubuntu", "ubuntu_linux_amd64", "ubuntu_linux_arm64_v8")
117+
118+
local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
119+
local_repository(
120+
name = "rpy610_test",
121+
path = "./py/tests/rpy610/subrepo",
122+
)

py/tests/rpy610/BUILD.bazel

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
load("//py/private/py_venv:defs.bzl", "py_venv_test")
2+
3+
py_venv_test(
4+
name = "test",
5+
srcs = [
6+
"test.py",
7+
],
8+
imports = [
9+
".",
10+
],
11+
main = "test.py",
12+
deps = [
13+
"@pypi_cowsay//:pkg",
14+
"@rpy610_test//:foo"
15+
],
16+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
load("@aspect_rules_py//py:defs.bzl", "py_library")
2+
3+
py_library(
4+
name = "foo",
5+
srcs = [
6+
"foo.py"
7+
],
8+
imports = ["."],
9+
visibility = ["//visibility:public"]
10+
)

py/tests/rpy610/subrepo/MODULE.bazel

Whitespace-only changes.

py/tests/rpy610/subrepo/foo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def foo(x):
2+
return x ** 3.15

py/tests/rpy610/test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
import site
6+
7+
print("---")
8+
print("__file__:", __file__)
9+
print("sys.prefix:", sys.prefix)
10+
print("sys.executable:", sys.executable)
11+
print("site.PREFIXES:")
12+
for p in site.PREFIXES:
13+
print(" -", p)
14+
15+
# The virtualenv module should have already been loaded at interpreter startup
16+
assert "_virtualenv" in sys.modules
17+
18+
# Note that we can't assume that a `.runfiles` tree has been created as CI may
19+
# use a different layout.
20+
21+
# The virtualenv changes the sys.prefix, which should be in our runfiles
22+
assert sys.prefix.endswith("/py/tests/rpy610/.test")
23+
24+
# That prefix should also be "the" prefix per site.PREFIXES
25+
assert site.PREFIXES[0].endswith("/py/tests/rpy610/.test")
26+
27+
# The virtualenv also changes the sys.executable (if we've done this right)
28+
assert sys.executable.find("/py/tests/rpy610/.test/bin/python") != -1
29+
30+
# aspect-build/rules_py#610, these imports aren't quite right
31+
import foo
32+
print(foo.__file__)

py/tools/py/src/venv.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ pub fn populate_venv_with_copies(
486486
.into_diagnostic()?;
487487

488488
for line in BufReader::new(source_pth).lines().map_while(Result::ok) {
489-
#[cfg(feature = "debug")]
489+
//#[cfg(feature = "debug")]
490490
eprintln!("Got pth line {}", &line);
491491

492492
let line = line.trim().to_string();
@@ -553,6 +553,13 @@ pub fn populate_venv_with_copies(
553553
//
554554
// [1] https://github.com/python/cpython/blob/ce31ae5209c976d28d1c21fcbb06c0ae5e50a896/Lib/site.py#L215
555555

556+
// aspect-build/rules_py#610
557+
//
558+
// While these relative paths seem to work fine for _internal_
559+
// runfiles within the `_main` workspace, problems occur when we
560+
// try to take relative paths to _other_ workspaces because bzlmod
561+
// may munge the directory names to be something that doesn't
562+
// exist.
556563
let path_to_runfiles =
557564
diff_paths(&action_bin_dir, action_bin_dir.join(&venv.site_dir)).unwrap();
558565

@@ -566,7 +573,6 @@ pub fn populate_venv_with_copies(
566573
}
567574
}
568575

569-
//Err(miette!("Failing for debug purposes"))
570576
Ok(())
571577
}
572578

0 commit comments

Comments
 (0)