1# Copyright 2024 The Bazel Authors. All rights reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15"""Values and helpers for pip_repository related flags. 16 17NOTE: The transitive loads of this should be kept minimal. This avoids loading 18unnecessary files when all that are needed are flag definitions. 19""" 20 21load("@bazel_skylib//rules:common_settings.bzl", "string_flag") 22load("//python/private:enum.bzl", "enum") 23 24# Determines if we should use whls for third party 25# 26# buildifier: disable=name-conventions 27UseWhlFlag = enum( 28 # Automatically decide the effective value based on environment, target 29 # platform and the presence of distributions for a particular package. 30 AUTO = "auto", 31 # Do not use `sdist` and fail if there are no available whls suitable for the target platform. 32 ONLY = "only", 33 # Do not use whl distributions and instead build the whls from `sdist`. 34 NO = "no", 35) 36 37# Determines whether universal wheels should be preferred over arch platform specific ones. 38# 39# buildifier: disable=name-conventions 40UniversalWhlFlag = enum( 41 # Prefer platform-specific wheels over universal wheels. 42 ARCH = "arch", 43 # Prefer universal wheels over platform-specific wheels. 44 UNIVERSAL = "universal", 45) 46 47INTERNAL_FLAGS = [ 48 "dist", 49 "whl_plat", 50 "whl_plat_py3", 51 "whl_plat_py3_abi3", 52 "whl_plat_pycp3x", 53 "whl_plat_pycp3x_abi3", 54 "whl_plat_pycp3x_abicp", 55 "whl_py2_py3", 56 "whl_py3", 57 "whl_py3_abi3", 58 "whl_pycp3x", 59 "whl_pycp3x_abi3", 60 "whl_pycp3x_abicp", 61] 62 63def define_pypi_internal_flags(name): 64 for flag in INTERNAL_FLAGS: 65 string_flag( 66 name = "_internal_pip_" + flag, 67 build_setting_default = "", 68 values = [""], 69 visibility = ["//visibility:public"], 70 ) 71