rules_py icon indicating copy to clipboard operation
rules_py copied to clipboard

[Bug]: cannot use `py_venv`

Open KoltesDigital opened this issue 1 year ago • 3 comments

What happened?

I've just added bazel_dep(name = "aspect_rules_py", version = "0.7.1") to make a venv, in a project where there already was rules_python with pip and so on: was working well.

But I'm unable to declare a py_venv:

ERROR: error loading package '@@aspect_rules_py~//py/tools/venv_bin': Unable to find package for @@[unknown repo 'rules_rust' requested from @@aspect_rules_py~]//rust:defs.bzl: The repository '@@[unknown repo 'rules_rust' requested from @@aspect_rules_py~]' could not be resolved: No repository visible as '@rules_rust' from repository '@@aspect_rules_py~'.
ERROR: X:/external/aspect_rules_py~/py/private/toolchain/venv/BUILD.bazel:3:17: error loading package '@@aspect_rules_py~//py/tools/venv_bin': Unable to find package for @@[unknown repo 'rules_rust' requested from @@aspect_rules_py~]//rust:defs.bzl: The repository '@@[unknown repo 'rules_rust' requested from @@aspect_rules_py~]' could not be resolved: No repository visible as '@rules_rust' 
from repository '@@aspect_rules_py~'. and referenced by '@@aspect_rules_py~//py/private/toolchain/venv:venv_toolchain_source'

I tried to untangle the code to find the dependency chain, but I'm out of luck.

Version

Development (host) and target OS/architectures: windows amd64

Output of bazel --version: bazel 7.1.1

Version of the Aspect rules, or other relevant rules from your WORKSPACE or MODULE.bazel file:
bazel_dep(name = "aspect_rules_py", version = "0.7.1") bazel_dep(name = "rules_python", version = "0.31.0")

Language(s) and/or frameworks involved: N/A

How to reproduce

Simply put

load("@aspect_rules_py//py:defs.bzl", "py_venv")

py_venv(
    name = "venv",
)

and build it.

Any other information?

I'm migrating to bzlmod: my WORKSPACE is empty.

KoltesDigital avatar Apr 16 '24 11:04 KoltesDigital

Do you have the toolchain setup? https://github.com/aspect-build/rules_py/blob/main/e2e/use_release/MODULE.bazel#L8-L10

It's missing from the setup on the releases page, will add.

mattem avatar Apr 18 '24 13:04 mattem

I'm not able to reproduce.

rules_py_snip % bazel build :all
INFO: Analyzed target //:venv (80 packages loaded, 2585 targets configured).
INFO: Found 1 target...
Target //:venv up-to-date:
  bazel-bin/venv
  bazel-bin/venv.venv.pth
INFO: Elapsed time: 2.189s, Critical Path: 0.33s
INFO: 6 processes: 6 internal.
INFO: Build completed successfully, 6 total actions

alexeagle@MacBook-Pro-79 rules_py_snip % cat .bazelversion 
7.1.1
alexeagle@MacBook-Pro-79 rules_py_snip % cat BUILD 
load("@aspect_rules_py//py:defs.bzl", "py_venv")

py_venv(
    name = "venv",
)
alexeagle@MacBook-Pro-79 rules_py_snip % cat MODULE.bazel 
bazel_dep(name = "aspect_rules_py", version = "0.7.1")
bazel_dep(name = "rules_python", version = "0.31.0")
alexeagle@MacBook-Pro-79 rules_py_snip % cat WORKSPACE 

The fact that the error references rules_rust suggests that you're doing something unusual. As you can see from "Dependency Graph" on https://registry.bazel.build/modules/aspect_rules_py/0.7.1 there is no dependency from rules_py to rules_rust, only a devDependency.

alexeagle avatar Apr 20 '24 17:04 alexeagle

@mattem the toolchain declaration is provided by the rules_py module here: https://github.com/aspect-build/rules_py/blob/main/MODULE.bazel#L21 that's not a devDependency; it should also function for users. I don't have a theory why @KoltesDigital is seeing this error.

alexeagle avatar Apr 21 '24 18:04 alexeagle

Hi! I found the same issue in one repo I'm working on when trying to build it on a Windows machine. I was able to reproduce it with this minimal project: https://github.com/jgsogo/rules_py-331

bazel build //...

...
Starting local Bazel server and connecting to it...
ERROR: error loading package '@@aspect_rules_py~//py/tools/venv_bin': Unable to find package for @@[unknown repo 'rules_rust' requested from @@aspect_rules_py~]//rust:defs.bzl: The repository '@@[unknown repo 'rules_rust' requested from @@aspect_rules_py~]' could not be resolved: No repository visible as '@rules_rust' from repository '@@aspect_rules_py~'.
ERROR: C:/users/jgsog/_bazel_jgsog/lcqsxfsl/external/aspect_rules_py~/py/private/toolchain/venv/BUILD.bazel:3:17: error loading package '@@aspect_rules_py~//py/tools/venv_bin': Unable to find package for @@[unknown repo 'rules_rust' requested from @@aspect_rules_py~]//rust:defs.bzl: The repository '@@[unknown repo 'rules_rust' requested from @@aspect_rules_py~]' could not be resolved: No repository visible as '@rules_rust' from repository '@@aspect_rules_py~'. and referenced by '@@aspect_rules_py~//py/private/toolchain/venv:venv_toolchain_source'
Target //tooling/python:_version_default.find_main up-to-date (nothing to build)
ERROR: Analysis of target '//tooling/python:version_default' failed; build aborted: Analysis failed
INFO: Elapsed time: 5.599s, Critical Path: 0.06s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
FAILED:
    Fetching repository @@rules_python~~python~python_3_12_x86_64-pc-windows-msvc; starting

This is an "old" computer running Windows 10.

jgsogo avatar Apr 27 '24 22:04 jgsogo

@jgsogo rules_py doesn't publish / support windows yet, this is expected.

Consider donating to the project if you would like to fund Windows support, https://github.com/aspect-build/rules_py/issues/237#issuecomment-1874394936

mattem avatar Apr 29 '24 13:04 mattem

oh X:/external I missed the windows path in that original post 🤦🏻

alexeagle avatar Apr 29 '24 13:04 alexeagle

Closing as this falls in the "windows isn't supported" category, repro works as expected on supported platforms.

mattem avatar Apr 29 '24 13:04 mattem

Oops, wasn't aware of that. Thanks anyway :)

KoltesDigital avatar Apr 29 '24 14:04 KoltesDigital