Skip to content

Commit f14bea6

Browse files
committed
add warnings for the python toolchains that have been dropped
1 parent 9b4a71a commit f14bea6

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

python/private/config_settings.bzl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ If the value is missing, then the default value is being used, see documentation
3535
# access it, but it's not intended for general public usage.
3636
_NOT_ACTUALLY_PUBLIC = ["//visibility:public"]
3737

38-
def construct_config_settings(*, name, default_version, versions, minor_mapping, documented_flags): # buildifier: disable=function-docstring
38+
def construct_config_settings(
39+
*,
40+
name,
41+
default_version,
42+
versions,
43+
minor_mapping,
44+
documented_flags): # buildifier: disable=function-docstring
3945
"""Create a 'python_version' config flag and construct all config settings used in rules_python.
4046
4147
This mainly includes the targets that are used in the toolchain and pip hub
@@ -109,13 +115,29 @@ def construct_config_settings(*, name, default_version, versions, minor_mapping,
109115
# It's private because matching the concept of e.g. "3.8" value is done
110116
# using the `is_python_X.Y` config setting group, which is aware of the
111117
# minor versions that could match instead.
118+
first_minor = None
112119
for minor in minor_mapping.keys():
120+
if first_minor == None:
121+
first_minor = minor
122+
113123
native.config_setting(
114124
name = "is_python_{}".format(minor),
115125
flag_values = {_PYTHON_VERSION_MAJOR_MINOR_FLAG: minor},
116126
visibility = ["//visibility:public"],
117127
)
118128

129+
for minor in range(int(first_minor.partition(".")[-1]) + 1):
130+
minor = "3.{}".format(minor)
131+
if minor in minor_mapping:
132+
break
133+
134+
# TODO @aignas 2025-11-04: use env-marker-setting with the smallest minor_mapping version
135+
native.alias(
136+
name = "is_python_{}".format(minor),
137+
actual = "@platforms//:incompatible",
138+
visibility = ["//visibility:public"],
139+
)
140+
119141
_current_config(
120142
name = "current_config",
121143
build_setting_default = "",

python/private/full_version.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414

1515
"""A small helper to ensure that we are working with full versions."""
1616

17-
def full_version(*, version, minor_mapping):
17+
def full_version(*, version, minor_mapping, err = True):
1818
"""Return a full version.
1919
2020
Args:
2121
version: {type}`str` the version in `X.Y` or `X.Y.Z` format.
2222
minor_mapping: {type}`dict[str, str]` mapping between `X.Y` to `X.Y.Z` format.
23+
err: {type}`bool` whether to fail on error or return `None` instead.
2324
2425
Returns:
2526
a full version given the version string. If the string is already a
@@ -31,6 +32,8 @@ def full_version(*, version, minor_mapping):
3132
parts = version.split(".")
3233
if len(parts) == 3:
3334
return version
35+
elif not err:
36+
return None
3437
elif len(parts) == 2:
3538
fail(
3639
"Unknown Python version '{}', available values are: {}".format(

python/private/pypi/hub_builder.bzl

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,25 @@ def _pip_parse(self, module_ctx, pip_attr):
114114
version = python_version,
115115
))
116116

117-
self._platforms[python_version] = _platforms(
118-
python_version = python_version,
117+
full_python_version = full_version(
118+
version = python_version,
119119
minor_mapping = self._minor_mapping,
120+
err = False,
121+
)
122+
if not full_python_version:
123+
self._logger.warn(lambda: (
124+
"Ignoring pip python version '{version}' for hub " +
125+
"'{hub}' in module '{module}' because there is no registered " +
126+
"toolchain for it."
127+
).format(
128+
hub = self.name,
129+
module = self.module_name,
130+
version = python_version,
131+
))
132+
return
133+
134+
self._platforms[python_version] = _platforms(
135+
python_version = full_python_version,
120136
config = self._config,
121137
)
122138
_set_get_index_urls(self, pip_attr)
@@ -280,13 +296,10 @@ def _detect_interpreter(self, pip_attr):
280296
path = pip_attr.python_interpreter,
281297
)
282298

283-
def _platforms(*, python_version, minor_mapping, config):
299+
def _platforms(*, python_version, config):
284300
platforms = {}
285301
python_version = version.parse(
286-
full_version(
287-
version = python_version,
288-
minor_mapping = minor_mapping,
289-
),
302+
python_version,
290303
strict = True,
291304
)
292305

python/private/python.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,12 @@ def _python_impl(module_ctx):
268268
full_python_version = full_version(
269269
version = toolchain_info.python_version,
270270
minor_mapping = py.config.minor_mapping,
271+
err = False,
271272
)
273+
if not full_python_version:
274+
logger.warn(lambda: "The python version '{}' is unknown, please configure a toolchain to be downloaded".format(toolchain_info.python_version))
275+
continue
276+
272277
kwargs = {
273278
"python_version": full_python_version,
274279
"register_coverage_tool": toolchain_info.register_coverage_tool,

0 commit comments

Comments
 (0)