@@ -25,10 +25,18 @@ _OnFailure = enum(
2525 FAIL = "fail" ,
2626)
2727
28- _TOOLCHAIN_IMPL_TEMPLATE = """\
28+ _BUILD_BAZEL_TEMPLATE = """\
2929 # Generated by python/private/local_runtime_repo.bzl
3030
31- load("@rules_python//python/private:local_runtime_repo_setup.bzl", "define_local_runtime_toolchain_impl")
31+ load(
32+ "@rules_python//python/private:local_runtime_repo_setup.bzl",
33+ "define_local_runtime_toolchain_impl",
34+ "define_local_runtime_targets",
35+ )
36+
37+ package(
38+ default_visibility = ["//visibility:public"]
39+ )
3240
3341define_local_runtime_toolchain_impl(
3442 name = "local_runtime",
@@ -41,6 +49,8 @@ define_local_runtime_toolchain_impl(
4149 implementation_name = "{implementation_name}",
4250 os = "{os}",
4351)
52+
53+ define_local_runtime_targets()
4454"""
4555
4656RUNTIME_INFO_BZL_TEMPLATE = """
@@ -175,7 +185,7 @@ def _local_runtime_repo_impl(rctx):
175185 else :
176186 logger .warn ("No external python libraries found." )
177187
178- build_bazel = _TOOLCHAIN_IMPL_TEMPLATE .format (
188+ build_bazel = _BUILD_BAZEL_TEMPLATE .format (
179189 major = info ["major" ],
180190 minor = info ["minor" ],
181191 micro = info ["micro" ],
@@ -201,7 +211,9 @@ def _local_runtime_repo_impl(rctx):
201211 ))
202212
203213 # Text format for `python.toolchain.python_version_file`
204- rctx .file ("version.txt" , "{major}.{minor}" .format (** info ))
214+ # The name `python-version` is used to match pyenv and uv naming that looks
215+ # for a `.python-version` file.
216+ rctx .file ("python-version" , "{major}.{minor}" .format (** info ))
205217
206218local_runtime_repo = repository_rule (
207219 implementation = _local_runtime_repo_impl ,
@@ -282,7 +294,7 @@ How to handle errors when trying to automatically determine settings.
282294)
283295
284296def _expand_incompatible_template ():
285- return _TOOLCHAIN_IMPL_TEMPLATE .format (
297+ return _BUILD_BAZEL_TEMPLATE .format (
286298 interpreter_path = "/incompatible" ,
287299 implementation_name = "incompatible" ,
288300 interface_library = "None" ,
0 commit comments