From 185617062572d203f1c19d1490b2e755415517fe Mon Sep 17 00:00:00 2001 From: Matt Mackay Date: Sat, 5 Apr 2025 14:57:18 -0400 Subject: [PATCH] fix: escape name segment of stamped wheel files --- CHANGELOG.md | 1 + examples/wheel/wheel_test.py | 2 +- python/private/py_wheel.bzl | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbb0c03e59..cd6a8b6b31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,7 @@ Unreleased changes template. transitions transitioning on the `python_version` flag. Fixes [#2685](https://github.com/bazel-contrib/rules_python/issues/2685). * (toolchains) Run the check on the Python interpreter in isolated mode, to ensure it's not affected by userland environment variables, such as `PYTHONPATH`. +* (py_wheel) Ensure the filename segment is escaped in when using stamping wheel names. {#v0-0-0-added} ### Added diff --git a/examples/wheel/wheel_test.py b/examples/wheel/wheel_test.py index a3d6034930..b9b6c1b7e0 100644 --- a/examples/wheel/wheel_test.py +++ b/examples/wheel/wheel_test.py @@ -440,7 +440,7 @@ def test_rule_creates_directory_and_is_included_in_wheel(self): def test_rule_expands_workspace_status_keys_in_wheel_metadata(self): filename = self._get_path( - "example_minimal_library{BUILD_USER}-0.1.{BUILD_TIMESTAMP}-py3-none-any.whl" + "example_minimal_library{BUILD_USER}-0.1._BUILD_TIMESTAMP_-py3-none-any.whl" ) with zipfile.ZipFile(filename) as zf: diff --git a/python/private/py_wheel.bzl b/python/private/py_wheel.bzl index c196ca6ad0..9cbebed348 100644 --- a/python/private/py_wheel.bzl +++ b/python/private/py_wheel.bzl @@ -304,13 +304,15 @@ def _input_file_to_arg(input_file): return "%s;%s" % (py_package_lib.path_inside_wheel(input_file), input_file.path) def _py_wheel_impl(ctx): + is_stamping = is_stamping_enabled(ctx.attr) + abi = _replace_make_variables(ctx.attr.abi, ctx) python_tag = _replace_make_variables(ctx.attr.python_tag, ctx) version = _replace_make_variables(ctx.attr.version, ctx) filename_segments = [ _escape_filename_distribution_name(ctx.attr.distribution), - normalize_pep440(version), + _escape_filename_segment(normalize_pep440(version)) if is_stamping else normalize_pep440(version), _escape_filename_segment(python_tag), _escape_filename_segment(abi), _escape_filename_segment(ctx.attr.platform), @@ -352,7 +354,7 @@ def _py_wheel_impl(ctx): args.add_all(ctx.attr.strip_path_prefixes, format_each = "--strip_path_prefix=%s") # Pass workspace status files if stamping is enabled - if is_stamping_enabled(ctx.attr): + if is_stamping: args.add("--volatile_status_file", ctx.version_file) args.add("--stable_status_file", ctx.info_file) other_inputs.extend([ctx.version_file, ctx.info_file])