generated from bazel-contrib/rules-template
-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: py_library instances from generated repositories are not found by py_test (bzlmod) #276
Comments
wade-arista
added a commit
to wade-arista/rules_py
that referenced
this issue
Feb 28, 2024
Fix for aspect-build#276. In `_make_import_path`, `ctx.workspace_name` is always `_main` when evaluating the deps of targets in the main repo. This includes deps that are in external repos, e.g. importer = use_extension("//:import.bzl", "importer") use_repo(importer, "myrepo") with py_test(..., deps = ["@myrepo//foo"]) In this case, we actually want to use the label's `workspace_name` attr which will be the same as the runfiles path that we need for the venv import paths.
wade-arista
added a commit
to wade-arista/rules_py
that referenced
this issue
Feb 28, 2024
Fix for aspect-build#276. In `_make_import_path`, `ctx.workspace_name` is always `_main` when evaluating the deps of targets in the main repo. This includes deps that are in external repos, e.g. importer = use_extension("//:import.bzl", "importer") use_repo(importer, "myrepo") with py_test(..., deps = ["@myrepo//foo"]) In this case, we actually want to use the label's `workspace_name` attr which will be the same as the runfiles path that we need for the venv import paths.
wade-arista
added a commit
to wade-arista/rules_py
that referenced
this issue
Feb 28, 2024
Fix for aspect-build#276. In `_make_import_path`, `ctx.workspace_name` is always `_main` when evaluating the deps of targets in the main repo. This includes deps that are in external repos, e.g. importer = use_extension("//:import.bzl", "importer") use_repo(importer, "myrepo") with py_test(..., deps = ["@myrepo//foo"]) In this case, we actually want to use the label's `workspace_name` attr which will be the same as the runfiles path that we need for the venv import paths.
wade-arista
added a commit
to wade-arista/rules_py
that referenced
this issue
Mar 5, 2024
Fix for aspect-build#276. In `_make_import_path`, `ctx.workspace_name` is always `_main` when evaluating the deps of targets in the main repo. This includes deps that are in external repos, e.g. importer = use_extension("//:import.bzl", "importer") use_repo(importer, "myrepo") with py_test(..., deps = ["@myrepo//foo"]) In this case, we actually want to use the label's `workspace_name` attr which will be the same as the runfiles path that we need for the venv import paths. Also added a new e2e test that creates this external repo and verifies the fix. Without the fix in place, the test does fail as described in the e2e/repository-rule-deps/README.md "Repro" section.
wade-arista
added a commit
to wade-arista/rules_py
that referenced
this issue
Mar 5, 2024
Fix for aspect-build#276. In `_make_import_path`, `ctx.workspace_name` is always `_main` when evaluating the deps of targets in the main repo. This includes deps that are in external repos, e.g. importer = use_extension("//:import.bzl", "importer") use_repo(importer, "myrepo") with py_test(..., deps = ["@myrepo//foo"]) In this case, we actually want to use the label's `workspace_name` attr which will be the same as the runfiles path that we need for the venv import paths. Also added a new e2e test that creates this external repo and verifies the fix. Without the fix in place, the test does fail as described in the e2e/repository-rule-deps/README.md "Repro" section.
alexeagle
pushed a commit
that referenced
this issue
Mar 5, 2024
In `_make_import_path`, `ctx.workspace_name` is always `_main` when evaluating the deps of targets in the main repo. This includes deps that are in external repos, e.g. importer = use_extension("//:import.bzl", "importer") use_repo(importer, "myrepo") with py_test(..., deps = ["@myrepo//foo"]) In this case, we actually want to use the label's `workspace_name` attr which will be the same as the runfiles path that we need for the venv import paths. Also added a new e2e test that creates this external repo and verifies the fix. Without the fix in place, the test does fail as described in the e2e/repository-rule-deps/README.md "Repro" section. --- ### Test plan - New test case added in `e2e/repository-rule-deps`. - Manually tested against bazel 6.5 and 7.0.2. Fixes: #276
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What happened?
I'm using bzlmod in bazel 7.0.2.
I created a basic
repository_rule
that creates arules_py
py_library
. I then created a simple test that specifies the external repository in its deps and tries to import thispy_library
(foo
). It doesn't find the python package. If I access otherrules_py
py_library
instances from my_main
repo, instead, those are found as expected.Version
Development (host) and target OS/architectures: linux x86_64 "Ubuntu 22.04.3 LTS"
Output of
bazel --version
:Version of the Aspect rules, or other relevant rules from your
WORKSPACE
orMODULE.bazel
file:Language(s) and/or frameworks involved:
Python3
How to reproduce
I have a minimal repro here:
https://github.com/wade-arista/bazel-demo/tree/63fc4391a7c30be0587a642649b0c16514fab302/rules_py_reporule
test:
BUILD.bazel
for
@myrepo
:Any other information?
Using
ctx.label.workspace_name
when making the import path, when it is non-empty, fixes the issue.Here's the contents of the test's runfiles directory:
So in this case,
ctx.label.workspace_name
is_main~importer~myrepo
for e.g.@myrepo//bar
, butctx.workspace_name
is just_main
, so we need to use the former when building the runfiles import paths.The text was updated successfully, but these errors were encountered: