Skip to content

Commit

Permalink
fix: Make RECORD from wheel available via whl_filegroup
Browse files Browse the repository at this point in the history
whl_filegroup will now per default also provide the RECORD file from the wheel
  • Loading branch information
TimotheusBachinger committed Sep 26, 2024
1 parent 387c2f6 commit 524b8d8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 34 deletions.
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

0 comments on commit 524b8d8

Please sign in to comment.