From b6dd60b6eaf7292fe2f25816a841131c0cab6394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= <hugo@lysator.liu.se> Date: Sun, 21 May 2023 00:11:21 +0200 Subject: [PATCH] minor fixes. --- Makefile | 3 +++ cache.py | 6 ++++-- main.py | 8 +++++--- merge-json.py | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 317a4b4..0327d59 100644 --- a/Makefile +++ b/Makefile @@ -21,3 +21,6 @@ check: test: python -m pytest + +clean: + -rm -r $(CACHE_DIR)/* diff --git a/cache.py b/cache.py index 53be5aa..d46342d 100644 --- a/cache.py +++ b/cache.py @@ -28,10 +28,12 @@ def parse_puppet(s: str) -> dict[str, Any]: hash = hashlib.sha256(s.encode('UTF-8')) digest = hash.hexdigest() if record := r.get(digest): - return json.loads(record) + data = json.loads(record) else: almost_data = parse_puppet_for_real(s) hash = hashlib.sha256(almost_data) r.set(digest, almost_data) data = json.loads(almost_data) - return data + if type(data) != dict: + raise Exception("Weird data returned from puppet parse") + return data diff --git a/main.py b/main.py index 1cf91c2..5e8ca79 100644 --- a/main.py +++ b/main.py @@ -21,9 +21,10 @@ from typing import ( Tuple, ) -HashEntry: TypeAlias = Union[Tuple[Literal['=>'], str, Any], - Tuple[Literal['+>'], str, Any], - Tuple[Literal['splat-hash'], Any]] + +HashEntry: TypeAlias = Union[Tuple[Literal['=>'], str, Any], + Tuple[Literal['+>'], str, Any], + Tuple[Literal['splat-hash'], Any]] match sys.argv: case [_, d, *_]: @@ -38,6 +39,7 @@ data = info param_doc: dict[str, str] = {} + def print_hash(hash: list[HashEntry], indent: int, context: list[str]) -> None: diff --git a/merge-json.py b/merge-json.py index 65831da..0998d88 100755 --- a/merge-json.py +++ b/merge-json.py @@ -38,7 +38,7 @@ def merge_dicts(objects: list[str]) -> dict[Any, list]: return merged -def __main(): +def __main() -> None: import argparse parser = argparse.ArgumentParser() parser.add_argument('--out', action='store') -- GitLab