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