Skip to content

fix(whl_filegroup): Make RECORD from wheel available #2238

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

Merged
Merged
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
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ A brief description of the categories of changes:
* Nothing yet

### Fixed
* Nothing yet
* (whl_filegroup): Provide per default also the `RECORD` file

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


### Added
* (bzlmod): Toolchain overrides can now be done using the new
{bzl:obj}`python.override`, {bzl:obj}`python.single_version_override` and
Expand Down
12 changes: 5 additions & 7 deletions python/private/whl_filegroup/extract_wheel_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections.abc import Iterable
from pathlib import Path

WhlRecord = dict[str, tuple[str, int]]
WhlRecord = Iterable[str]


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


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


def extract_files(whl_path: Path, files: Iterable[str], outdir: Path) -> None:
Expand Down
37 changes: 10 additions & 27 deletions tests/whl_filegroup/extract_wheel_files_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,17 @@
class WheelRecordTest(unittest.TestCase):
def test_get_wheel_record(self) -> None:
record = extract_wheel_files.get_record(_WHEEL)
expected = {
"examples/wheel/lib/data.txt": (
"sha256=9vJKEdfLu8bZRArKLroPZJh1XKkK3qFMXiM79MBL2Sg",
12,
),
"examples/wheel/lib/module_with_data.py": (
"sha256=8s0Khhcqz3yVsBKv2IB5u4l4TMKh7-c_V6p65WVHPms",
637,
),
"examples/wheel/lib/simple_module.py": (
"sha256=z2hwciab_XPNIBNH8B1Q5fYgnJvQTeYf0ZQJpY8yLLY",
637,
),
"examples/wheel/main.py": (
"sha256=sgg5iWN_9inYBjm6_Zw27hYdmo-l24fA-2rfphT-IlY",
909,
),
"example_minimal_package-0.0.1.dist-info/WHEEL": (
"sha256=sobxWSyDDkdg_rinUth-jxhXHqoNqlmNMJY3aTZn2Us",
91,
),
"example_minimal_package-0.0.1.dist-info/METADATA": (
"sha256=cfiQ2hFJhCKCUgbwtAwWG0fhW6NTzw4cr1uKOBcV_IM",
76,
),
}
expected = (
"examples/wheel/lib/data.txt",
"examples/wheel/lib/module_with_data.py",
"examples/wheel/lib/simple_module.py",
"examples/wheel/main.py",
"example_minimal_package-0.0.1.dist-info/WHEEL",
"example_minimal_package-0.0.1.dist-info/METADATA",
"example_minimal_package-0.0.1.dist-info/RECORD",
)
self.maxDiff = None
self.assertDictEqual(record, expected)
self.assertEqual(list(record), list(expected))

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