8000 runfiles: Import `CurrentRepository` from Bazel (#988) · cflewis/rules_python@a475144 · GitHub
[go: up one dir, main page]

Skip to content

Commit a475144

Browse files
authored
runfiles: Import CurrentRepository from Bazel (bazel-contrib#988)
Also adds an integration test to the BCR test module that replaces the tests maintained in Bazel itself.
1 parent aab11ab commit a475144

File tree

13 files changed

+177
-3
lines changed

13 files changed

+177
-3
lines changed

.bazelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# This lets us glob() up all the files inside the examples to make them inputs to tests
44
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
55
# To update these lines, run tools/bazel_integration_test/update_deleted_packages.sh
6-
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/get_url,examples/bzlmod,examples/multi_python_versions,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/relative_requirements,tests/compile_pip_requirements,tests/pip_repository_entry_points,tests/pip_deps
7-
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/get_url,examples/bzlmod,examples/multi_python_versions,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/relative_requirements,tests/compile_pip_requirements,tests/pip_repository_entry_points,tests/pip_deps
6+
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/get_url,examples/bzlmod,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/runfiles,examples/multi_python_versions,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/relative_requirements,tests/compile_pip_requirements,tests/pip_repository_entry_points,tests/pip_deps
7+
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/get_url,examples/bzlmod,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/runfiles,examples/multi_python_versions,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/relative_requirements,tests/compile_pip_requirements,tests/pip_repository_entry_points,tests/pip_deps
88

99
test --test_output=errors
1010

examples/bzlmod/.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
other_module

examples/bzlmod/MODULE.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ pip.parse(
2828
requirements_windows = "//:requirements_windows.txt",
2929
)
3030
use_repo(pip, "pip")
31+
32+
bazel_dep(name = "other_module", version = "")
33+
local_path_override(
34+
module_name = "other_module",
35+
path = "other_module",
36+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module(
2+
name = "other_module",
3+
)
4+
5+
bazel_dep(name = "rules_python", version = "")

examples/bzlmod/other_module/WORKSPACE

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
load("@rules_python//python:defs.bzl", "py_library")
2+
3+
py_library(
4+
name = "lib",
5+
srcs = ["lib.py"],
6+
data = ["data/data.txt"],
7+
visibility = ["//visibility:public"],
8+
deps = ["@rules_python//python/runfiles"],
9+
)
10+
11+
exports_files(["data/data.txt"])
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello, other_module!
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from python.runfiles import runfiles
2+
3+
4+
def GetRunfilePathWithCurrentRepository():
5+
r = runfiles.Create()
6+
own_repo = r.CurrentRepository()
7+
# For a non-main repository, the name of the runfiles directory is equal to
8+
# the canonical repository name.
9+
return r.Rlocation(own_repo + "/other_module/pkg/data/data.txt")

examples/bzlmod/runfiles/BUILD.bazel

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
load("@rules_python//python:defs.bzl", "py_test")
2+
3+
py_test(
4+
name = "runfiles_test",
5+
srcs = ["runfiles_test.py"],
6+
data = [
7+
"data/data.txt",
8+
"@other_module//other_module/pkg:data/data.txt",
9+
],
10+
env = {
11+
"DATA_RLOCATIONPATH": "$(rlocationpath data/data.txt)",
12+
"OTHER_MODULE_DATA_RLOCATIONPATH": "$(rlocationpath @other_module//other_module/pkg:data/data.txt)",
13+
},
14+
deps = [
15+
"@other_module//other_module/pkg:lib",
16+
"@rules_python//python/runfiles",
17+
],
18+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello, example_bzlmod!

0 commit comments

Comments
 (0)
0