Skip to content

Commit a570e1a

Browse files
committed
fix(python): correctly order the toolchains
Since toolchain matching is done by matching the first target that matches target settings, the `minor_mapping` config setting is special, because e.g. all `3.11.X` toolchains match the `python_version = "3.11"` setting. This just reshuffles the list so that we have toolchains that are in the `minor_mapping` before the rest. Fixes bazel-contrib#2685
1 parent eb1c0a1 commit a570e1a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

python/private/python.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,18 @@ def parse_modules(*, module_ctx, _fail = fail):
243243
if len(toolchains) > _MAX_NUM_TOOLCHAINS:
244244
fail("more than {} python versions are not supported".format(_MAX_NUM_TOOLCHAINS))
245245

246+
# sort the toolchains so that the toolchain versions that are in the
247+
# `minor_mapping` are coming first. This ensures that `python_version =
248+
# "3.X"` transitions work as expected.
249+
minor_version_toolchains = []
250+
other_toolchains = []
251+
for t in toolchains:
252+
if t.python_version in config.minor_mapping:
253+
minor_version_toolchains.append(t)
254+
else:
255+
other_toolchains.append(t)
256+
toolchains = minor_version_toolchains + other_toolchains
257+
246258
return struct(
247259
config = config,
248260
debug_info = debug_info,

0 commit comments

Comments
 (0)