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

Import Python Bazel rules from rules_python #1188

Open
mortenmj opened this issue Dec 9, 2024 · 3 comments · May be fixed by #1189
Open

Import Python Bazel rules from rules_python #1188

mortenmj opened this issue Dec 9, 2024 · 3 comments · May be fixed by #1189

Comments

@mortenmj
Copy link
Contributor

mortenmj commented Dec 9, 2024

Rules such as py_runtime and py_runtime_pair are no longer part of Bazel core as of version 8.0.0 (released today), and should be imported from https://github.com/bazelbuild/rules_python/tree/main. These can be loaded through Bazel for now, by opting into a flag, but that ability is intended to go away in the next major release.

@mortenmj mortenmj linked a pull request Dec 9, 2024 that will close this issue
@mering
Copy link

mering commented Dec 13, 2024

Note: An alternative is to use a hermetic toolchain from rules_python.

For MODULE.bazel:

bazel_dep(name = "rules_python", version = "1.0.0")
PYTHON_VERSIONS = [
    "3.10",
    "3.11",
    "3.12",
    "3.13",
]
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
[
    python.toolchain(
        is_default = python_version == PYTHON_VERSIONS[-1],  # Choose last version as default.
        python_version = python_version,
    )
    for python_version in PYTHON_VERSIONS
]

Then apply the following patch:

diff --git a/python/BUILD b/python/BUILD
index 12936ad..0afe833 100644
--- a/python/BUILD
+++ b/python/BUILD
@@ -4,7 +4,7 @@ cc_binary(
     linkshared = 1,
     deps = [
         "//core:libjsonnet",
-        "@default_python3_headers//:headers",
+        "@rules_python//python/cc:current_py_cc_headers",
     ],
 )

This allows removing platform_defs folder and tools/build_defs/python_repo.bzl.

@simonff
Copy link

simonff commented Dec 20, 2024

/sub

@DarkAngel35-commits
Copy link

MODULE.bazel

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 a pull request may close this issue.

4 participants