Skip to content

Commit 5bdfbe2

Browse files
committed
Stop attempting to read @@//:.python-version
The idea to read .python-version in the root module was problematic for two reasons. For one thing, if there is a .python-version file in the root module, but no BUILD or BUILD.bazel file on the top level, we produce an error that we can't catch. This would be a breaking change, requiring users to add a BUILD.bazel file. Also, if the user has a .python-version file, and also sets is_default on a toolchain, we would fail the build (or, if we didn't, we'd change the default Python version against the users explicit instructions). That would also be a breaking change. Removing the @@//:.python-version logic means the user needs to opt in by saying python_version_file="@@//.python-version". That's not necessarily a bad thing, as being explicit allows anyone to grep the repo for the label and find out what cares about that file (as pointed out by @fmeum on Slack; good point).
1 parent 1a94ad4 commit 5bdfbe2

File tree

2 files changed

+1
-36
lines changed

2 files changed

+1
-36
lines changed

python/private/python.bzl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,6 @@ def parse_modules(*, module_ctx, _fail = fail):
118118
default_python_version_env,
119119
default_python_version,
120120
)
121-
if not default_python_version:
122-
fallback_python_version_file = module_ctx.path(Label("@@//:.python-version"))
123-
if fallback_python_version_file.exists:
124-
default_python_version = module_ctx.read(
125-
fallback_python_version_file,
126-
watch = "yes",
127-
).strip()
128121

129122
seen_versions = {}
130123
for mod in module_ctx.modules:
@@ -156,8 +149,7 @@ def parse_modules(*, module_ctx, _fail = fail):
156149
is_default = default_python_version == toolchain_version
157150
if toolchain_attr.is_default and not is_default:
158151
fail("The 'is_default' attribute doesn't work if you set " +
159-
"the default Python version with the `defaults` tag " +
160-
"or the '.python-version' file.")
152+
"the default Python version with the `defaults` tag.")
161153
else:
162154
is_default = toolchain_attr.is_default
163155

tests/python/python_tests.bzl

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -364,33 +364,6 @@ def _test_default_from_defaults_file(env):
364364

365365
_tests.append(_test_default_from_defaults_file)
366366

367-
def _test_default_from_defaults_implicit_file(env):
368-
py = parse_modules(
369-
module_ctx = _mock_mctx(
370-
_mod(
371-
name = "my_root_module",
372-
defaults = [],
373-
toolchain = [_toolchain("3.10"), _toolchain("3.11"), _toolchain("3.12")],
374-
is_root = True,
375-
),
376-
mocked_files = {Label("@@//:.python-version"): "3.12\n"},
377-
),
378-
)
379-
380-
env.expect.that_str(py.default_python_version).equals("3.12")
381-
382-
want_toolchains = [
383-
struct(
384-
name = "python_3_" + minor_version,
385-
python_version = "3." + minor_version,
386-
register_coverage_tool = False,
387-
)
388-
for minor_version in ["10", "11", "12"]
389-
]
390-
env.expect.that_collection(py.toolchains).contains_exactly(want_toolchains)
391-
392-
_tests.append(_test_default_from_defaults_implicit_file)
393-
394367
def _test_first_occurance_of_the_toolchain_wins(env):
395368
py = parse_modules(
396369
module_ctx = _mock_mctx(

0 commit comments

Comments
 (0)