Skip to content

fix: escape name segment of stamped wheel files #2741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ END_UNRELEASED_TEMPLATE
* (rules) PyInfo provider is now advertised by py_test, py_binary, and py_library;
this allows aspects using required_providers to function correctly.
([#2506](https://github.com/bazel-contrib/rules_python/issues/2506)).
* (py_wheel) Ensure the filename segment is escaped in when using stamping wheel names.

{#v0-0-0-added}
### Added
Expand Down
2 changes: 1 addition & 1 deletion examples/wheel/wheel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The distribution likely needs escaping too.

)

with zipfile.ZipFile(filename) as zf:
Expand Down
6 changes: 4 additions & 2 deletions python/private/py_wheel.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something strange is going on, or I'm missing something.

The net code change is the same as before: normalize(...) if ... else normalize(...)

The test was updated, though? Which would mean it's working?? Is the test not covering something...?

_escape_filename_segment(python_tag),
_escape_filename_segment(abi),
_escape_filename_segment(ctx.attr.platform),
Expand Down Expand Up @@ -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])
Expand Down