Skip to content

Commit 9a98e8c

Browse files
fix(whl_filegroup): Make RECORD from wheel available (#2238)
Why this change is being made, briefly. * We need to also get the `RECORD` file from a wheel in order to package everything * It seems a bit weird to me that the `RECORD` file is *not part* of `whl_filegroup` even no pattern filtering was applied (or I am misunderstanding something) * Further: neither `hash` nor `filelen` have been used in the code, so why are only files considered with those attributes?
1 parent 416bd4c commit 9a98e8c

File tree

3 files changed

+16
-36
lines changed

3 files changed

+16
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ A brief description of the categories of changes:
2828
* Nothing yet
2929

3030
### Fixed
31-
* Nothing yet
31+
* (whl_filegroup): Provide per default also the `RECORD` file
3232

3333
### Added
3434
* Nothing yet
@@ -83,7 +83,6 @@ A brief description of the categories of changes:
8383
* (toolchain) The {bzl:obj}`gen_python_config_settings` has been fixed to include
8484
the flag_values from the platform definitions.
8585

86-
8786
### Added
8887
* (bzlmod): Toolchain overrides can now be done using the new
8988
{bzl:obj}`python.override`, {bzl:obj}`python.single_version_override` and

python/private/whl_filegroup/extract_wheel_files.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from collections.abc import Iterable
77
from pathlib import Path
88

9-
WhlRecord = dict[str, tuple[str, int]]
9+
WhlRecord = Iterable[str]
1010

1111

1212
def get_record(whl_path: Path) -> WhlRecord:
@@ -20,18 +20,16 @@ def get_record(whl_path: Path) -> WhlRecord:
2020
except ValueError:
2121
raise RuntimeError(f"{whl_path} doesn't contain exactly one .dist-info/RECORD")
2222
record_lines = zipf.read(record_file).decode().splitlines()
23-
return {
24-
file: (filehash, int(filelen))
23+
return (
24+
line.split(",")[0]
2525
for line in record_lines
26-
for file, filehash, filelen in [line.split(",")]
27-
if filehash # Skip RECORD itself, which has no hash or length
28-
}
26+
)
2927

3028

3129
def get_files(whl_record: WhlRecord, regex_pattern: str) -> list[str]:
3230
"""Get files in a wheel that match a regex pattern."""
3331
p = re.compile(regex_pattern)
34-
return [filepath for filepath in whl_record.keys() if re.match(p, filepath)]
32+
return [filepath for filepath in whl_record if re.match(p, filepath)]
3533

3634

3735
def extract_files(whl_path: Path, files: Iterable[str], outdir: Path) -> None:

tests/whl_filegroup/extract_wheel_files_test.py

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,17 @@
1010
class WheelRecordTest(unittest.TestCase):
1111
def test_get_wheel_record(self) -> None:
1212
record = extract_wheel_files.get_record(_WHEEL)
13-
expected = {
14-
"examples/wheel/lib/data.txt": (
15-
"sha256=9vJKEdfLu8bZRArKLroPZJh1XKkK3qFMXiM79MBL2Sg",
16-
12,
17-
),
18-
"examples/wheel/lib/module_with_data.py": (
19-
"sha256=8s0Khhcqz3yVsBKv2IB5u4l4TMKh7-c_V6p65WVHPms",
20-
637,
21-
),
22-
"examples/wheel/lib/simple_module.py": (
23-
"sha256=z2hwciab_XPNIBNH8B1Q5fYgnJvQTeYf0ZQJpY8yLLY",
24-
637,
25-
),
26-
"examples/wheel/main.py": (
27-
"sha256=sgg5iWN_9inYBjm6_Zw27hYdmo-l24fA-2rfphT-IlY",
28-
909,
29-
),
30-
"example_minimal_package-0.0.1.dist-info/WHEEL": (
31-
"sha256=sobxWSyDDkdg_rinUth-jxhXHqoNqlmNMJY3aTZn2Us",
32-
91,
33-
),
34-
"example_minimal_package-0.0.1.dist-info/METADATA": (
35-
"sha256=cfiQ2hFJhCKCUgbwtAwWG0fhW6NTzw4cr1uKOBcV_IM",
36-
76,
37-
),
38-
}
13+
expected = (
14+
"examples/wheel/lib/data.txt",
15+
"examples/wheel/lib/module_with_data.py",
16+
"examples/wheel/lib/simple_module.py",
17+
"examples/wheel/main.py",
18+
"example_minimal_package-0.0.1.dist-info/WHEEL",
19+
"example_minimal_package-0.0.1.dist-info/METADATA",
20+
"example_minimal_package-0.0.1.dist-info/RECORD",
21+
)
3922
self.maxDiff = None
40-
self.assertDictEqual(record, expected)
23+
self.assertEqual(list(record), list(expected))
4124

4225
def test_get_files(self) -> None:
4326
pattern = "(examples/wheel/lib/.*\.txt$|.*main)"

0 commit comments

Comments
 (0)