@@ -103,8 +103,8 @@ public void runtimeSetByPythonTop() throws Exception {
103
103
"pkg/BUILD" ,
104
104
"py_runtime(" ,
105
105
" name = 'my_py_runtime'," ,
106
- " interpreter_path = '/system/python2 '," ,
107
- " python_version = 'PY2 '," ,
106
+ " interpreter_path = '/system/python3 '," ,
107
+ " python_version = 'PY3 '," ,
108
108
")" ,
109
109
"py_binary(" ,
110
110
" name = 'pybin'," ,
@@ -114,7 +114,7 @@ public void runtimeSetByPythonTop() throws Exception {
114
114
analysisMock .pySupport ().createPythonTopEntryPoint (mockToolsConfig , "//pkg:my_py_runtime" );
115
115
useConfiguration ("--incompatible_use_python_toolchains=false" , "--python_top=" + pythonTop );
116
116
String path = getInterpreterPathFromStub (getConfiguredTarget ("//pkg:pybin" ));
117
- assertThat (path ).isEqualTo ("/system/python2 " );
117
+ assertThat (path ).isEqualTo ("/system/python3 " );
118
118
}
119
119
120
120
@ Test
@@ -149,8 +149,8 @@ public void pythonTopTakesPrecedenceOverPythonPath() throws Exception {
149
149
"pkg/BUILD" ,
150
150
"py_runtime(" ,
151
151
" name = 'my_py_runtime'," ,
152
- " interpreter_path = '/system/python2 '," ,
153
- " python_version = 'PY2 '," ,
152
+ " interpreter_path = '/system/python3 '," ,
153
+ " python_version = 'PY3 '," ,
154
154
")" ,
155
155
"py_binary(" ,
156
156
" name = 'pybin'," ,
@@ -163,7 +163,7 @@ public void pythonTopTakesPrecedenceOverPythonPath() throws Exception {
163
163
"--python_top=" + pythonTop ,
164
164
"--python_path=/better/not/be/this/one" );
165
165
String path = getInterpreterPathFromStub (getConfiguredTarget ("//pkg:pybin" ));
166
- assertThat (path ).isEqualTo ("/system/python2 " );
166
+ assertThat (path ).isEqualTo ("/system/python3 " );
167
167
}
168
168
169
169
// TODO(brandjon): Move generic toolchain tests that don't access legacy behavior to
@@ -177,20 +177,13 @@ private void defineToolchains() throws Exception {
177
177
"toolchains/BUILD" ,
178
178
"load('" + TOOLCHAIN_BZL + "', 'py_runtime_pair')" ,
179
179
"py_runtime(" ,
180
- " name = 'py2_runtime'," ,
181
- " interpreter_path = '/system/python2'," ,
182
- " python_version = 'PY2'," ,
183
- " stub_shebang = '#!/usr/bin/env python'," ,
184
- ")" ,
185
- "py_runtime(" ,
186
180
" name = 'py3_runtime'," ,
187
181
" interpreter_path = '/system/python3'," ,
188
182
" python_version = 'PY3'," ,
189
183
" stub_shebang = '#!/usr/bin/env python3'," ,
190
184
")" ,
191
185
"py_runtime_pair(" ,
192
186
" name = 'py_runtime_pair'," ,
193
- " py2_runtime = ':py2_runtime'," ,
194
187
" py3_runtime = ':py3_runtime'," ,
195
188
")" ,
196
189
"toolchain(" ,
@@ -199,12 +192,12 @@ private void defineToolchains() throws Exception {
199
192
" toolchain_type = '" + TOOLCHAIN_TYPE + "'," ,
200
193
")" ,
201
194
"py_runtime_pair(" ,
202
- " name = 'py_runtime_pair_for_py2_only '," ,
203
- " py2_runtime = ':py2_runtime '," ,
195
+ " name = 'py_runtime_pair_for_py3_only '," ,
196
+ " py3_runtime = ':py3_runtime '," ,
204
197
")" ,
205
198
"toolchain(" ,
206
- " name = 'py_toolchain_for_py2_only '," ,
207
- " toolchain = ':py_runtime_pair_for_py2_only '," ,
199
+ " name = 'py_toolchain_for_py3_only '," ,
200
+ " toolchain = ':py_runtime_pair_for_py3_only '," ,
208
201
" toolchain_type = '" + TOOLCHAIN_TYPE + "'," ,
209
202
")" );
210
203
}
@@ -215,11 +208,6 @@ public void runtimeObtainedFromToolchain() throws Exception {
215
208
scratch .file (
216
209
"pkg/BUILD" ,
217
210
"py_binary(" ,
218
- " name = 'py2_bin'," ,
219
- " srcs = ['py2_bin.py']," ,
220
- " python_version = 'PY2'," ,
221
- ")" ,
222
- "py_binary(" ,
223
211
" name = 'py3_bin'," ,
224
212
" srcs = ['py3_bin.py']," ,
225
213
" python_version = 'PY3'," ,
@@ -228,17 +216,12 @@ public void runtimeObtainedFromToolchain() throws Exception {
228
216
"--incompatible_use_python_toolchains=true" ,
229
217
"--extra_toolchains=//toolchains:py_toolchain" );
230
218
231
- ConfiguredTarget py2 = getConfiguredTarget ("//pkg:py2_bin" );
232
219
ConfiguredTarget py3 = getConfiguredTarget ("//pkg:py3_bin" );
233
220
234
- String py2Path = getInterpreterPathFromStub (py2 );
235
221
String py3Path = getInterpreterPathFromStub (py3 );
236
- assertThat (py2Path ).isEqualTo ("/system/python2" );
237
222
assertThat (py3Path ).isEqualTo ("/system/python3" );
238
223
239
- String py2Shebang = getShebangFromStub (py2 );
240
224
String py3Shebang = getShebangFromStub (py3 );
241
- assertThat (py2Shebang ).isEqualTo ("#!/usr/bin/env python" );
242
225
assertThat (py3Shebang ).isEqualTo ("#!/usr/bin/env python3" );
243
226
}
244
227
@@ -248,41 +231,21 @@ public void toolchainCanOmitUnusedRuntimeVersion() throws Exception {
248
231
scratch .file (
249
232
"pkg/BUILD" ,
250
233
"py_binary(" ,
251
- " name = 'py2_bin '," ,
252
- " srcs = ['py2_bin .py']," ,
253
- " python_version = 'PY2 '," ,
234
+ " name = 'py3_bin '," ,
235
+ " srcs = ['py3_bin .py']," ,
236
+ " python_version = 'PY3 '," ,
254
237
")" );
255
238
useConfiguration (
256
239
"--incompatible_use_python_toolchains=true" ,
257
- "--extra_toolchains=//toolchains:py_toolchain_for_py2_only " );
240
+ "--extra_toolchains=//toolchains:py_toolchain_for_py3_only " );
258
241
259
- String path = getInterpreterPathFromStub (getConfiguredTarget ("//pkg:py2_bin " ));
260
- assertThat (path ).isEqualTo ("/system/python2 " );
242
+ String path = getInterpreterPathFromStub (getConfiguredTarget ("//pkg:py3_bin " ));
243
+ assertThat (path ).isEqualTo ("/system/python3 " );
261
244
}
262
245
263
246
@ Test
264
247
public void toolchainTakesPrecedenceOverLegacyFlags () throws Exception {
265
248
defineToolchains ();
266
- scratch .file (
267
- "pkg/BUILD" ,
268
- "py_binary(" ,
269
- " name = 'py2_bin'," ,
270
- " srcs = ['py2_bin.py']," ,
271
- " python_version = 'PY2'," ,
272
- ")" );
273
- useConfiguration (
274
- "--incompatible_use_python_toolchains=true" ,
275
- "--extra_toolchains=//toolchains:py_toolchain" ,
276
- "--python_path=/better/not/be/this/one" );
277
-
278
- String path = getInterpreterPathFromStub (getConfiguredTarget ("//pkg:py2_bin" ));
279
- assertThat (path ).isEqualTo ("/system/python2" );
280
- }
281
-
282
- @ Test
283
- public void toolchainIsMissingNeededRuntime () throws Exception {
284
- defineToolchains ();
285
- reporter .removeHandler (failFastHandler );
286
249
scratch .file (
287
250
"pkg/BUILD" ,
288
251
"py_binary(" ,
@@ -292,10 +255,11 @@ public void toolchainIsMissingNeededRuntime() throws Exception {
292
255
")" );
293
256
useConfiguration (
294
257
"--incompatible_use_python_toolchains=true" ,
295
- "--extra_toolchains=//toolchains:py_toolchain_for_py2_only" );
258
+ "--extra_toolchains=//toolchains:py_toolchain" ,
259
+ "--python_path=/better/not/be/this/one" );
296
260
297
- getConfiguredTarget ("//pkg:py3_bin" );
298
- assertContainsEvent ( "The Python toolchain does not provide a runtime for Python version PY3 " );
261
+ String path = getInterpreterPathFromStub ( getConfiguredTarget ("//pkg:py3_bin" ) );
262
+ assertThat ( path ). isEqualTo ( "/system/python3 " );
299
263
}
300
264
301
265
/**
@@ -330,16 +294,16 @@ private void defineCustomToolchain(String... lines) throws Exception {
330
294
}
331
295
332
296
/**
333
- * Defines a PY2 py_binary target at //pkg:pybin, configures it to use the custom toolchain
297
+ * Defines a py_binary target at //pkg:pybin, configures it to use the custom toolchain
334
298
* //toolchains:custom, and attempts to retrieve it with {@link #getConfiguredTarget}.
335
299
*/
336
- private void analyzePy2BinaryTargetUsingCustomToolchain () throws Exception {
300
+ private void analyzePyBinaryTargetUsingCustomToolchain () throws Exception {
337
301
scratch .file (
338
302
"pkg/BUILD" ,
339
303
"py_binary(" ,
340
304
" name = 'pybin'," ,
341
305
" srcs = ['pybin.py']," ,
342
- " python_version = 'PY2 '," ,
306
+ " python_version = 'PY3 '," ,
343
307
")" );
344
308
useConfiguration (
345
309
"--incompatible_use_python_toolchains=true" ,
@@ -352,48 +316,42 @@ public void toolchainInfoFieldIsMissing() throws Exception {
352
316
reporter .removeHandler (failFastHandler );
353
317
defineCustomToolchain (
354
318
"return platform_common.ToolchainInfo(" ,
355
- " py2_runtime = PyRuntimeInfo(" ,
356
- " interpreter_path = '/system/python2 '," ,
357
- " python_version = 'PY2 ')" ,
319
+ " py3_runtime = PyRuntimeInfo(" ,
320
+ " interpreter_path = '/system/python3 '," ,
321
+ " python_version = 'PY3 ')" ,
358
322
")" );
359
- // Use PY2 binary to test that we still validate the PY3 field even when it's not needed.
360
- analyzePy2BinaryTargetUsingCustomToolchain ();
323
+ analyzePyBinaryTargetUsingCustomToolchain ();
361
324
assertContainsEvent (
362
- "Error parsing the Python toolchain's ToolchainInfo: field 'py3_runtime ' is missing" );
325
+ "Error parsing the Python toolchain's ToolchainInfo: field 'py2_runtime ' is missing" );
363
326
}
364
327
365
328
@ Test
366
329
public void toolchainInfoFieldHasBadType () throws Exception {
367
330
reporter .removeHandler (failFastHandler );
368
331
defineCustomToolchain (
369
332
"return platform_common.ToolchainInfo(" ,
370
- " py2_runtime = PyRuntimeInfo(" ,
371
- " interpreter_path = '/system/python2 '," ,
372
- " python_version = 'PY2 ')," ,
373
- " py3_runtime = 'abc'," ,
333
+ " py3_runtime = PyRuntimeInfo(" ,
334
+ " interpreter_path = '/system/python3 '," ,
335
+ " python_version = 'PY3 ')," ,
336
+ " py2_runtime = 'abc'," ,
374
337
")" );
375
- // Use PY2 binary to test that we still validate the PY3 field even when it's not needed.
376
- analyzePy2BinaryTargetUsingCustomToolchain ();
338
+ analyzePyBinaryTargetUsingCustomToolchain ();
377
339
assertContainsEvent (
378
340
"Error parsing the Python toolchain's ToolchainInfo: Expected a PyRuntimeInfo in field "
379
- + "'py3_runtime ', but got 'string'" );
341
+ + "'py2_runtime ', but got 'string'" );
380
342
}
381
343
382
344
@ Test
383
345
public void toolchainInfoFieldHasBadVersion () throws Exception {
384
346
reporter .removeHandler (failFastHandler );
385
347
defineCustomToolchain (
386
348
"return platform_common.ToolchainInfo(" ,
387
- " py2_runtime = PyRuntimeInfo(" ,
388
- " interpreter_path = '/system/python2'," ,
389
- " python_version = 'PY2')," ,
390
349
" py3_runtime = PyRuntimeInfo(" ,
391
350
" interpreter_path = '/system/python3'," ,
392
351
// python_version is erroneously set to PY2 for the PY3 field.
393
352
" python_version = 'PY2')," ,
394
353
")" );
395
- // Use PY2 binary to test that we still validate the PY3 field even when it's not needed.
396
- analyzePy2BinaryTargetUsingCustomToolchain ();
354
+ analyzePyBinaryTargetUsingCustomToolchain ();
397
355
assertContainsEvent (
398
356
"Error retrieving the Python runtime from the toolchain: Expected field 'py3_runtime' to "
399
357
+ "have a runtime with python_version = 'PY3', but got python_version = 'PY2'" );
0 commit comments