Skip to content

Commit

Permalink
externaldata: Error cleanly when source is missing required checksum
Browse files Browse the repository at this point in the history
See #421
  • Loading branch information
bbhtt committed May 29, 2024
1 parent 6bef8dd commit 0863ed6
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib/externaldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,23 @@ def from_source(
if not source.get("url"):
raise SourceUnsupported('Data is not external: no "url" property')

if source.get("url"):

if (
source.get("type") == ExternalBase.Type.EXTRA_DATA
and "sha256" not in source.keys()
):
raise SourceLoadError("Extra data is missing SHA256 checksum")

if source.get("type") in (
ExternalBase.Type.FILE,
ExternalBase.Type.ARCHIVE,
):
if not any(
k in source.keys() for k in ("md5", "sha1", "sha256", "sha512")
):
raise SourceLoadError("Data is missing checksum")

# FIXME: https://github.com/python/mypy/issues/9282
return super().from_source(source_path, source, module) # type: ignore

Expand Down

0 comments on commit 0863ed6

Please sign in to comment.