1load("@python_versions//3.10:defs.bzl", py_binary_3_10 = "py_binary", py_test_3_10 = "py_test") 2load("@python_versions//3.11:defs.bzl", py_binary_3_11 = "py_binary", py_test_3_11 = "py_test") 3load("@python_versions//3.9:defs.bzl", py_binary_3_9 = "py_binary", py_test_3_9 = "py_test") 4load("@rules_python//python:defs.bzl", "py_binary", "py_test") 5load("@rules_python//python:versions.bzl", "MINOR_MAPPING") 6load("@rules_python//python/config_settings:transition.bzl", py_versioned_binary = "py_binary", py_versioned_test = "py_test") 7 8py_binary( 9 name = "version_default", 10 srcs = ["version.py"], 11 main = "version.py", 12) 13 14py_binary_3_9( 15 name = "version_3_9", 16 srcs = ["version.py"], 17 main = "version.py", 18) 19 20py_binary_3_10( 21 name = "version_3_10", 22 srcs = ["version.py"], 23 main = "version.py", 24) 25 26py_binary_3_11( 27 name = "version_3_11", 28 srcs = ["version.py"], 29 main = "version.py", 30) 31 32py_versioned_binary( 33 name = "version_3_10_versioned", 34 srcs = ["version.py"], 35 main = "version.py", 36 python_version = "3.10", 37) 38 39# This is a work in progress and the commented 40# tests will not work until we can support 41# multiple pips with bzlmod. 42 43py_test( 44 name = "my_lib_default_test", 45 srcs = ["my_lib_test.py"], 46 main = "my_lib_test.py", 47 deps = ["//libs/my_lib"], 48) 49 50py_test_3_9( 51 name = "my_lib_3_9_test", 52 srcs = ["my_lib_test.py"], 53 main = "my_lib_test.py", 54 deps = ["//libs/my_lib"], 55) 56 57py_test_3_10( 58 name = "my_lib_3_10_test", 59 srcs = ["my_lib_test.py"], 60 main = "my_lib_test.py", 61 deps = ["//libs/my_lib"], 62) 63 64py_versioned_test( 65 name = "my_lib_versioned_test", 66 srcs = ["my_lib_test.py"], 67 main = "my_lib_test.py", 68 python_version = "3.10", 69 deps = select( 70 { 71 "@rules_python//python/config_settings:is_python_" + MINOR_MAPPING["3.10"]: ["//libs/my_lib"], 72 }, 73 no_match_error = """\ 74This test is failing to find dependencies and it seems that the is_python_{version} 75does not match the transitioned configuration of python-version 3.10. Please 76look at the 77 78 @rules_python//python/config_settings:config_settings.bzl 79 80to fix any bugs.""".format( 81 version = MINOR_MAPPING["3.10"], 82 ), 83 ), 84) 85 86py_test( 87 name = "version_default_test", 88 srcs = ["version_test.py"], 89 env = {"VERSION_CHECK": "3.9"}, # The default defined in the WORKSPACE. 90 main = "version_test.py", 91) 92 93py_test_3_9( 94 name = "version_3_9_test", 95 srcs = ["version_test.py"], 96 env = {"VERSION_CHECK": "3.9"}, 97 main = "version_test.py", 98) 99 100py_test_3_10( 101 name = "version_3_10_test", 102 srcs = ["version_test.py"], 103 env = {"VERSION_CHECK": "3.10"}, 104 main = "version_test.py", 105) 106 107py_versioned_test( 108 name = "version_versioned_test", 109 srcs = ["version_test.py"], 110 env = {"VERSION_CHECK": "3.10"}, 111 main = "version_test.py", 112 python_version = "3.10", 113) 114 115py_test_3_11( 116 name = "version_3_11_test", 117 srcs = ["version_test.py"], 118 env = {"VERSION_CHECK": "3.11"}, 119 main = "version_test.py", 120) 121 122py_test( 123 name = "version_default_takes_3_10_subprocess_test", 124 srcs = ["cross_version_test.py"], 125 data = [":version_3_10"], 126 env = { 127 "SUBPROCESS_VERSION_CHECK": "3.10", 128 "SUBPROCESS_VERSION_PY_BINARY": "$(rootpath :version_3_10)", 129 "VERSION_CHECK": "3.9", 130 }, 131 main = "cross_version_test.py", 132) 133 134py_test_3_10( 135 name = "version_3_10_takes_3_9_subprocess_test", 136 srcs = ["cross_version_test.py"], 137 data = [":version_3_9"], 138 env = { 139 "SUBPROCESS_VERSION_CHECK": "3.9", 140 "SUBPROCESS_VERSION_PY_BINARY": "$(rootpath :version_3_9)", 141 "VERSION_CHECK": "3.10", 142 }, 143 main = "cross_version_test.py", 144) 145 146py_versioned_test( 147 name = "version_3_10_takes_3_9_subprocess_test_2", 148 srcs = ["cross_version_test.py"], 149 data = [":version_3_9"], 150 env = { 151 "SUBPROCESS_VERSION_CHECK": "3.9", 152 "SUBPROCESS_VERSION_PY_BINARY": "$(rootpath :version_3_9)", 153 "VERSION_CHECK": "3.10", 154 }, 155 main = "cross_version_test.py", 156 python_version = "3.10", 157) 158 159sh_test( 160 name = "version_test_binary_default", 161 srcs = ["version_test.sh"], 162 data = [":version_default"], 163 env = { 164 "VERSION_CHECK": "3.9", # The default defined in the WORKSPACE. 165 "VERSION_PY_BINARY": "$(rootpath :version_default)", 166 }, 167) 168 169sh_test( 170 name = "version_test_binary_3_9", 171 srcs = ["version_test.sh"], 172 data = [":version_3_9"], 173 env = { 174 "VERSION_CHECK": "3.9", 175 "VERSION_PY_BINARY": "$(rootpath :version_3_9)", 176 }, 177) 178 179sh_test( 180 name = "version_test_binary_3_10", 181 srcs = ["version_test.sh"], 182 data = [":version_3_10"], 183 env = { 184 "VERSION_CHECK": "3.10", 185 "VERSION_PY_BINARY": "$(rootpath :version_3_10)", 186 }, 187) 188