Skip to content

Commit

Permalink
Add an option for disabling digest verification
Browse files Browse the repository at this point in the history
Closes #6.
  • Loading branch information
jwodder committed Nov 1, 2023
1 parent 6a09320 commit 2561758
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ v2.0.0 (in development)
- The `.file` property in wheel inspection results (containing the file's
size and digest) has been removed
- `RECORD` entries with negative sizes are now detected & errored on earlier
- Gave `inspect_wheel()` a `verify_files` option for controlling verification
of files' digests
- Gave the CLI command a `--verify-files`/`--no-verify-files` option for
controlling verification of files' digests


v1.7.1 (2022-04-08)
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ python_requires = ~=3.7
install_requires =
attrs >= 20.1.0
cached-property ~= 1.5; python_version < "3.8"
click >= 8.0
entry-points-txt ~= 0.1.0
headerparser ~= 0.4.0
packaging >= 17.1
Expand Down
25 changes: 18 additions & 7 deletions src/wheel_inspect/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import json
import os.path
import sys
from pathlib import Path
from typing import Sequence
import click
from .inspecting import inspect_dist_info_dir, inspect_wheel


def main() -> None:
for path in sys.argv[1:]:
if os.path.isdir(path):
about = inspect_dist_info_dir(path)
@click.command()
@click.option(
"--verify-files/--no-verify-files",
default=True,
help=(
"Verify the digests of files listed inside wheels' RECORDs"
" [default: --verify-files]"
),
)
@click.argument("paths", type=click.Path(exists=True, path_type=Path))
def main(paths: Sequence[Path], verify_files: bool) -> None:
for p in paths:
if p.is_dir():
about = inspect_dist_info_dir(p)
else:
about = inspect_wheel(path)
about = inspect_wheel(p, verify_files=verify_files)
print(json.dumps(about, sort_keys=True, indent=4))


Expand Down
12 changes: 8 additions & 4 deletions src/wheel_inspect/inspecting.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def jsonify_entry_points(epset: EntryPointSet) -> Dict[str, Any]:
EXTRA_DIST_INFO_FILES = ["dependency_links", "namespace_packages", "top_level"]


def inspect(obj: DistInfoProvider) -> Dict[str, Any]:
def inspect(obj: DistInfoProvider, verify_files: bool = True) -> Dict[str, Any]:
about = obj.basic_metadata()
about["dist_info"] = {}
about["valid"] = True
Expand All @@ -84,7 +84,7 @@ def inspect(obj: DistInfoProvider) -> Dict[str, Any]:
about["dist_info"]["record"] = {
k: v.for_json() if v is not None else None for k, v in record.items()
}
if isinstance(obj, WheelFile):
if isinstance(obj, WheelFile) and verify_files:
try:
obj.verify_record()
except errors.WheelValidationError as e:
Expand Down Expand Up @@ -173,13 +173,17 @@ def inspect(obj: DistInfoProvider) -> Dict[str, Any]:
return about


def inspect_wheel(path: AnyPath) -> Dict[str, Any]:
def inspect_wheel(path: AnyPath, verify_files: bool = True) -> Dict[str, Any]:
"""
Examine the Python wheel at the given path and return various information
about the contents within as a JSON-serializable `dict`
:param bool verify_files: If true, the files within the wheel will have
their digests calculated in order to verify the digests & sizes listed
in the wheel's :file:`RECORD`
"""
with WheelFile.from_path(path) as wf:
return inspect(wf)
return inspect(wf, verify_files=verify_files)


def inspect_dist_info_dir(path: AnyPath) -> Dict[str, Any]:
Expand Down

0 comments on commit 2561758

Please sign in to comment.