Skip to content

incompatible_python_disable_py2 #17293

@rickeylev

Description

@rickeylev

This issue tracks enabling --incompatible_python_disable_py2 (implemented in d1bbf4b) as part of #15684

When enabled, the Python rules will reject Python 2 only attribute values. This includes:

  • python_version=PY2
  • srcs_version=PY2 and srcs_version=PY2ONLY
  • Setting py2_runtime

To fix, you must update your rules (or dependencies) to not set these Python 2 values:

  • For srcs_version: remove the attribute.
  • For py2_runtime: remove the attribute.
  • For python_version: remove the attribute from py_binary and py_test. For py_runtime,
    the entire target can be deleted, as there is nothing that can use it.

Note that the PyInfo and PyRuntimeInfo providers do not raise an error. This is simply because providers can't access flags to know whether to enforce behavior; code should still be updated as appropriate:

  • For PyInfo, stop reading/writing has_py2_only_sources and has_py3_only_sources.
  • For PyRuntimeInfo, set python_version=PY3

Most of this can be automated using buildozer

remove python_version //...%py_binary
remove python_version //...%py_test
remove srcs_version //...%py_binary
remove srcs_version //...%py_test
remove srcs_version //...%py_library
remove py2_runtime //...%py_runtime_pair

It may not be your code with a problem, but a dependency. In this case, you probably just need to update your dependency to a newer version -- most projects no longer require Python 2.

  • For rules_pkg, upgrade to 0.3.0 or greater

Metadata

Metadata

Labels

breaking-change-7.0Incompatible flags to be flipped in Bazel 7.0incompatible-changeIncompatible/breaking changemigration-readyIncompatible flag is ready for migration with Bazel rolling releases or Bazel@last_greenteam-Rules-PythonNative rules for Pythontype: process

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions