Skip to content
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

Bzlmod python_interpreter_target usage #66

Closed
mering opened this issue Jan 3, 2024 · 4 comments
Closed

Bzlmod python_interpreter_target usage #66

mering opened this issue Jan 3, 2024 · 4 comments

Comments

@mering
Copy link

mering commented Jan 3, 2024

How can I specify a specific Python toolchain with Bzlmod.

I have the following toolchain:

bazel_dep(name = "rules_python", version = "0.27.1")
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
    is_default = True,
    python_version = "3.11",
)
use_repo(python, "python_3_11")

It works to specify the toolchain via resolved repo name but this requires hard-coding all versions:

bazel_dep(name = "pybind11_bazel", version = "2.11.1")
python_configure = use_extension("@pybind11_bazel//:python_configure.bzl", "extension")
python_configure.toolchain(python_version = "3", python_interpreter_target = "@@rules_python~0.27.1~python~python_3_11_x86_64-unknown-linux-gnu//:bin/python3")
use_repo(python_configure, "local_config_python", "pybind11")

I tried using the following alias target but it got not resolved correctly:

bazel_dep(name = "pybind11_bazel", version = "2.11.1")
python_configure = use_extension("@pybind11_bazel//:python_configure.bzl", "extension")
python_configure.toolchain(python_version = "3", python_interpreter_target = "@python_3_11//:python3")
use_repo(python_configure, "local_config_python", "pybind11")

My guess would be that the following is not resolved correctly:

if repository_ctx.attr.python_interpreter_target != None:
return str(repository_ctx.path(repository_ctx.attr.python_interpreter_target))

Maybe this is because generated files are not supported by repository_ctx.path():

Returns a path from a string, label or path. If the path is relative, it will resolve relative to the repository directory. If the path is a label, it will resolve to the path of the corresponding file. Note that remote repositories are executed during the analysis phase and thus cannot depends on a target result (the label should point to a non-generated file). If path is a path, it will return that path as is.

@junyer
Copy link
Contributor

junyer commented Jan 3, 2024

I don't think pybind11_bazel can do better right now, but @rickeylev has (much) greater Bazel knowledge than I do, so there might be some way to get this working ahead of initial support for rules_python. :)

@finn-ball
Copy link

I think this may be a critical bug for those on multiple platforms:

"@@rules_python~0.27.1~python~python_3_11_x86_64-unknown-linux-gnu//:bin/python3"

Will not register for non-linux and non-x86_64 platforms.

@junyer
Copy link
Contributor

junyer commented Jan 25, 2024

Ping, @rickeylev!

@junyer
Copy link
Contributor

junyer commented Feb 16, 2024

As of the v2.11.1.bzl.2 release, pybind11_bazel uses rules_python. Please refer to the latter's documentation for details about registering toolchains.

@junyer junyer closed this as completed Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants