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

[FR]: Support multiple Python toolchains #154

Open
JaredNeil opened this issue Mar 27, 2023 · 3 comments
Open

[FR]: Support multiple Python toolchains #154

JaredNeil opened this issue Mar 27, 2023 · 3 comments
Labels
enhancement New feature or request funding needed Contribute to https://opencollective.com/aspect-build

Comments

@JaredNeil
Copy link

JaredNeil commented Mar 27, 2023

What is the current behavior?

rules_py doesn't seem to have an easy way to use multiple python toolchains in the same repository.

Describe the feature

When using python_register_multi_toolchains from bazelbuild/rules_python, it creates py_test and py_binary macros for each version of python that are loaded from @python//<version>:defs.bzl. It would be nice to have a rules_py analog to python_register_multi_toolchains, or some easy way to have rules_py's py_* rules use multiple python toolchains in a single workspace.

@JaredNeil JaredNeil added the enhancement New feature or request label Mar 27, 2023
@github-actions github-actions bot added the untriaged Requires traige label Mar 27, 2023
@alexeagle alexeagle added funding needed Contribute to https://opencollective.com/aspect-build and removed untriaged Requires traige labels Aug 29, 2023
@finn-ball
Copy link

This works for me using bazel modules:

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
    is_default = True,
    python_version = "3.10",
)
python.toolchain(
    python_version = "3.11",
)
python.toolchain(
    python_version = "3.12",
)
use_repo(
    python,
    "python_3_10",
    "python_3_11",
    "python_3_12",
    "python_versions",
)

Then edit in your flags as desired to the .bazelrc:

build:310 --@rules_python//python/config_settings:python_version="3.10"
build:311 --@rules_python//python/config_settings:python_version="3.11"
build:312 --@rules_python//python/config_settings:python_version="3.12"

When executing a target such as:

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

py_binary(
    name = "main",
    srcs = ["main.py"],
)

@JaredNeil
Copy link
Author

Would that let you define a 3.10 py_test and a 3.12 py_test in a the same package and run them both in the same bazel test invocation, like the example linked in the first comment?

@finn-ball
Copy link

The example linked uses the rules py_test_3_8, py_test_3_10 etc as separate targets.

The way I've just sent allows you to register multiple toolchains and then launch multiple invocations of bazel but with different toolchains on the same target.

e.g

bazel test //... --config=310
bazel test //... --config=311

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request funding needed Contribute to https://opencollective.com/aspect-build
Projects
Status: No status
Development

No branches or pull requests

3 participants