Skip to content

Commit 3ecc4df

Browse files
committed
feat(legacy): ensure that we are using an X.Y version in pip_multiparse
1 parent 9f06b4e commit 3ecc4df

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

python/pip.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ load("//python/pip_install:requirements.bzl", _compile_pip_requirements = "compi
1919
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED")
2020
load("//python/private:full_version.bzl", "full_version")
2121
load("//python/private:render_pkg_aliases.bzl", "NO_MATCH_ERROR_MESSAGE_TEMPLATE")
22+
load("//python/private:version_label.bzl", "version_label")
2223

2324
compile_pip_requirements = _compile_pip_requirements
2425
package_annotation = _package_annotation
@@ -369,7 +370,7 @@ def multi_pip_parse(name, default_version, python_versions, python_interpreter_t
369370
if not python_version in requirements_lock:
370371
fail("Missing requirements_lock for Python version %s in '%s'" % (python_version, name))
371372

372-
pip_parse_name = name + "_" + python_version.replace(".", "_")
373+
pip_parse_name = name + "_" + version_label(full_version(python_version), sep = "_")
373374
pip_parse(
374375
name = pip_parse_name,
375376
python_interpreter_target = python_interpreter_target[python_version],

python/private/toolchains_repo.bzl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ load(
3030
"PLATFORMS",
3131
"WINDOWS_NAME",
3232
)
33+
load(":full_version.bzl", "full_version")
3334
load(":which.bzl", "which_with_fail")
3435

3536
def get_repository_name(repository_workspace):
@@ -252,8 +253,12 @@ def _multi_toolchain_aliases_impl(rctx):
252253
rules_python = rctx.attr._rules_python_workspace.workspace_name
253254

254255
for python_version, repository_name in rctx.attr.python_versions.items():
255-
file = "{}/defs.bzl".format(python_version)
256-
rctx.file(file, content = """\
256+
python_version = full_version(python_version)
257+
for is_short in [False, True]:
258+
python_version_short, _, _ = python_version.rpartition(".")
259+
v = python_version_short if is_short else python_version
260+
261+
rctx.file("{}/defs.bzl".format(v), content = """\
257262
# Generated by python/private/toolchains_repo.bzl
258263
259264
load(
@@ -266,16 +271,18 @@ load(
266271
_py_test = "py_test",
267272
)
268273
274+
{warning}
269275
compile_pip_requirements = _compile_pip_requirements
270276
host_platform = _host_platform
271277
interpreter = _interpreter
272278
py_binary = _py_binary
273279
py_console_script_binary = _py_console_script_binary
274280
py_test = _py_test
275281
""".format(
276-
repository_name = repository_name,
277-
))
278-
rctx.file("{}/BUILD.bazel".format(python_version), "")
282+
repository_name = repository_name,
283+
warning = "" if is_short else 'print("switch to importing from \"{}:defs.bzl\"")'.format(python_version_short),
284+
))
285+
rctx.file("{}/BUILD.bazel".format(v), "")
279286

280287
pip_bzl = """\
281288
# Generated by python/private/toolchains_repo.bzl

0 commit comments

Comments
 (0)