From 47fcdd1ce3a3da4074524f49707a5c05fd04e227 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sun, 29 Oct 2023 23:07:24 +0100 Subject: [PATCH] feat: Indent generated JSON files This allows easier version control using Git. --- app/generator.py | 4 ++-- app/utils.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/generator.py b/app/generator.py index c57bb8b..409296a 100644 --- a/app/generator.py +++ b/app/generator.py @@ -1,7 +1,7 @@ import json from os.path import join from app import api -from app.utils import get_repository_name, write_json, read_json, create_if_not_exists +from app.utils import get_repository_name, to_json, write_json, read_json, create_if_not_exists from abc import abstractmethod @@ -40,7 +40,7 @@ class ReleaseApi(Api): tag = release["tag"] release_path = join(path, repository_name) - release_json = json.dumps(release) + release_json = to_json(release) create_if_not_exists(release_path) diff --git a/app/utils.py b/app/utils.py index 91f0e85..5b58bdc 100644 --- a/app/utils.py +++ b/app/utils.py @@ -5,10 +5,13 @@ import os def write_json(text: str | dict | list, to, overwrite=True): if not os.path.exists(to) or overwrite: with open(to, "w") as f: - if not isinstance(text, str): - text = json.dumps(text) + text = to_json(text) f.write(text) +def to_json(text: str | dict | list): + if not isinstance(text, str): + text = json.dumps(text, indent=2) + return text def read_json(path, default): if os.path.exists(path):