1*60517a1eSAndroid Build Coastguard Worker# Copyright 2024 The Bazel Authors. All rights reserved. 2*60517a1eSAndroid Build Coastguard Worker# 3*60517a1eSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 4*60517a1eSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 5*60517a1eSAndroid Build Coastguard Worker# You may obtain a copy of the License at 6*60517a1eSAndroid Build Coastguard Worker# 7*60517a1eSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 8*60517a1eSAndroid Build Coastguard Worker# 9*60517a1eSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 10*60517a1eSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 11*60517a1eSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*60517a1eSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 13*60517a1eSAndroid Build Coastguard Worker# limitations under the License. 14*60517a1eSAndroid Build Coastguard Worker 15*60517a1eSAndroid Build Coastguard Worker""" 16*60517a1eSAndroid Build Coastguard WorkerEXPERIMENTAL: This is experimental and may be removed without notice 17*60517a1eSAndroid Build Coastguard Worker 18*60517a1eSAndroid Build Coastguard WorkerA module extension for working with uv. 19*60517a1eSAndroid Build Coastguard Worker""" 20*60517a1eSAndroid Build Coastguard Worker 21*60517a1eSAndroid Build Coastguard Workerload("//python/uv:repositories.bzl", "uv_register_toolchains") 22*60517a1eSAndroid Build Coastguard Worker 23*60517a1eSAndroid Build Coastguard Worker_DOC = """\ 24*60517a1eSAndroid Build Coastguard WorkerA module extension for working with uv. 25*60517a1eSAndroid Build Coastguard Worker""" 26*60517a1eSAndroid Build Coastguard Worker 27*60517a1eSAndroid Build Coastguard Workeruv_toolchain = tag_class(attrs = { 28*60517a1eSAndroid Build Coastguard Worker "uv_version": attr.string(doc = "Explicit version of uv.", mandatory = True), 29*60517a1eSAndroid Build Coastguard Worker}) 30*60517a1eSAndroid Build Coastguard Worker 31*60517a1eSAndroid Build Coastguard Workerdef _uv_toolchain_extension(module_ctx): 32*60517a1eSAndroid Build Coastguard Worker for mod in module_ctx.modules: 33*60517a1eSAndroid Build Coastguard Worker for toolchain in mod.tags.toolchain: 34*60517a1eSAndroid Build Coastguard Worker if not mod.is_root: 35*60517a1eSAndroid Build Coastguard Worker fail( 36*60517a1eSAndroid Build Coastguard Worker "Only the root module may configure the uv toolchain.", 37*60517a1eSAndroid Build Coastguard Worker "This prevents conflicting registrations with any other modules.", 38*60517a1eSAndroid Build Coastguard Worker "NOTE: We may wish to enforce a policy where toolchain configuration is only allowed in the root module, or in rules_python. See https://github.com/bazelbuild/bazel/discussions/22024", 39*60517a1eSAndroid Build Coastguard Worker ) 40*60517a1eSAndroid Build Coastguard Worker 41*60517a1eSAndroid Build Coastguard Worker uv_register_toolchains( 42*60517a1eSAndroid Build Coastguard Worker uv_version = toolchain.uv_version, 43*60517a1eSAndroid Build Coastguard Worker register_toolchains = False, 44*60517a1eSAndroid Build Coastguard Worker ) 45*60517a1eSAndroid Build Coastguard Worker 46*60517a1eSAndroid Build Coastguard Workeruv = module_extension( 47*60517a1eSAndroid Build Coastguard Worker doc = _DOC, 48*60517a1eSAndroid Build Coastguard Worker implementation = _uv_toolchain_extension, 49*60517a1eSAndroid Build Coastguard Worker tag_classes = {"toolchain": uv_toolchain}, 50*60517a1eSAndroid Build Coastguard Worker) 51