Skip to content

Commit 59550c8

Browse files
Add --validate-record to CLI (#161)
1 parent 0d68505 commit 59550c8

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/installer/__main__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ def _get_main_parser() -> argparse.ArgumentParser:
4343
action="store_true",
4444
help="don't generate bytecode for installed modules",
4545
)
46+
parser.add_argument(
47+
"--validate-record",
48+
metavar="part",
49+
default="none",
50+
type=str,
51+
choices=["all", "entries", "none"],
52+
help="validate the wheel against certain part of its record (default=none)",
53+
)
4654
return parser
4755

4856

@@ -84,6 +92,8 @@ def _main(cli_args: Sequence[str], program: Optional[str] = None) -> None:
8492
bytecode_levels = [0, 1]
8593

8694
with WheelFile.open(args.wheel) as source:
95+
if args.validate_record != "none":
96+
source.validate_record(args.validate_record == "all")
8797
destination = SchemeDictionaryDestination(
8898
scheme_dict=_get_scheme_dict(source.distribution, prefix=args.prefix),
8999
interpreter=sys.executable,

tests/test_main.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22

3+
import pytest
4+
35
from installer.__main__ import _get_scheme_dict as get_scheme_dict
46
from installer.__main__ import _main as main
57

@@ -67,3 +69,26 @@ def test_main_no_pyc(fancy_wheel, tmp_path):
6769

6870
installed_pyc_files = destdir.rglob("*.pyc")
6971
assert set(installed_pyc_files) == set()
72+
73+
74+
@pytest.mark.parametrize(
75+
"validation_part",
76+
["all", "entries", "none"],
77+
)
78+
def test_main_validate_record_all_pass(fancy_wheel, tmp_path, validation_part):
79+
destdir = tmp_path / "dest"
80+
81+
main(
82+
[str(fancy_wheel), "-d", str(destdir), "--validate-record", validation_part],
83+
"python -m installer",
84+
)
85+
86+
installed_py_files = destdir.rglob("*.py")
87+
88+
assert {f.stem for f in installed_py_files} == {"__init__", "__main__", "data"}
89+
90+
installed_pyc_files = destdir.rglob("*.pyc")
91+
assert {f.name.split(".")[0] for f in installed_pyc_files} == {
92+
"__init__",
93+
"__main__",
94+
}

0 commit comments

Comments
 (0)