Skip to content

Migrate tools to PY3 #10127

@brandjon

Description

@brandjon

py_binary and py_test targets within Bazel's own source tree should at some point be migrated to no longer need python_version = "PY2" (the default is PY3).

However, this may be a breaking change if users of these tools have a build that does not have a PY3 runtime in their Python toolchain. It's unclear whether this is a problem in practice.

Some users, particularly on Mac, do not have a Python 3 interpreter installed, but register a Python toolchain that has PY3 point to the Python 2 interpreter instead (see @bazel_tools//tools/python:autodetecting_toolchain_nonstrict). This satisfies (really, bypasses) Bazel's version checking, but fails miserably the moment you introduce PY3-only code. Users of such a toolchain won't care when we flip the value of python_version, but they will care when the underlying source files break PY2 compatibility.

Our options are to:

  1. attempt to roll this out and see if anyone breaks or complains. This is tricky because downstream CI would really be testing our CI configuration moreso than our users' toolchain environments.

  2. roll out an incompatible flag. This may or may not be possible using select() / SBC magic. python_version is a nonconfigurable attribute, but you could imagine wrapper targets that select on the incompatible change flag to pick either a PY2 target or PY3 one. Alternatively, we can add a mechanism for incompatible change flags to change the content of Starlark files or what Starlark file gets used within @bazel_tools. We'll probably need such a mechanism in the future anyway.

The following targets would need conversion:

> bazel query 'attr(python_version, PY2, kind(py_, //...))'

//tools/python:pywrapper_test
//tools/build_defs/pkg:make_rpm_test
//tools/build_defs/pkg:make_rpm
//tools/build_defs/pkg:make_deb
//tools/build_defs/pkg:build_tar
//tools/build_defs/pkg:archive_test
//tools/aquery_differ:aquery_differ_test
//tools/aquery_differ:aquery_differ
//tools/android:stubify_manifest_test
//tools/android:stubify_manifest
//tools/android:strip_resources
//tools/android:resource_extractor_test
//tools/android:resource_extractor
//tools/android:junction_test
//tools/android:instrumentation_test_check_test
//tools/android:instrumentation_test_check
//tools/android:incremental_install_test
//tools/android:incremental_install
//tools/android:build_split_manifest_test
//tools/android:build_split_manifest
//tools/android:build_incremental_dexmanifest
//tools/android:aar_resources_extractor_test
//tools/android:aar_resources_extractor
//tools/android:aar_native_libs_zip_creator_test
//tools/android:aar_native_libs_zip_creator
//tools/android:aar_embedded_jars_extractor_test
//tools/android:aar_embedded_jars_extractor
//src/test/starlark:starlark_test_testdata/string_test_characters_sky
[... other _sky targets, all of which are generated by the same pattern in //src/test/starlark ...]

Metadata

Metadata

Assignees

Labels

P1I'll work on this now. (Assignee required)area-EngProdBazel CI, infrastructure, bootstrapping, release, and distribution toolingteam-OSSIssues for the Bazel OSS team: installation, release processBazel packaging, websitetype: bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions