Skip to content

Commit b5a337b

Browse files
committed
Drop support for Bazel 7.0 in python_version_env
Implement python.defaults.python_version_env in terms of module_ctx.getenv, which was introduced in Bazel 7.1. This means that Bazel 7.0 users who wish to use the new python_version_env will have to upgrade to Bazel 7.1 or later.
1 parent 678a608 commit b5a337b

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

python/private/python.bzl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,10 @@ def parse_modules(*, module_ctx, _fail = fail):
114114
module_ctx.read(default_python_version_file).strip(),
115115
)
116116
if default_python_version_env:
117-
# Bazel version 7.1.0 and later support module_ctx.getenv(name, default):
118-
# When building incrementally, any change to the value of the variable
119-
# named by `name` will cause this repository to be re-fetched.
120-
if "getenv" in dir(module_ctx):
121-
getenv = module_ctx.getenv
122-
else:
123-
getenv = module_ctx.os.environ.get
124-
default_python_version = getenv(default_python_version_env, default_python_version)
117+
default_python_version = module_ctx.getenv(
118+
default_python_version_env,
119+
default_python_version,
120+
)
125121
if not default_python_version:
126122
fallback_python_version_file = module_ctx.path(Label("@@//:.python-version"))
127123
if fallback_python_version_file.exists:

tests/python/python_tests.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def _mock_mctx(*modules, environ = {}, mocked_files = {}):
2424
return struct(
2525
path = lambda x: struct(exists = x in mocked_files, _file = x),
2626
read = lambda x: mocked_files[x._file if "_file" in dir(x) else x],
27+
getenv = environ.get,
2728
os = struct(environ = environ),
2829
modules = [
2930
struct(

0 commit comments

Comments
 (0)