Skip to content

Commit 79f6546

Browse files
mai93rickeylev
andauthored
chore: reject py2 runtimes and remove usages of ctx.fragments.py.disable_py2 (#3319)
This removes the usages of the disable_py2 fragment attribute. This also makes py2 runtimes rejected (both when set on py_runtime and PyRuntimeInfo) Because Python 2 support was dropped long ago and other parts of the code reject, ignore, or don't work with Python 2 already, this is not considered a breaking change. Work towards: #3252 --------- Co-authored-by: Richard Levasseur <[email protected]>
1 parent 309e93e commit 79f6546

File tree

4 files changed

+9
-19
lines changed

4 files changed

+9
-19
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ END_UNRELEASED_TEMPLATE
7171
paths, runtime site-packages]`.
7272
* (pip) Publishing deps are no longer pulled via `experimental_index_url`.
7373
([#2937](https://github.com/bazel-contrib/rules_python/issues/2937)).
74+
* (toolchains) `py_runtime` and `PyRuntimeInfo` reject Python 2 settings.
75+
Setting `py_runtime.python_version = "PY2"` or non-None
76+
`PyRuntimeInfo.py2_runtime` is an error.
7477

7578
{#v0-0-0-fixed}
7679
### Fixed

python/private/flags.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ load(":enum.bzl", "FlagEnum", "enum")
3939
_POSSIBLY_NATIVE_FLAGS = {
4040
"build_python_zip": (lambda ctx: ctx.fragments.py.build_python_zip, "native"),
4141
"default_to_explicit_init_py": (lambda ctx: ctx.fragments.py.default_to_explicit_init_py, "native"),
42-
"disable_py2": (lambda ctx: ctx.fragments.py.disable_py2, "native"),
4342
"python_import_all_repositories": (lambda ctx: ctx.fragments.bazel_py.python_import_all_repositories, "native"),
4443
"python_path": (lambda ctx: ctx.fragments.bazel_py.python_path, "native"),
4544
}

python/private/py_runtime_pair_rule.bzl

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
1818
load("//python:py_runtime_info.bzl", "PyRuntimeInfo")
1919
load(":common_labels.bzl", "labels")
20-
load(":flags.bzl", "read_possibly_native_flag")
2120
load(":reexports.bzl", "BuiltinPyRuntimeInfo")
2221

2322
def _py_runtime_pair_impl(ctx):
@@ -37,10 +36,9 @@ def _py_runtime_pair_impl(ctx):
3736
else:
3837
py3_runtime = None
3938

40-
# TODO: Uncomment this after --incompatible_python_disable_py2 defaults to true
41-
# if _is_py2_disabled(ctx) and py2_runtime != None:
42-
# fail("Using Python 2 is not supported and disabled; see " +
43-
# "https://github.com/bazelbuild/bazel/issues/15684")
39+
if py2_runtime != None:
40+
fail("Using Python 2 is not supported and disabled; see " +
41+
"https://github.com/bazelbuild/bazel/issues/15684")
4442

4543
extra_kwargs = {}
4644
if ctx.attr._visible_for_testing[BuildSettingInfo].value:
@@ -62,15 +60,6 @@ def _get_py_runtime_info(target):
6260
else:
6361
return target[BuiltinPyRuntimeInfo]
6462

65-
# buildifier: disable=unused-variable
66-
def _is_py2_disabled(ctx):
67-
# Because this file isn't bundled with Bazel, so we have to conditionally
68-
# check for this flag.
69-
# TODO: Remove this once all supported Balze versions have this flag.
70-
if not hasattr(ctx.fragments.py, "disable_py"):
71-
return False
72-
return read_possibly_native_flag(ctx, "disable_py2")
73-
7463
_MaybeBuiltinPyRuntimeInfo = [[BuiltinPyRuntimeInfo]] if BuiltinPyRuntimeInfo != None else []
7564

7665
py_runtime_pair = rule(

python/private/py_runtime_rule.bzl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ def _py_runtime_impl(ctx):
8787
if python_version_flag:
8888
interpreter_version_info = _interpreter_version_info_from_version_str(python_version_flag)
8989

90-
# TODO: Uncomment this after --incompatible_python_disable_py2 defaults to true
91-
# if ctx.fragments.py.disable_py2 and python_version == "PY2":
92-
# fail("Using Python 2 is not supported and disabled; see " +
93-
# "https://github.com/bazelbuild/bazel/issues/15684")
90+
if python_version == "PY2":
91+
fail("Using Python 2 is not supported and disabled; see " +
92+
"https://github.com/bazelbuild/bazel/issues/15684")
9493

9594
pyc_tag = ctx.attr.pyc_tag
9695
if not pyc_tag and (ctx.attr.implementation_name and

0 commit comments

Comments
 (0)