Skip to content

Commit a79b66a

Browse files
authored
chore/fix!: remove incompatible whl packaging flags (#1569)
Remove incompatible `whl` packaging flags that had been flipped in `0.27.0` release. Also fixes a bug where the the build stamp values (e.g. build username) were lowercased when they shouldn't be.
1 parent b106f91 commit a79b66a

File tree

5 files changed

+35
-164
lines changed

5 files changed

+35
-164
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ A brief description of the categories of changes:
2424
### Changed
2525

2626
* **BREAKING** The deprecated `incompatible_generate_aliases` feature flags
27-
from `pip_parse` and `gazelle` got removed. They have been flipped to `True`
27+
from `pip_parse` and `gazelle` got removed. They had been flipped to `True`
2828
in 0.27.0 release.
29+
* **BREAKING** (wheel) The `incompatible_normalize_name` and
30+
`incompatible_normalize_version` flags have been removed. They had been
31+
flipped to `True` in 0.27.0 release.
2932

3033
### Fixed
3134

@@ -34,6 +37,8 @@ A brief description of the categories of changes:
3437
platform-specific content in `MODULE.bazel.lock` files; Follow
3538
[#1643](https://github.com/bazelbuild/rules_python/issues/1643) for removing
3639
platform-specific content in `MODULE.bazel.lock` files.
40+
* (wheel) The stamp variables inside the distribution name are no longer
41+
lower-cased when normalizing under PEP440 conventions.
3742

3843
### Added
3944

examples/wheel/BUILD.bazel

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ py_wheel(
5454
testonly = True, # Set this to verify the generated .dist target doesn't break things
5555
# Package data. We're building "example_minimal_library-0.0.1-py3-none-any.whl"
5656
distribution = "example_minimal_library",
57-
incompatible_normalize_name = True,
58-
incompatible_normalize_version = True,
5957
python_tag = "py3",
6058
version = "0.0.1",
6159
deps = [
@@ -78,8 +76,6 @@ py_wheel(
7876
testonly = True,
7977
abi = "$(ABI)",
8078
distribution = "example_minimal_library",
81-
incompatible_normalize_name = True,
82-
incompatible_normalize_version = True,
8379
python_tag = "$(PYTHON_TAG)",
8480
toolchains = ["//examples/wheel:make_variable_tags"],
8581
version = "$(VERSION)",
@@ -99,8 +95,6 @@ py_wheel(
9995
name = "minimal_with_py_library_with_stamp",
10096
# Package data. We're building "example_minimal_library-0.0.1-py3-none-any.whl"
10197
distribution = "example_minimal_library{BUILD_USER}",
102-
incompatible_normalize_name = False,
103-
incompatible_normalize_version = False,
10498
python_tag = "py3",
10599
stamp = 1,
106100
version = "0.1.{BUILD_TIMESTAMP}",
@@ -129,8 +123,6 @@ py_wheel(
129123
name = "minimal_with_py_package",
130124
# Package data. We're building "example_minimal_package-0.0.1-py3-none-any.whl"
131125
distribution = "example_minimal_package",
132-
incompatible_normalize_name = True,
133-
incompatible_normalize_version = True,
134126
python_tag = "py3",
135127
version = "0.0.1",
136128
deps = [":example_pkg"],
@@ -164,8 +156,6 @@ py_wheel(
164156
"//examples/wheel:README.md": "README",
165157
},
166158
homepage = "www.example.com",
167-
incompatible_normalize_name = True,
168-
incompatible_normalize_version = True,
169159
license = "Apache 2.0",
170160
project_urls = {
171161
"Bug Tracker": "www.example.com/issues",
@@ -187,8 +177,6 @@ py_wheel(
187177
entry_points = {
188178
"console_scripts": ["main = foo.bar:baz"],
189179
},
190-
incompatible_normalize_name = True,
191-
incompatible_normalize_version = True,
192180
python_tag = "py3",
193181
strip_path_prefixes = [
194182
"examples",
@@ -203,8 +191,6 @@ py_wheel(
203191
name = "custom_package_root_multi_prefix",
204192
# Package data. We're building "custom_custom_package_root_multi_prefix-0.0.1-py3-none-any.whl"
205193
distribution = "example_custom_package_root_multi_prefix",
206-
incompatible_normalize_name = True,
207-
incompatible_normalize_version = True,
208194
python_tag = "py3",
209195
strip_path_prefixes = [
210196
"examples/wheel/lib",
@@ -220,8 +206,6 @@ py_wheel(
220206
name = "custom_package_root_multi_prefix_reverse_order",
221207
# Package data. We're building "custom_custom_package_root_multi_prefix_reverse_order-0.0.1-py3-none-any.whl"
222208
distribution = "example_custom_package_root_multi_prefix_reverse_order",
223-
incompatible_normalize_name = True,
224-
incompatible_normalize_version = True,
225209
python_tag = "py3",
226210
strip_path_prefixes = [
227211
"examples/wheel",
@@ -236,8 +220,6 @@ py_wheel(
236220
py_wheel(
237221
name = "python_requires_in_a_package",
238222
distribution = "example_python_requires_in_a_package",
239-
incompatible_normalize_name = True,
240-
incompatible_normalize_version = True,
241223
python_requires = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*",
242224
python_tag = "py3",
243225
version = "0.0.1",
@@ -249,8 +231,6 @@ py_wheel(
249231
py_wheel(
250232
name = "use_rule_with_dir_in_outs",
251233
distribution = "use_rule_with_dir_in_outs",
252-
incompatible_normalize_name = True,
253-
incompatible_normalize_version = True,
254234
python_tag = "py3",
255235
version = "0.0.1",
256236
deps = [
@@ -264,8 +244,6 @@ py_wheel(
264244
name = "python_abi3_binary_wheel",
265245
abi = "abi3",
266246
distribution = "example_python_abi3_binary_wheel",
267-
incompatible_normalize_name = True,
268-
incompatible_normalize_version = True,
269247
# these platform strings must line up with test_python_abi3_binary_wheel() in wheel_test.py
270248
platform = select({
271249
":aarch64-apple-darwin": "macosx_11_0_arm64",
@@ -279,28 +257,13 @@ py_wheel(
279257
version = "0.0.1",
280258
)
281259

282-
py_wheel(
283-
name = "legacy_filename_escaping",
284-
# Per https://www.python.org/dev/peps/pep-0427/#escaping-and-unicode
285-
# runs of non-alphanumeric, non-digit symbols should be replaced with a single underscore.
286-
# Unicode non-ascii letters should *not* be replaced with underscore.
287-
distribution = "file~~name-escaping",
288-
incompatible_normalize_name = False,
289-
incompatible_normalize_version = False,
290-
python_tag = "py3",
291-
version = "0.0.1-r7",
292-
deps = [":example_pkg"],
293-
)
294-
295260
py_wheel(
296261
name = "filename_escaping",
297262
# Per https://packaging.python.org/en/latest/specifications/binary-distribution-format/#escaping-and-unicode
298263
# runs of "-", "_" and "." should be replaced with a single underscore.
299264
# Unicode non-ascii letters aren't allowed according to
300265
# https://packaging.python.org/en/latest/specifications/name-normalization/.
301266
distribution = "File--Name-Escaping",
302-
incompatible_normalize_name = True,
303-
incompatible_normalize_version = True,
304267
python_tag = "py3",
305268
version = "v0.0.1.RC1+ubuntu-r7",
306269
deps = [":example_pkg"],
@@ -315,7 +278,6 @@ py_test(
315278
":custom_package_root_multi_prefix_reverse_order",
316279
":customized",
317280
":filename_escaping",
318-
":legacy_filename_escaping",
319281
":minimal_with_py_library",
320282
":minimal_with_py_library_with_stamp",
321283
":minimal_with_py_package",

examples/wheel/wheel_test.py

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -192,44 +192,6 @@ def test_customized_wheel(self):
192192
filename, "48eed93258bba0bb366c879b77917d947267d89e7e60005d1766d844fb909118"
193193
)
194194

195-
def test_legacy_filename_escaping(self):
196-
filename = self._get_path(
197-
"file_name_escaping-0.0.1_r7-py3-none-any.whl",
198-
)
199-
with zipfile.ZipFile(filename) as zf:
200-
self.assertAllEntriesHasReproducibleMetadata(zf)
201-
self.assertEqual(
202-
zf.namelist(),
203-
[
204-
"examples/wheel/lib/data.txt",
205-
"examples/wheel/lib/module_with_data.py",
206-
"examples/wheel/lib/simple_module.py",
207-
"examples/wheel/main.py",
208-
# PEP calls for replacing only in the archive filename.
209-
# Alas setuptools also escapes in the dist-info directory
210-
# name, so let's be compatible.
211-
"file_name_escaping-0.0.1_r7.dist-info/WHEEL",
212-
"file_name_escaping-0.0.1_r7.dist-info/METADATA",
213-
"file_name_escaping-0.0.1_r7.dist-info/RECORD",
214-
],
215-
)
216-
metadata_contents = zf.read(
217-
"file_name_escaping-0.0.1_r7.dist-info/METADATA"
218-
)
219-
self.assertEqual(
220-
metadata_contents,
221-
b"""\
222-
Metadata-Version: 2.1
223-
Name: file~~name-escaping
224-
Version: 0.0.1-r7
225-
226-
UNKNOWN
227-
""",
228-
)
229-
self.assertFileSha256Equal(
230-
filename, "ace5fab6458f8c3b4b50801b8e8214288bba786472e81547fced743a67531312"
231-
)
232-
233195
def test_filename_escaping(self):
234196
filename = self._get_path(
235197
"file_name_escaping-0.0.1rc1+ubuntu.r7-py3-none-any.whl",
@@ -450,15 +412,15 @@ def test_rule_creates_directory_and_is_included_in_wheel(self):
450412

451413
def test_rule_expands_workspace_status_keys_in_wheel_metadata(self):
452414
filename = self._get_path(
453-
"example_minimal_library_BUILD_USER_-0.1._BUILD_TIMESTAMP_-py3-none-any.whl"
415+
"example_minimal_library{BUILD_USER}-0.1.{BUILD_TIMESTAMP}-py3-none-any.whl"
454416
)
455417

456418
with zipfile.ZipFile(filename) as zf:
457419
self.assertAllEntriesHasReproducibleMetadata(zf)
458420
metadata_file = None
459421
for f in zf.namelist():
460-
self.assertNotIn("_BUILD_TIMESTAMP_", f)
461-
self.assertNotIn("_BUILD_USER_", f)
422+
self.assertNotIn("{BUILD_TIMESTAMP}", f)
423+
self.assertNotIn("{BUILD_USER}", f)
462424
if os.path.basename(f) == "METADATA":
463425
metadata_file = f
464426
self.assertIsNotNone(metadata_file)

python/private/py_wheel.bzl

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -118,28 +118,7 @@ See [`py_wheel_dist`](#py_wheel_dist) for more info.
118118
),
119119
}
120120

121-
_feature_flags = {
122-
"incompatible_normalize_name": attr.bool(
123-
default = True,
124-
doc = """\
125-
Normalize the package distribution name according to latest
126-
Python packaging standards.
127-
128-
See https://packaging.python.org/en/latest/specifications/binary-distribution-format/#escaping-and-unicode
129-
and https://packaging.python.org/en/latest/specifications/name-normalization/.
130-
131-
Apart from the valid names according to the above, we also accept
132-
'{' and '}', which may be used as placeholders for stamping.
133-
""",
134-
),
135-
"incompatible_normalize_version": attr.bool(
136-
default = True,
137-
doc = "Normalize the package version according to PEP440 standard. " +
138-
"With this option set to True, if the user wants to pass any " +
139-
"stamp variables, they have to be enclosed in '{}', e.g. " +
140-
"'{BUILD_TIMESTAMP}'.",
141-
),
142-
}
121+
_feature_flags = {}
143122

144123
_requirement_attrs = {
145124
"extra_requires": attr.string_list_dict(
@@ -237,9 +216,16 @@ def _escape_filename_distribution_name(name):
237216
'{' and '}', which may be used as placeholders for stamping.
238217
"""
239218
escaped = ""
219+
_inside_stamp_var = False
240220
for character in name.elems():
241-
if character.isalnum() or character in ["{", "}"]:
242-
escaped += character.lower()
221+
if character == "{":
222+
_inside_stamp_var = True
223+
escaped += character
224+
elif character == "}":
225+
_inside_stamp_var = False
226+
escaped += character
227+
elif character.isalnum():
228+
escaped += character if _inside_stamp_var else character.lower()
243229
elif character in ["-", "_", "."]:
244230
if escaped == "":
245231
fail(
@@ -297,23 +283,13 @@ def _py_wheel_impl(ctx):
297283
python_tag = _replace_make_variables(ctx.attr.python_tag, ctx)
298284
version = _replace_make_variables(ctx.attr.version, ctx)
299285

300-
filename_segments = []
301-
302-
if ctx.attr.incompatible_normalize_name:
303-
filename_segments.append(_escape_filename_distribution_name(ctx.attr.distribution))
304-
else:
305-
filename_segments.append(_escape_filename_segment(ctx.attr.distribution))
306-
307-
if ctx.attr.incompatible_normalize_version:
308-
filename_segments.append(normalize_pep440(version))
309-
else:
310-
filename_segments.append(_escape_filename_segment(version))
311-
312-
filename_segments.extend([
286+
filename_segments = [
287+
_escape_filename_distribution_name(ctx.attr.distribution),
288+
normalize_pep440(version),
313289
_escape_filename_segment(python_tag),
314290
_escape_filename_segment(abi),
315291
_escape_filename_segment(ctx.attr.platform),
316-
])
292+
]
317293

318294
outfile = ctx.actions.declare_file("-".join(filename_segments) + ".whl")
319295

@@ -344,10 +320,6 @@ def _py_wheel_impl(ctx):
344320
args.add("--out", outfile)
345321
args.add("--name_file", name_file)
346322
args.add_all(ctx.attr.strip_path_prefixes, format_each = "--strip_path_prefix=%s")
347-
if not ctx.attr.incompatible_normalize_name:
348-
args.add("--noincompatible_normalize_name")
349-
if not ctx.attr.incompatible_normalize_version:
350-
args.add("--noincompatible_normalize_version")
351323

352324
# Pass workspace status files if stamping is enabled
353325
if is_stamping_enabled(ctx.attr):

0 commit comments

Comments
 (0)