1*60517a1eSAndroid Build Coastguard Worker# Copyright 2018 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 Workerload("@bazel_skylib//rules:build_test.bzl", "build_test") 16*60517a1eSAndroid Build Coastguard Workerload("@bazel_skylib//rules:write_file.bzl", "write_file") 17*60517a1eSAndroid Build Coastguard Workerload("//examples/wheel/private:wheel_utils.bzl", "directory_writer", "make_variable_tags") 18*60517a1eSAndroid Build Coastguard Workerload("//python:defs.bzl", "py_library", "py_test") 19*60517a1eSAndroid Build Coastguard Workerload("//python:packaging.bzl", "py_package", "py_wheel") 20*60517a1eSAndroid Build Coastguard Workerload("//python:pip.bzl", "compile_pip_requirements") 21*60517a1eSAndroid Build Coastguard Workerload("//python:versions.bzl", "gen_python_config_settings") 22*60517a1eSAndroid Build Coastguard Workerload("//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary") 23*60517a1eSAndroid Build Coastguard Workerload("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility 24*60517a1eSAndroid Build Coastguard Worker 25*60517a1eSAndroid Build Coastguard Workerpackage(default_visibility = ["//visibility:public"]) 26*60517a1eSAndroid Build Coastguard Worker 27*60517a1eSAndroid Build Coastguard Workerlicenses(["notice"]) # Apache 2.0 28*60517a1eSAndroid Build Coastguard Worker 29*60517a1eSAndroid Build Coastguard Workerpy_library( 30*60517a1eSAndroid Build Coastguard Worker name = "main", 31*60517a1eSAndroid Build Coastguard Worker srcs = ["main.py"], 32*60517a1eSAndroid Build Coastguard Worker deps = [ 33*60517a1eSAndroid Build Coastguard Worker "//examples/wheel/lib:simple_module", 34*60517a1eSAndroid Build Coastguard Worker "//examples/wheel/lib:module_with_data", 35*60517a1eSAndroid Build Coastguard Worker # Example dependency which is not packaged in the wheel 36*60517a1eSAndroid Build Coastguard Worker # due to "packages" filter on py_package rule. 37*60517a1eSAndroid Build Coastguard Worker "//tests/load_from_macro:foo", 38*60517a1eSAndroid Build Coastguard Worker ], 39*60517a1eSAndroid Build Coastguard Worker) 40*60517a1eSAndroid Build Coastguard Worker 41*60517a1eSAndroid Build Coastguard Workerpy_library( 42*60517a1eSAndroid Build Coastguard Worker name = "main_with_gen_data", 43*60517a1eSAndroid Build Coastguard Worker srcs = ["main.py"], 44*60517a1eSAndroid Build Coastguard Worker data = [ 45*60517a1eSAndroid Build Coastguard Worker ":gen_dir", 46*60517a1eSAndroid Build Coastguard Worker ], 47*60517a1eSAndroid Build Coastguard Worker) 48*60517a1eSAndroid Build Coastguard Worker 49*60517a1eSAndroid Build Coastguard Workerdirectory_writer( 50*60517a1eSAndroid Build Coastguard Worker name = "gen_dir", 51*60517a1eSAndroid Build Coastguard Worker out = "someDir", 52*60517a1eSAndroid Build Coastguard Worker files = {"foo.py": ""}, 53*60517a1eSAndroid Build Coastguard Worker) 54*60517a1eSAndroid Build Coastguard Worker 55*60517a1eSAndroid Build Coastguard Worker# Package just a specific py_libraries, without their dependencies 56*60517a1eSAndroid Build Coastguard Workerpy_wheel( 57*60517a1eSAndroid Build Coastguard Worker name = "minimal_with_py_library", 58*60517a1eSAndroid Build Coastguard Worker testonly = True, # Set this to verify the generated .dist target doesn't break things 59*60517a1eSAndroid Build Coastguard Worker # Package data. We're building "example_minimal_library-0.0.1-py3-none-any.whl" 60*60517a1eSAndroid Build Coastguard Worker distribution = "example_minimal_library", 61*60517a1eSAndroid Build Coastguard Worker python_tag = "py3", 62*60517a1eSAndroid Build Coastguard Worker # NOTE: twine_binary = "//tools/publish:twine" does not work on non-bzlmod 63*60517a1eSAndroid Build Coastguard Worker # setups because the `//tools/publish:twine` produces multiple files and is 64*60517a1eSAndroid Build Coastguard Worker # unsuitable as the `src` to the underlying native_binary rule. 65*60517a1eSAndroid Build Coastguard Worker twine = None if BZLMOD_ENABLED else "@rules_python_publish_deps_twine//:pkg", 66*60517a1eSAndroid Build Coastguard Worker version = "0.0.1", 67*60517a1eSAndroid Build Coastguard Worker deps = [ 68*60517a1eSAndroid Build Coastguard Worker "//examples/wheel/lib:module_with_data", 69*60517a1eSAndroid Build Coastguard Worker "//examples/wheel/lib:simple_module", 70*60517a1eSAndroid Build Coastguard Worker ], 71*60517a1eSAndroid Build Coastguard Worker) 72*60517a1eSAndroid Build Coastguard Worker 73*60517a1eSAndroid Build Coastguard Worker# Populate a rule with "Make Variable" arguments for 74*60517a1eSAndroid Build Coastguard Worker# abi, python_tag and version. You might want to do this 75*60517a1eSAndroid Build Coastguard Worker# for the following use cases: 76*60517a1eSAndroid Build Coastguard Worker# - abi, python_tag: introspect a toolchain to map to appropriate cpython tags 77*60517a1eSAndroid Build Coastguard Worker# - version: populate given this or a dependent module's version 78*60517a1eSAndroid Build Coastguard Workermake_variable_tags( 79*60517a1eSAndroid Build Coastguard Worker name = "make_variable_tags", 80*60517a1eSAndroid Build Coastguard Worker) 81*60517a1eSAndroid Build Coastguard Worker 82*60517a1eSAndroid Build Coastguard Workerpy_wheel( 83*60517a1eSAndroid Build Coastguard Worker name = "minimal_with_py_library_with_make_variables", 84*60517a1eSAndroid Build Coastguard Worker testonly = True, 85*60517a1eSAndroid Build Coastguard Worker abi = "$(ABI)", 86*60517a1eSAndroid Build Coastguard Worker distribution = "example_minimal_library", 87*60517a1eSAndroid Build Coastguard Worker python_tag = "$(PYTHON_TAG)", 88*60517a1eSAndroid Build Coastguard Worker toolchains = ["//examples/wheel:make_variable_tags"], 89*60517a1eSAndroid Build Coastguard Worker version = "$(VERSION)", 90*60517a1eSAndroid Build Coastguard Worker deps = [ 91*60517a1eSAndroid Build Coastguard Worker "//examples/wheel/lib:module_with_data", 92*60517a1eSAndroid Build Coastguard Worker "//examples/wheel/lib:simple_module", 93*60517a1eSAndroid Build Coastguard Worker ], 94*60517a1eSAndroid Build Coastguard Worker) 95*60517a1eSAndroid Build Coastguard Worker 96*60517a1eSAndroid Build Coastguard Workerbuild_test( 97*60517a1eSAndroid Build Coastguard Worker name = "dist_build_tests", 98*60517a1eSAndroid Build Coastguard Worker targets = [":minimal_with_py_library.dist"], 99*60517a1eSAndroid Build Coastguard Worker) 100*60517a1eSAndroid Build Coastguard Worker 101*60517a1eSAndroid Build Coastguard Worker# Package just a specific py_libraries, without their dependencies 102*60517a1eSAndroid Build Coastguard Workerpy_wheel( 103*60517a1eSAndroid Build Coastguard Worker name = "minimal_with_py_library_with_stamp", 104*60517a1eSAndroid Build Coastguard Worker # Package data. We're building "example_minimal_library-0.0.1-py3-none-any.whl" 105*60517a1eSAndroid Build Coastguard Worker distribution = "example_minimal_library{BUILD_USER}", 106*60517a1eSAndroid Build Coastguard Worker python_tag = "py3", 107*60517a1eSAndroid Build Coastguard Worker stamp = 1, 108*60517a1eSAndroid Build Coastguard Worker version = "0.1.{BUILD_TIMESTAMP}", 109*60517a1eSAndroid Build Coastguard Worker deps = [ 110*60517a1eSAndroid Build Coastguard Worker "//examples/wheel/lib:module_with_data", 111*60517a1eSAndroid Build Coastguard Worker "//examples/wheel/lib:simple_module", 112*60517a1eSAndroid Build Coastguard Worker ], 113*60517a1eSAndroid Build Coastguard Worker) 114*60517a1eSAndroid Build Coastguard Worker 115*60517a1eSAndroid Build Coastguard Worker# Use py_package to collect all transitive dependencies of a target, 116*60517a1eSAndroid Build Coastguard Worker# selecting just the files within a specific python package. 117*60517a1eSAndroid Build Coastguard Workerpy_package( 118*60517a1eSAndroid Build Coastguard Worker name = "example_pkg", 119*60517a1eSAndroid Build Coastguard Worker # Only include these Python packages. 120*60517a1eSAndroid Build Coastguard Worker packages = ["examples.wheel"], 121*60517a1eSAndroid Build Coastguard Worker deps = [":main"], 122*60517a1eSAndroid Build Coastguard Worker) 123*60517a1eSAndroid Build Coastguard Worker 124*60517a1eSAndroid Build Coastguard Workerpy_package( 125*60517a1eSAndroid Build Coastguard Worker name = "example_pkg_with_data", 126*60517a1eSAndroid Build Coastguard Worker packages = ["examples.wheel"], 127*60517a1eSAndroid Build Coastguard Worker deps = [":main_with_gen_data"], 128*60517a1eSAndroid Build Coastguard Worker) 129*60517a1eSAndroid Build Coastguard Worker 130*60517a1eSAndroid Build Coastguard Workerpy_wheel( 131*60517a1eSAndroid Build Coastguard Worker name = "minimal_with_py_package", 132*60517a1eSAndroid Build Coastguard Worker # Package data. We're building "example_minimal_package-0.0.1-py3-none-any.whl" 133*60517a1eSAndroid Build Coastguard Worker distribution = "example_minimal_package", 134*60517a1eSAndroid Build Coastguard Worker python_tag = "py3", 135*60517a1eSAndroid Build Coastguard Worker version = "0.0.1", 136*60517a1eSAndroid Build Coastguard Worker deps = [":example_pkg"], 137*60517a1eSAndroid Build Coastguard Worker) 138*60517a1eSAndroid Build Coastguard Worker 139*60517a1eSAndroid Build Coastguard Worker# An example that uses all features provided by py_wheel. 140*60517a1eSAndroid Build Coastguard Workerpy_wheel( 141*60517a1eSAndroid Build Coastguard Worker name = "customized", 142*60517a1eSAndroid Build Coastguard Worker author = "Example Author with non-ascii characters: żółw", 143*60517a1eSAndroid Build Coastguard Worker author_email = "[email protected]", 144*60517a1eSAndroid Build Coastguard Worker classifiers = [ 145*60517a1eSAndroid Build Coastguard Worker "License :: OSI Approved :: Apache Software License", 146*60517a1eSAndroid Build Coastguard Worker "Intended Audience :: Developers", 147*60517a1eSAndroid Build Coastguard Worker ], 148*60517a1eSAndroid Build Coastguard Worker console_scripts = { 149*60517a1eSAndroid Build Coastguard Worker "customized_wheel": "examples.wheel.main:main", 150*60517a1eSAndroid Build Coastguard Worker }, 151*60517a1eSAndroid Build Coastguard Worker description_file = "README.md", 152*60517a1eSAndroid Build Coastguard Worker # Package data. We're building "example_customized-0.0.1-py3-none-any.whl" 153*60517a1eSAndroid Build Coastguard Worker distribution = "example_customized", 154*60517a1eSAndroid Build Coastguard Worker entry_points = { 155*60517a1eSAndroid Build Coastguard Worker "console_scripts": ["another = foo.bar:baz"], 156*60517a1eSAndroid Build Coastguard Worker "group2": [ 157*60517a1eSAndroid Build Coastguard Worker "second = second.main:s", 158*60517a1eSAndroid Build Coastguard Worker "first = first.main:f", 159*60517a1eSAndroid Build Coastguard Worker ], 160*60517a1eSAndroid Build Coastguard Worker }, 161*60517a1eSAndroid Build Coastguard Worker extra_distinfo_files = { 162*60517a1eSAndroid Build Coastguard Worker "//examples/wheel:NOTICE": "NOTICE", 163*60517a1eSAndroid Build Coastguard Worker # Rename the file when packaging to show we can. 164*60517a1eSAndroid Build Coastguard Worker "//examples/wheel:README.md": "README", 165*60517a1eSAndroid Build Coastguard Worker }, 166*60517a1eSAndroid Build Coastguard Worker homepage = "www.example.com", 167*60517a1eSAndroid Build Coastguard Worker license = "Apache 2.0", 168*60517a1eSAndroid Build Coastguard Worker project_urls = { 169*60517a1eSAndroid Build Coastguard Worker "Bug Tracker": "www.example.com/issues", 170*60517a1eSAndroid Build Coastguard Worker "Documentation": "www.example.com/docs", 171*60517a1eSAndroid Build Coastguard Worker }, 172*60517a1eSAndroid Build Coastguard Worker python_tag = "py3", 173*60517a1eSAndroid Build Coastguard Worker # Requirements embedded into the wheel metadata. 174*60517a1eSAndroid Build Coastguard Worker requires = ["pytest"], 175*60517a1eSAndroid Build Coastguard Worker summary = "A one-line summary of this test package", 176*60517a1eSAndroid Build Coastguard Worker version = "0.0.1", 177*60517a1eSAndroid Build Coastguard Worker deps = [":example_pkg"], 178*60517a1eSAndroid Build Coastguard Worker) 179*60517a1eSAndroid Build Coastguard Worker 180*60517a1eSAndroid Build Coastguard Worker# An example of how to change the wheel package root directory using 'strip_path_prefixes'. 181*60517a1eSAndroid Build Coastguard Workerpy_wheel( 182*60517a1eSAndroid Build Coastguard Worker name = "custom_package_root", 183*60517a1eSAndroid Build Coastguard Worker # Package data. We're building "examples_custom_package_root-0.0.1-py3-none-any.whl" 184*60517a1eSAndroid Build Coastguard Worker distribution = "examples_custom_package_root", 185*60517a1eSAndroid Build Coastguard Worker entry_points = { 186*60517a1eSAndroid Build Coastguard Worker "console_scripts": ["main = foo.bar:baz"], 187*60517a1eSAndroid Build Coastguard Worker }, 188*60517a1eSAndroid Build Coastguard Worker python_tag = "py3", 189*60517a1eSAndroid Build Coastguard Worker strip_path_prefixes = [ 190*60517a1eSAndroid Build Coastguard Worker "examples", 191*60517a1eSAndroid Build Coastguard Worker ], 192*60517a1eSAndroid Build Coastguard Worker version = "0.0.1", 193*60517a1eSAndroid Build Coastguard Worker deps = [ 194*60517a1eSAndroid Build Coastguard Worker ":example_pkg", 195*60517a1eSAndroid Build Coastguard Worker ], 196*60517a1eSAndroid Build Coastguard Worker) 197*60517a1eSAndroid Build Coastguard Worker 198*60517a1eSAndroid Build Coastguard Workerpy_wheel( 199*60517a1eSAndroid Build Coastguard Worker name = "custom_package_root_multi_prefix", 200*60517a1eSAndroid Build Coastguard Worker # Package data. We're building "custom_custom_package_root_multi_prefix-0.0.1-py3-none-any.whl" 201*60517a1eSAndroid Build Coastguard Worker distribution = "example_custom_package_root_multi_prefix", 202*60517a1eSAndroid Build Coastguard Worker python_tag = "py3", 203*60517a1eSAndroid Build Coastguard Worker strip_path_prefixes = [ 204*60517a1eSAndroid Build Coastguard Worker "examples/wheel/lib", 205*60517a1eSAndroid Build Coastguard Worker "examples/wheel", 206*60517a1eSAndroid Build Coastguard Worker ], 207*60517a1eSAndroid Build Coastguard Worker version = "0.0.1", 208*60517a1eSAndroid Build Coastguard Worker deps = [ 209*60517a1eSAndroid Build Coastguard Worker ":example_pkg", 210*60517a1eSAndroid Build Coastguard Worker ], 211*60517a1eSAndroid Build Coastguard Worker) 212*60517a1eSAndroid Build Coastguard Worker 213*60517a1eSAndroid Build Coastguard Workerpy_wheel( 214*60517a1eSAndroid Build Coastguard Worker name = "custom_package_root_multi_prefix_reverse_order", 215*60517a1eSAndroid Build Coastguard Worker # Package data. We're building "custom_custom_package_root_multi_prefix_reverse_order-0.0.1-py3-none-any.whl" 216*60517a1eSAndroid Build Coastguard Worker distribution = "example_custom_package_root_multi_prefix_reverse_order", 217*60517a1eSAndroid Build Coastguard Worker python_tag = "py3", 218*60517a1eSAndroid Build Coastguard Worker strip_path_prefixes = [ 219*60517a1eSAndroid Build Coastguard Worker "examples/wheel", 220*60517a1eSAndroid Build Coastguard Worker "examples/wheel/lib", # this is not effective, because the first prefix takes priority 221*60517a1eSAndroid Build Coastguard Worker ], 222*60517a1eSAndroid Build Coastguard Worker version = "0.0.1", 223*60517a1eSAndroid Build Coastguard Worker deps = [ 224*60517a1eSAndroid Build Coastguard Worker ":example_pkg", 225*60517a1eSAndroid Build Coastguard Worker ], 226*60517a1eSAndroid Build Coastguard Worker) 227*60517a1eSAndroid Build Coastguard Worker 228*60517a1eSAndroid Build Coastguard Workerpy_wheel( 229*60517a1eSAndroid Build Coastguard Worker name = "python_requires_in_a_package", 230*60517a1eSAndroid Build Coastguard Worker distribution = "example_python_requires_in_a_package", 231*60517a1eSAndroid Build Coastguard Worker python_requires = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*", 232*60517a1eSAndroid Build Coastguard Worker python_tag = "py3", 233*60517a1eSAndroid Build Coastguard Worker version = "0.0.1", 234*60517a1eSAndroid Build Coastguard Worker deps = [ 235*60517a1eSAndroid Build Coastguard Worker ":example_pkg", 236*60517a1eSAndroid Build Coastguard Worker ], 237*60517a1eSAndroid Build Coastguard Worker) 238*60517a1eSAndroid Build Coastguard Worker 239*60517a1eSAndroid Build Coastguard Workerpy_wheel( 240*60517a1eSAndroid Build Coastguard Worker name = "use_rule_with_dir_in_outs", 241*60517a1eSAndroid Build Coastguard Worker distribution = "use_rule_with_dir_in_outs", 242*60517a1eSAndroid Build Coastguard Worker python_tag = "py3", 243*60517a1eSAndroid Build Coastguard Worker version = "0.0.1", 244*60517a1eSAndroid Build Coastguard Worker deps = [ 245*60517a1eSAndroid Build Coastguard Worker ":example_pkg_with_data", 246*60517a1eSAndroid Build Coastguard Worker ], 247*60517a1eSAndroid Build Coastguard Worker) 248*60517a1eSAndroid Build Coastguard Worker 249*60517a1eSAndroid Build Coastguard Workergen_python_config_settings() 250*60517a1eSAndroid Build Coastguard Worker 251*60517a1eSAndroid Build Coastguard Workerpy_wheel( 252*60517a1eSAndroid Build Coastguard Worker name = "python_abi3_binary_wheel", 253*60517a1eSAndroid Build Coastguard Worker abi = "abi3", 254*60517a1eSAndroid Build Coastguard Worker distribution = "example_python_abi3_binary_wheel", 255*60517a1eSAndroid Build Coastguard Worker # these platform strings must line up with test_python_abi3_binary_wheel() in wheel_test.py 256*60517a1eSAndroid Build Coastguard Worker platform = select({ 257*60517a1eSAndroid Build Coastguard Worker ":aarch64-apple-darwin": "macosx_11_0_arm64", 258*60517a1eSAndroid Build Coastguard Worker ":aarch64-unknown-linux-gnu": "manylinux2014_aarch64", 259*60517a1eSAndroid Build Coastguard Worker ":x86_64-apple-darwin": "macosx_11_0_x86_64", # this is typically macosx_10_9_x86_64? 260*60517a1eSAndroid Build Coastguard Worker ":x86_64-pc-windows-msvc": "win_amd64", 261*60517a1eSAndroid Build Coastguard Worker ":x86_64-unknown-linux-gnu": "manylinux2014_x86_64", 262*60517a1eSAndroid Build Coastguard Worker }), 263*60517a1eSAndroid Build Coastguard Worker python_requires = ">=3.8", 264*60517a1eSAndroid Build Coastguard Worker python_tag = "cp38", 265*60517a1eSAndroid Build Coastguard Worker version = "0.0.1", 266*60517a1eSAndroid Build Coastguard Worker) 267*60517a1eSAndroid Build Coastguard Worker 268*60517a1eSAndroid Build Coastguard Workerpy_wheel( 269*60517a1eSAndroid Build Coastguard Worker name = "filename_escaping", 270*60517a1eSAndroid Build Coastguard Worker # Per https://packaging.python.org/en/latest/specifications/binary-distribution-format/#escaping-and-unicode 271*60517a1eSAndroid Build Coastguard Worker # runs of "-", "_" and "." should be replaced with a single underscore. 272*60517a1eSAndroid Build Coastguard Worker # Unicode non-ascii letters aren't allowed according to 273*60517a1eSAndroid Build Coastguard Worker # https://packaging.python.org/en/latest/specifications/name-normalization/. 274*60517a1eSAndroid Build Coastguard Worker distribution = "File--Name-Escaping", 275*60517a1eSAndroid Build Coastguard Worker python_tag = "py3", 276*60517a1eSAndroid Build Coastguard Worker version = "v0.0.1.RC1+ubuntu-r7", 277*60517a1eSAndroid Build Coastguard Worker deps = [":example_pkg"], 278*60517a1eSAndroid Build Coastguard Worker) 279*60517a1eSAndroid Build Coastguard Worker 280*60517a1eSAndroid Build Coastguard Workerwrite_file( 281*60517a1eSAndroid Build Coastguard Worker name = "requires_file", 282*60517a1eSAndroid Build Coastguard Worker out = "requires.txt", 283*60517a1eSAndroid Build Coastguard Worker content = """\ 284*60517a1eSAndroid Build Coastguard Worker# Requirements file 285*60517a1eSAndroid Build Coastguard Worker--index-url https://pypi.com 286*60517a1eSAndroid Build Coastguard Worker 287*60517a1eSAndroid Build Coastguard Workertomli>=2.0.0 288*60517a1eSAndroid Build Coastguard Workerstarlark # Example comment 289*60517a1eSAndroid Build Coastguard Worker""".splitlines(), 290*60517a1eSAndroid Build Coastguard Worker) 291*60517a1eSAndroid Build Coastguard Worker 292*60517a1eSAndroid Build Coastguard Workerwrite_file( 293*60517a1eSAndroid Build Coastguard Worker name = "extra_requires_file", 294*60517a1eSAndroid Build Coastguard Worker out = "extra_requires.txt", 295*60517a1eSAndroid Build Coastguard Worker content = """\ 296*60517a1eSAndroid Build Coastguard Worker# Extras Requirements file 297*60517a1eSAndroid Build Coastguard Worker--index-url https://pypi.com 298*60517a1eSAndroid Build Coastguard Worker 299*60517a1eSAndroid Build Coastguard Workerpyyaml>=6.0.0,!=6.0.1 300*60517a1eSAndroid Build Coastguard Workertoml; (python_version == "3.11" or python_version == "3.12") and python_version != "3.8" 301*60517a1eSAndroid Build Coastguard Workerwheel; python_version == "3.11" or python_version == "3.12" # Example comment 302*60517a1eSAndroid Build Coastguard Worker""".splitlines(), 303*60517a1eSAndroid Build Coastguard Worker) 304*60517a1eSAndroid Build Coastguard Worker 305*60517a1eSAndroid Build Coastguard Worker# py_wheel can use text files to specify their requirements. This 306*60517a1eSAndroid Build Coastguard Worker# can be convenient for users of `compile_pip_requirements` who have 307*60517a1eSAndroid Build Coastguard Worker# granular `requirements.in` files per package. This target shows 308*60517a1eSAndroid Build Coastguard Worker# how to provide this file. 309*60517a1eSAndroid Build Coastguard Workerpy_wheel( 310*60517a1eSAndroid Build Coastguard Worker name = "requires_files", 311*60517a1eSAndroid Build Coastguard Worker distribution = "requires_files", 312*60517a1eSAndroid Build Coastguard Worker extra_requires_files = {":extra_requires.txt": "example"}, 313*60517a1eSAndroid Build Coastguard Worker python_tag = "py3", 314*60517a1eSAndroid Build Coastguard Worker # py_wheel can use text files to specify their requirements. This 315*60517a1eSAndroid Build Coastguard Worker # can be convenient for users of `compile_pip_requirements` who have 316*60517a1eSAndroid Build Coastguard Worker # granular `requirements.in` files per package. 317*60517a1eSAndroid Build Coastguard Worker requires_file = ":requires.txt", 318*60517a1eSAndroid Build Coastguard Worker version = "0.0.1", 319*60517a1eSAndroid Build Coastguard Worker deps = [":example_pkg"], 320*60517a1eSAndroid Build Coastguard Worker) 321*60517a1eSAndroid Build Coastguard Worker 322*60517a1eSAndroid Build Coastguard Worker# Package just a specific py_libraries, without their dependencies 323*60517a1eSAndroid Build Coastguard Workerpy_wheel( 324*60517a1eSAndroid Build Coastguard Worker name = "minimal_data_files", 325*60517a1eSAndroid Build Coastguard Worker testonly = True, # Set this to verify the generated .dist target doesn't break things 326*60517a1eSAndroid Build Coastguard Worker 327*60517a1eSAndroid Build Coastguard Worker # Re-using some files already checked into the repo. 328*60517a1eSAndroid Build Coastguard Worker data_files = { 329*60517a1eSAndroid Build Coastguard Worker "//examples/wheel:NOTICE": "scripts/NOTICE", 330*60517a1eSAndroid Build Coastguard Worker "README.md": "data/target/path/README.md", 331*60517a1eSAndroid Build Coastguard Worker }, 332*60517a1eSAndroid Build Coastguard Worker distribution = "minimal_data_files", 333*60517a1eSAndroid Build Coastguard Worker version = "0.0.1", 334*60517a1eSAndroid Build Coastguard Worker) 335*60517a1eSAndroid Build Coastguard Worker 336*60517a1eSAndroid Build Coastguard Workerpy_wheel( 337*60517a1eSAndroid Build Coastguard Worker name = "extra_requires", 338*60517a1eSAndroid Build Coastguard Worker distribution = "extra_requires", 339*60517a1eSAndroid Build Coastguard Worker extra_requires = {"example": [ 340*60517a1eSAndroid Build Coastguard Worker "pyyaml>=6.0.0,!=6.0.1", 341*60517a1eSAndroid Build Coastguard Worker 'toml; (python_version == "3.11" or python_version == "3.12") and python_version != "3.8"', 342*60517a1eSAndroid Build Coastguard Worker 'wheel; python_version == "3.11" or python_version == "3.12" ', 343*60517a1eSAndroid Build Coastguard Worker ]}, 344*60517a1eSAndroid Build Coastguard Worker python_tag = "py3", 345*60517a1eSAndroid Build Coastguard Worker # py_wheel can use text files to specify their requirements. This 346*60517a1eSAndroid Build Coastguard Worker # can be convenient for users of `compile_pip_requirements` who have 347*60517a1eSAndroid Build Coastguard Worker # granular `requirements.in` files per package. 348*60517a1eSAndroid Build Coastguard Worker requires = [ 349*60517a1eSAndroid Build Coastguard Worker "tomli>=2.0.0", 350*60517a1eSAndroid Build Coastguard Worker "starlark", 351*60517a1eSAndroid Build Coastguard Worker 'pytest; python_version != "3.8"', 352*60517a1eSAndroid Build Coastguard Worker ], 353*60517a1eSAndroid Build Coastguard Worker version = "0.0.1", 354*60517a1eSAndroid Build Coastguard Worker deps = [":example_pkg"], 355*60517a1eSAndroid Build Coastguard Worker) 356*60517a1eSAndroid Build Coastguard Worker 357*60517a1eSAndroid Build Coastguard Workerpy_test( 358*60517a1eSAndroid Build Coastguard Worker name = "wheel_test", 359*60517a1eSAndroid Build Coastguard Worker srcs = ["wheel_test.py"], 360*60517a1eSAndroid Build Coastguard Worker data = [ 361*60517a1eSAndroid Build Coastguard Worker ":custom_package_root", 362*60517a1eSAndroid Build Coastguard Worker ":custom_package_root_multi_prefix", 363*60517a1eSAndroid Build Coastguard Worker ":custom_package_root_multi_prefix_reverse_order", 364*60517a1eSAndroid Build Coastguard Worker ":customized", 365*60517a1eSAndroid Build Coastguard Worker ":extra_requires", 366*60517a1eSAndroid Build Coastguard Worker ":filename_escaping", 367*60517a1eSAndroid Build Coastguard Worker ":minimal_data_files", 368*60517a1eSAndroid Build Coastguard Worker ":minimal_with_py_library", 369*60517a1eSAndroid Build Coastguard Worker ":minimal_with_py_library_with_stamp", 370*60517a1eSAndroid Build Coastguard Worker ":minimal_with_py_package", 371*60517a1eSAndroid Build Coastguard Worker ":python_abi3_binary_wheel", 372*60517a1eSAndroid Build Coastguard Worker ":python_requires_in_a_package", 373*60517a1eSAndroid Build Coastguard Worker ":requires_files", 374*60517a1eSAndroid Build Coastguard Worker ":use_rule_with_dir_in_outs", 375*60517a1eSAndroid Build Coastguard Worker ], 376*60517a1eSAndroid Build Coastguard Worker deps = [ 377*60517a1eSAndroid Build Coastguard Worker "//python/runfiles", 378*60517a1eSAndroid Build Coastguard Worker ], 379*60517a1eSAndroid Build Coastguard Worker) 380*60517a1eSAndroid Build Coastguard Worker 381*60517a1eSAndroid Build Coastguard Worker# Test wheel publishing 382*60517a1eSAndroid Build Coastguard Worker 383*60517a1eSAndroid Build Coastguard Workercompile_pip_requirements( 384*60517a1eSAndroid Build Coastguard Worker name = "requirements_server", 385*60517a1eSAndroid Build Coastguard Worker src = "requirements_server.in", 386*60517a1eSAndroid Build Coastguard Worker) 387*60517a1eSAndroid Build Coastguard Worker 388*60517a1eSAndroid Build Coastguard Workerpy_test( 389*60517a1eSAndroid Build Coastguard Worker name = "test_publish", 390*60517a1eSAndroid Build Coastguard Worker srcs = ["test_publish.py"], 391*60517a1eSAndroid Build Coastguard Worker data = [ 392*60517a1eSAndroid Build Coastguard Worker ":minimal_with_py_library", 393*60517a1eSAndroid Build Coastguard Worker ":minimal_with_py_library.publish", 394*60517a1eSAndroid Build Coastguard Worker ":pypiserver", 395*60517a1eSAndroid Build Coastguard Worker ], 396*60517a1eSAndroid Build Coastguard Worker env = { 397*60517a1eSAndroid Build Coastguard Worker "PUBLISH_PATH": "$(location :minimal_with_py_library.publish)", 398*60517a1eSAndroid Build Coastguard Worker "SERVER_PATH": "$(location :pypiserver)", 399*60517a1eSAndroid Build Coastguard Worker "WHEEL_PATH": "$(rootpath :minimal_with_py_library)", 400*60517a1eSAndroid Build Coastguard Worker }, 401*60517a1eSAndroid Build Coastguard Worker target_compatible_with = select({ 402*60517a1eSAndroid Build Coastguard Worker "@platforms//os:linux": [], 403*60517a1eSAndroid Build Coastguard Worker "@platforms//os:macos": [], 404*60517a1eSAndroid Build Coastguard Worker "//conditions:default": ["@platforms//:incompatible"], 405*60517a1eSAndroid Build Coastguard Worker }), 406*60517a1eSAndroid Build Coastguard Worker deps = [ 407*60517a1eSAndroid Build Coastguard Worker "@pypiserver//pypiserver", 408*60517a1eSAndroid Build Coastguard Worker ], 409*60517a1eSAndroid Build Coastguard Worker) 410*60517a1eSAndroid Build Coastguard Worker 411*60517a1eSAndroid Build Coastguard Workerpy_console_script_binary( 412*60517a1eSAndroid Build Coastguard Worker name = "pypiserver", 413*60517a1eSAndroid Build Coastguard Worker pkg = "@pypiserver//pypiserver", 414*60517a1eSAndroid Build Coastguard Worker script = "pypi-server", 415*60517a1eSAndroid Build Coastguard Worker) 416