diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f0bcc1ad..12bbedb3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -26,13 +26,21 @@ jobs: uses: bazel-contrib/.github/.github/workflows/bazel.yaml@646899086d7aaee8e532540480f3e91e00596234 # 11 Dec 2024 with: # NB: the root folder is tested with Aspect Workflows on BuildKite, see /.aspect/workflows/config.yaml - folders: '["e2e/smoke", "e2e/repository-rule-deps", "e2e/system-interpreter", "examples/uv_pip_compile"]' + folders: | + [ + "e2e/cross-repo-610", + "e2e/repository-rule-deps", + "e2e/smoke", + "e2e/system-interpreter", + "examples/uv_pip_compile" + ] # TODO: Build Windows tools and add to toolchain # TODO(alex): switch the root folder to bzlmod # TODO: fix remaining folders on Bazel 8 exclude: | [ {"os": "windows-latest"}, + {"folder": "e2e/cross-repo-610", "bzlmodEnabled": false}, {"folder": "e2e/repository-rule-deps", "bzlmodEnabled": false}, {"folder": "e2e/system-interpreter", "bzlmodEnabled": false}, {"folder": "examples/uv_pip_compile", "bzlmodEnabled": false}, diff --git a/MODULE.bazel b/MODULE.bazel index 42965e9f..920b210c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -114,11 +114,3 @@ oci.pull( tag = "latest", ) use_repo(oci, "ubuntu", "ubuntu_linux_amd64", "ubuntu_linux_arm64_v8") - -# For tests -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", -) diff --git a/e2e/cross-repo-610/BUILD.bazel b/e2e/cross-repo-610/BUILD.bazel new file mode 100644 index 00000000..3db0de5c --- /dev/null +++ b/e2e/cross-repo-610/BUILD.bazel @@ -0,0 +1,24 @@ +load("@aspect_rules_py//py/unstable:defs.bzl", "py_venv_test") +load("@rules_python//python/pip_install:requirements.bzl", "compile_pip_requirements") + +py_venv_test( + name = "test", + srcs = [ + "test.py", + ], + imports = [ + ".", + ], + main = "test.py", + deps = [ + "@pip//cowsay", + "@subrepo_a//:foo", + ], +) + +compile_pip_requirements( + name = "requirements", + extra_args = ["--allow-unsafe"], + requirements_in = "requirements.in", + requirements_txt = "requirements.txt", +) diff --git a/e2e/cross-repo-610/MODULE.bazel b/e2e/cross-repo-610/MODULE.bazel new file mode 100644 index 00000000..06c398b2 --- /dev/null +++ b/e2e/cross-repo-610/MODULE.bazel @@ -0,0 +1,48 @@ +"Bazel dependencies" + +bazel_dep(name = "aspect_rules_py", version = "0.0.0", dev_dependency = True) +local_path_override( + module_name = "aspect_rules_py", + path = "../..", +) + +# Because we use a prerelease of rules_py, we must compile the rust tools from source. +bazel_dep(name = "rules_rust", version = "0.53.0") + +rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") +rust.toolchain( + edition = "2021", + versions = ["1.81.0"], +) +use_repo(rust, "rust_toolchains") + +register_toolchains("@rust_toolchains//:all") + +bazel_dep(name = "rules_python", version = "0.29.0", dev_dependency = True) + +python = use_extension("@rules_python//python/extensions:python.bzl", "python") +python.toolchain( + configure_coverage_tool = True, + python_version = "3.11.6", +) + +# TODO: Swap in our pip +pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") +pip.parse( + hub_name = "pip", + python_version = "3.11.6", + requirements_lock = "//:requirements.txt", +) +use_repo(pip, "pip") + +local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository") + +local_repository( + name = "subrepo_a", + path = "./subrepo_a", +) + +local_repository( + name = "subrepo_b", + path = "./subrepo_b", +) diff --git a/e2e/cross-repo-610/requirements.in b/e2e/cross-repo-610/requirements.in new file mode 100644 index 00000000..c6b9ffd0 --- /dev/null +++ b/e2e/cross-repo-610/requirements.in @@ -0,0 +1 @@ +cowsay diff --git a/e2e/cross-repo-610/requirements.txt b/e2e/cross-repo-610/requirements.txt new file mode 100644 index 00000000..b318878f --- /dev/null +++ b/e2e/cross-repo-610/requirements.txt @@ -0,0 +1,9 @@ +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# bazel run //:requirements.update +# +cowsay==6.1 \ + --hash=sha256:274b1e6fc1b966d53976333eb90ac94cb07a450a700b455af9fbdf882244b30a + # via -r requirements.in diff --git a/e2e/cross-repo-610/subrepo_a/BUILD.bazel b/e2e/cross-repo-610/subrepo_a/BUILD.bazel new file mode 100644 index 00000000..58b2fd53 --- /dev/null +++ b/e2e/cross-repo-610/subrepo_a/BUILD.bazel @@ -0,0 +1,13 @@ +load("@aspect_rules_py//py:defs.bzl", "py_library") + +py_library( + name = "foo", + srcs = [ + "foo.py", + ], + imports = ["."], + visibility = ["//visibility:public"], + deps = [ + "@subrepo_b//:bar", + ], +) diff --git a/py/tests/rpy610/subrepo/MODULE.bazel b/e2e/cross-repo-610/subrepo_a/MODULE.bazel similarity index 100% rename from py/tests/rpy610/subrepo/MODULE.bazel rename to e2e/cross-repo-610/subrepo_a/MODULE.bazel diff --git a/py/tests/rpy610/subrepo/foo.py b/e2e/cross-repo-610/subrepo_a/foo.py similarity index 100% rename from py/tests/rpy610/subrepo/foo.py rename to e2e/cross-repo-610/subrepo_a/foo.py diff --git a/py/tests/rpy610/subrepo/BUILD.bazel b/e2e/cross-repo-610/subrepo_b/BUILD.bazel similarity index 80% rename from py/tests/rpy610/subrepo/BUILD.bazel rename to e2e/cross-repo-610/subrepo_b/BUILD.bazel index f3d8cb46..cb3d2130 100644 --- a/py/tests/rpy610/subrepo/BUILD.bazel +++ b/e2e/cross-repo-610/subrepo_b/BUILD.bazel @@ -1,9 +1,9 @@ load("@aspect_rules_py//py:defs.bzl", "py_library") py_library( - name = "foo", + name = "bar", srcs = [ - "foo.py", + "bar.py", ], imports = ["."], visibility = ["//visibility:public"], diff --git a/e2e/cross-repo-610/subrepo_b/MODULE.bazel b/e2e/cross-repo-610/subrepo_b/MODULE.bazel new file mode 100644 index 00000000..e69de29b diff --git a/e2e/cross-repo-610/subrepo_b/bar.py b/e2e/cross-repo-610/subrepo_b/bar.py new file mode 100644 index 00000000..462c4a1a --- /dev/null +++ b/e2e/cross-repo-610/subrepo_b/bar.py @@ -0,0 +1,2 @@ +def bar(x): + return x // 5 diff --git a/py/tests/rpy610/test.py b/e2e/cross-repo-610/test.py similarity index 78% rename from py/tests/rpy610/test.py rename to e2e/cross-repo-610/test.py index fd0befb2..19df7328 100644 --- a/py/tests/rpy610/test.py +++ b/e2e/cross-repo-610/test.py @@ -19,14 +19,18 @@ # use a different layout. # The virtualenv changes the sys.prefix, which should be in our runfiles -assert sys.prefix.endswith("/py/tests/rpy610/.test") +assert sys.prefix.endswith("_main/.test") # That prefix should also be "the" prefix per site.PREFIXES -assert site.PREFIXES[0].endswith("/py/tests/rpy610/.test") +assert site.PREFIXES[0].endswith("_main/.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 +assert sys.executable.find("_main/.test/bin/python") != -1 # aspect-build/rules_py#610, these imports aren't quite right import foo print(foo.__file__) + +# Transitive through foo +import bar +print(bar.__file__) diff --git a/py/tests/rpy610/BUILD.bazel b/py/tests/rpy610/BUILD.bazel deleted file mode 100644 index ff5fd0d3..00000000 --- a/py/tests/rpy610/BUILD.bazel +++ /dev/null @@ -1,16 +0,0 @@ -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", - ], -)