Skip to content

@rules_python//python/config_settings:python_version does not control toolchain #1751

Closed
@UebelAndre

Description

@UebelAndre

🐞 bug report

Affected Rule

The issue is caused by the rule: `python_register_multi_toolchains`

Is this a regression?

I think this has always been a bug.

Description

A clear and concise description of the problem...

@rules_python//python/config_settings:python_version does not control the of the python toolchain that's used when paired with python_register_multi_toolchains

🔬 Minimal Reproduction

Using a simple WORKSPACE like the one below, I'm able to invoke the following to see the version of python printed does not match the version specified in the command line

bazel run //:example --@rules_python//python/config_settings:python_version=3.11.4

WORKSPACE.bazel

workspace(name = "example")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "rules_python",
    sha256 = "d71d2c67e0bce986e1c5a7731b4693226867c45bfe0b7c5e0067228a536fc580",
    strip_prefix = "rules_python-0.29.0",
    url = "https://github.com/bazelbuild/rules_python/releases/download/0.29.0/rules_python-0.29.0.tar.gz",
)

load("@rules_python//python:repositories.bzl", "py_repositories")

py_repositories()

load("@rules_python//python:repositories.bzl", "python_register_multi_toolchains")

python_register_multi_toolchains(
    name = "python",
    default_version = "3.11",
    python_versions = [
        "3.8",
        "3.11",
    ],
    register_coverage_tool = True,
)

BUILD.bazel

load("@rules_python//python:defs.bzl", "py_binary")

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

example.py

import sys
print(sys.version)

🔥 Exception or Error

The example above will print py3.11.6, the newest available toolchain, but not the one specified on the command line.

🌍 Your Environment

Operating System:

  
Linux, MacOS, Windows
  

Output of bazel version:

  
7.0.1
  

Rules_python version:

  
0.29.0
  

Anything else relevant?

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: toolchainRelated to the toolchains provided by rules_python

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions