Remove logic in the python_version select() that reads deprecated flag
--force_python has been made a no-op, so there's no need for
@bazel_tools//tools/python:python_version to consider it.
Work toward #7797.
RELNOTES: None
PiperOrigin-RevId: 302676532
diff --git a/tools/python/BUILD.tools b/tools/python/BUILD.tools
index 0fb695b..c2ef695 100644
--- a/tools/python/BUILD.tools
+++ b/tools/python/BUILD.tools
@@ -94,10 +94,11 @@
# ...
# )
#
-# Caution: Do not `select()` on the built-in command-line flags `--force_python`
-# or `--python_version`, as they do not always reflect the true Python version
-# of the current target. `select()`-ing on them can lead to action conflicts and
-# will be disallowed.
+# Note that it is not allowed to `select()` on the built-in command-line flag
+# `--python_version`. This is because historically, the flag's value has not
+# always corresponded to the effective Python version, due to some indirections
+# around legacy APIs, legacy semantics, and changing the default version from
+# PY2 to PY3.
define_python_version_flag(
name = "python_version",
)
diff --git a/tools/python/python_version.bzl b/tools/python/python_version.bzl
index aecad07..35813e2 100644
--- a/tools/python/python_version.bzl
+++ b/tools/python/python_version.bzl
@@ -21,15 +21,14 @@
_PY3 = "PY3"
def _python_version_flag_impl(ctx):
- # Version is determined using the same logic as in PythonOptions#getPythonVersion:
+ # Version is determined using the same logic as in
+ # PythonOptions#getPythonVersion:
#
# 1. Consult --python_version first, if present.
- # 2. Next fall back on --force_python, if present.
- # 3. Final fallback is on the hardcoded default.
+ # 2. Fallback on the default, which is governed by an incompatible change
+ # flag.
if ctx.attr.python_version_flag != _UNSET:
version = ctx.attr.python_version_flag
- elif ctx.attr.force_python_flag != _UNSET:
- version = ctx.attr.force_python_flag
else:
version = _PY3 if ctx.attr.incompatible_py3_is_default_flag else _PY2
@@ -41,7 +40,6 @@
_python_version_flag = rule(
implementation = _python_version_flag_impl,
attrs = {
- "force_python_flag": attr.string(mandatory = True, values = [_PY2, _PY3, _UNSET]),
"python_version_flag": attr.string(mandatory = True, values = [_PY2, _PY3, _UNSET]),
"incompatible_py3_is_default_flag": attr.bool(mandatory = True),
},
@@ -65,17 +63,7 @@
fail("Python version flag must be named 'python_version'")
# Config settings for the underlying native flags we depend on:
- # --force_python, --python_version, and --incompatible_py3_is_default.
- native.config_setting(
- name = "_force_python_setting_PY2",
- values = {"force_python": "PY2"},
- visibility = ["//visibility:private"],
- )
- native.config_setting(
- name = "_force_python_setting_PY3",
- values = {"force_python": "PY3"},
- visibility = ["//visibility:private"],
- )
+ # --python_version and --incompatible_py3_is_default.
native.config_setting(
name = "_python_version_setting_PY2",
values = {"python_version": "PY2"},
@@ -99,11 +87,6 @@
_python_version_flag(
name = name,
- force_python_flag = select({
- ":_force_python_setting_PY2": _PY2,
- ":_force_python_setting_PY3": _PY3,
- "//conditions:default": _UNSET,
- }),
python_version_flag = select({
":_python_version_setting_PY2": _PY2,
":_python_version_setting_PY3": _PY3,