Skip to content

Conversation

@furtib
Copy link
Contributor

@furtib furtib commented Jan 15, 2026

Why:
We should use an external Python toolchain instead of maintaining our own.
This is necessary mainly for Bazel 8 support.

What:

  • Replaced the Python toolchain

Addresses:
#108

@furtib furtib marked this pull request as ready for review January 15, 2026 07:30
@furtib furtib marked this pull request as draft January 15, 2026 07:30
@furtib furtib force-pushed the replace-python-toolchain branch 2 times, most recently from bf1da1d to 9fb4c71 Compare January 15, 2026 09:26
@furtib furtib changed the title Update python toolchain Bazel 8 support (update python toolchain) Jan 15, 2026
@furtib furtib mentioned this pull request Jan 15, 2026
@furtib furtib marked this pull request as ready for review January 15, 2026 10:22
@Szelethus Szelethus self-requested a review January 15, 2026 16:22
Copy link
Collaborator

@nettle nettle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on Bazel 8, @furtib!
This change is crucial.
At the same time the incompatibility between 8 and 7 and 6 is quite big.
We must be very careful to do not destroy what is working somehow in 6 and 7.
Please do not submit without consensus between all of us.

@furtib furtib force-pushed the replace-python-toolchain branch from e49ac73 to 962d110 Compare January 15, 2026 17:40
@furtib furtib force-pushed the replace-python-toolchain branch 4 times, most recently from 605e170 to 8459e07 Compare January 16, 2026 12:21
@furtib furtib requested a review from Szelethus January 16, 2026 12:27
# this script will be run with the python interpreter
"{Mode}": "Run",
"{Verbosity}": "DEBUG",
"{PythonPath}": python_path,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is needed? Can you explain a little? Is there any precedence for this in other projects?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the point of this patch.
Shebangs are always absolute paths!
Bazel, providing its own interpreter/compiler etc, will always give relative paths.
I will look for an example from the wild, but getting rid of the shebang was the main point of this PR.

Copy link
Collaborator

@nettle nettle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, seams like we will have to use rules_python at some point anyway, so we should be ready. And this patch is very good prototype!
However, I'm sure we should split it and move forward very carefully:

  1. Refactor py_runtime to python toolchain at least for Bazel 6 and 7
  2. Make implementation work with all Bazel versions
    (theoretically this can be combined, at least partially, with the first step)
  3. Add Bazel 8 support

Before that we must clarify requirements towards rules_python vs bazel_tools in different Bazel versions. As I can understand Bazel 8 still support bazel_tools, but I'm not sure.

Comment on lines +21 to +32
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

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

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

py_repositories()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I really dont like is that we add external dependency like this.
In Bazel mod it looks OK, but for Bazel 6 it sucks.

Comment on lines +135 to +136
executable = py_toolchain.interpreter,
arguments = [ctx.outputs.codechecker_script.path],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, maybe...

default = "@default_python_tools//:py3_runtime",
),
},
toolchains = ["@rules_python//python:toolchain_type"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also thinking about toolchain, but for some reasons used runtime.
It is definitely good idea to try toolchain again!

output = ctx.outputs.codechecker_test_script,
is_executable = True,
substitutions = {
#"#{Python_path}": py_toolchain.stub_shebang,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be interesting!
I did not know about stub_shebang!

Copy link
Contributor Author

@furtib furtib Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely happy with it.
stub_shebang seems to be a static string #!/usr/bin/env python3. (env is not guaranteed to be there)
As I see it, the interpreter is a more lucrative option. Bazel places the interpreter into the sandbox, and we don't have to worry about it at all.

Comment on lines +244 to +250
ctx.actions.write(
output = ctx.outputs.test_script_wrapper,
is_executable = True,
content = """
{} {}
""".format(py_toolchain.interpreter.short_path, ctx.outputs.codechecker_test_script.short_path)
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this does not look elegant to me!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.
I did this to use the bazel provided python instead of the system-provided (through stub_shebang).

@furtib furtib force-pushed the replace-python-toolchain branch 2 times, most recently from f8f3f59 to 5dae841 Compare January 21, 2026 09:24
@furtib furtib changed the title Bazel 8 support (update python toolchain) Replace python toolchain with @rules_python Jan 21, 2026
@furtib
Copy link
Contributor Author

furtib commented Jan 21, 2026

I tried to minimize the changes in this patch for easier review.
I currently cannot minimize the changes further, since our own toolchain and the @rules_python one are incompatible with each other.
I understand that the rules_python dependency in the WORKSPACE file is troublesome. I will try to come up with alternatives.

@furtib furtib requested review from Szelethus and nettle January 21, 2026 09:31
@furtib furtib force-pushed the replace-python-toolchain branch from 5dae841 to beb76ea Compare January 21, 2026 09:41
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

Successfully merging this pull request may close these issues.

3 participants