From 2eb3633bcb45b954acaa8d00bf39d5583d65397e Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Mon, 18 Mar 2024 13:26:13 -0400 Subject: [PATCH] `json.dumps(indent=2)` (#17714) --- chia/_tests/build-job-matrix.py | 2 +- chia/_tests/environments/wallet.py | 2 +- chia/clvm/spend_sim.py | 2 +- chia/cmds/data_funcs.py | 46 +++++++++++++++--------------- chia/cmds/rpc.py | 4 +-- chia/rpc/data_layer_rpc_util.py | 4 +-- installhelper.py | 2 +- tools/manage_clvm.py | 2 +- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/chia/_tests/build-job-matrix.py b/chia/_tests/build-job-matrix.py index 87348b7a83..9bc6080875 100644 --- a/chia/_tests/build-job-matrix.py +++ b/chia/_tests/build-job-matrix.py @@ -198,7 +198,7 @@ if len(messages) > 0: configuration_json = json.dumps(configuration) -for line in json.dumps(configuration, indent=4).splitlines(): +for line in json.dumps(configuration, indent=2).splitlines(): logging.info(line) print(f"{configuration_json}") diff --git a/chia/_tests/environments/wallet.py b/chia/_tests/environments/wallet.py index 4d1bf9e1b9..14fc2141c4 100644 --- a/chia/_tests/environments/wallet.py +++ b/chia/_tests/environments/wallet.py @@ -31,7 +31,7 @@ class BalanceCheckingError(Exception): self.errors = errors def __repr__(self) -> str: - return json.dumps(self.errors, indent=4) + return json.dumps(self.errors, indent=2) def __str__(self) -> str: return self.__repr__() diff --git a/chia/clvm/spend_sim.py b/chia/clvm/spend_sim.py index be7f9a1a58..ea6654ac76 100644 --- a/chia/clvm/spend_sim.py +++ b/chia/clvm/spend_sim.py @@ -86,7 +86,7 @@ class CostLogger: "standard cost": self.cost_dict, "no puzzle reveals": self.cost_dict_no_puzs, } - return json.dumps(merged_dict, indent=4) + return json.dumps(merged_dict, indent=2) @streamable diff --git a/chia/cmds/data_funcs.py b/chia/cmds/data_funcs.py index cbcbb5e40b..3beb16aa01 100644 --- a/chia/cmds/data_funcs.py +++ b/chia/cmds/data_funcs.py @@ -46,7 +46,7 @@ async def create_data_store_cmd( final_fee = None if fee is None else uint64(int(Decimal(fee) * units["chia"])) async with get_client(rpc_port=rpc_port, fingerprint=fingerprint) as (client, _): res = await client.create_data_store(fee=final_fee, verbose=verbose) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) async def get_value_cmd( @@ -61,7 +61,7 @@ async def get_value_cmd( root_hash_bytes = None if root_hash is None else bytes32.from_hexstr(root_hash) async with get_client(rpc_port=rpc_port, fingerprint=fingerprint) as (client, _): res = await client.get_value(store_id=store_id_bytes, key=key_bytes, root_hash=root_hash_bytes) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) async def update_data_store_cmd( @@ -84,7 +84,7 @@ async def update_data_store_cmd( fee=final_fee, submit_on_chain=submit_on_chain, ) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) return res @@ -104,7 +104,7 @@ async def submit_pending_root_cmd( store_id=store_id_bytes, fee=final_fee, ) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) return res @@ -125,7 +125,7 @@ async def get_keys_cmd( res = await client.get_keys( store_id=store_id_bytes, root_hash=root_hash_bytes, page=page, max_page_size=max_page_size ) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) return res @@ -146,7 +146,7 @@ async def get_keys_values_cmd( res = await client.get_keys_values( store_id=store_id_bytes, root_hash=root_hash_bytes, page=page, max_page_size=max_page_size ) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) return res @@ -159,7 +159,7 @@ async def get_root_cmd( store_id_bytes = bytes32.from_hexstr(store_id) async with get_client(rpc_port=rpc_port, fingerprint=fingerprint) as (client, _): res = await client.get_root(store_id=store_id_bytes) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) async def subscribe_cmd( @@ -171,7 +171,7 @@ async def subscribe_cmd( store_id_bytes = bytes32.from_hexstr(store_id) async with get_client(rpc_port=rpc_port, fingerprint=fingerprint) as (client, _): res = await client.subscribe(store_id=store_id_bytes, urls=urls) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) async def unsubscribe_cmd( @@ -183,7 +183,7 @@ async def unsubscribe_cmd( store_id_bytes = bytes32.from_hexstr(store_id) async with get_client(rpc_port=rpc_port, fingerprint=fingerprint) as (client, _): res = await client.unsubscribe(store_id=store_id_bytes, retain=retain) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) async def remove_subscriptions_cmd( @@ -195,7 +195,7 @@ async def remove_subscriptions_cmd( store_id_bytes = bytes32.from_hexstr(store_id) async with get_client(rpc_port=rpc_port, fingerprint=fingerprint) as (client, _): res = await client.remove_subscriptions(store_id=store_id_bytes, urls=urls) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) async def get_kv_diff_cmd( @@ -217,7 +217,7 @@ async def get_kv_diff_cmd( res = await client.get_kv_diff( store_id=store_id_bytes, hash_1=hash_1_bytes, hash_2=hash_2_bytes, page=page, max_page_size=max_page_size ) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) return res @@ -230,7 +230,7 @@ async def get_root_history_cmd( store_id_bytes = bytes32.from_hexstr(store_id) async with get_client(rpc_port=rpc_port, fingerprint=fingerprint) as (client, _): res = await client.get_root_history(store_id=store_id_bytes) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) async def add_missing_files_cmd( @@ -246,7 +246,7 @@ async def add_missing_files_cmd( overwrite=overwrite, foldername=foldername, ) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) async def add_mirror_cmd( @@ -266,7 +266,7 @@ async def add_mirror_cmd( amount=amount, fee=final_fee, ) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) async def delete_mirror_cmd( @@ -282,7 +282,7 @@ async def delete_mirror_cmd( coin_id=coin_id_bytes, fee=final_fee, ) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) async def get_mirrors_cmd( @@ -293,7 +293,7 @@ async def get_mirrors_cmd( store_id_bytes = bytes32.from_hexstr(store_id) async with get_client(rpc_port=rpc_port, fingerprint=fingerprint) as (client, _): res = await client.get_mirrors(store_id=store_id_bytes) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) async def get_subscriptions_cmd( @@ -302,7 +302,7 @@ async def get_subscriptions_cmd( ) -> None: async with get_client(rpc_port=rpc_port, fingerprint=fingerprint) as (client, _): res = await client.get_subscriptions() - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) async def get_owned_stores_cmd( @@ -311,7 +311,7 @@ async def get_owned_stores_cmd( ) -> None: async with get_client(rpc_port=rpc_port, fingerprint=fingerprint) as (client, _): res = await client.get_owned_stores() - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) async def get_sync_status_cmd( @@ -322,13 +322,13 @@ async def get_sync_status_cmd( store_id_bytes = bytes32.from_hexstr(store_id) async with get_client(rpc_port=rpc_port, fingerprint=fingerprint) as (client, _): res = await client.get_sync_status(store_id=store_id_bytes) - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) async def check_plugins_cmd(rpc_port: Optional[int]) -> None: async with get_client(rpc_port=rpc_port) as (client, _): res = await client.check_plugins() - print(json.dumps(res, indent=4, sort_keys=True)) + print(json.dumps(res, indent=2, sort_keys=True)) async def clear_pending_roots( @@ -339,7 +339,7 @@ async def clear_pending_roots( ) -> Dict[str, Any]: async with get_client(rpc_port=rpc_port, fingerprint=fingerprint, root_path=root_path) as (client, _): result = await client.clear_pending_roots(store_id=store_id) - print(json.dumps(result, indent=4, sort_keys=True)) + print(json.dumps(result, indent=2, sort_keys=True)) return result @@ -354,7 +354,7 @@ async def get_proof_cmd( result = dict() async with get_client(rpc_port=rpc_port, fingerprint=fingerprint, root_path=root_path) as (client, _): result = await client.get_proof(store_id=store_id, keys=[hexstr_to_bytes(key) for key in key_strings]) - print(json.dumps(result, indent=4, sort_keys=True)) + print(json.dumps(result, indent=2, sort_keys=True)) return result @@ -368,6 +368,6 @@ async def verify_proof_cmd( result = dict() async with get_client(rpc_port=rpc_port, fingerprint=fingerprint, root_path=root_path) as (client, _): result = await client.verify_proof(proof=proof) - print(json.dumps(result, indent=4, sort_keys=True)) + print(json.dumps(result, indent=2, sort_keys=True)) return result diff --git a/chia/cmds/rpc.py b/chia/cmds/rpc.py index 376411ccf1..95929378f7 100644 --- a/chia/cmds/rpc.py +++ b/chia/cmds/rpc.py @@ -78,7 +78,7 @@ async def call_daemon_command( def print_result(json_dict: Dict[str, Any]) -> None: - print(json.dumps(json_dict, indent=4, sort_keys=True)) + print(json.dumps(json_dict, indent=2, sort_keys=True)) def get_routes(service: str, config: Dict[str, Any], quiet: bool = False) -> Dict[str, Any]: @@ -126,7 +126,7 @@ def status_cmd(json_output: bool) -> None: if json_output: # If --json-output option is used, print the status data as JSON - print(json.dumps(status_data, indent=4)) + print(json.dumps(status_data, indent=2)) else: print("╭──────────────┬───────────╮") print_row("SERVICE", "STATUS") diff --git a/chia/rpc/data_layer_rpc_util.py b/chia/rpc/data_layer_rpc_util.py index 4991524b04..d1f7413c58 100644 --- a/chia/rpc/data_layer_rpc_util.py +++ b/chia/rpc/data_layer_rpc_util.py @@ -47,12 +47,12 @@ def marshal() -> RouteDecorator: async def wrapper(self: object, request: Dict[str, object]) -> Dict[str, object]: # import json # name = route.__name__ - # print(f"\n ==== {name} request.json\n{json.dumps(request, indent=4)}") + # print(f"\n ==== {name} request.json\n{json.dumps(request, indent=2)}") unmarshalled_request = request_class.unmarshal(request) response = await route(self, request=unmarshalled_request) marshalled_response = response.marshal() - # print(f"\n ==== {name} response.json\n{json.dumps(marshalled_response, indent=4)}") + # print(f"\n ==== {name} response.json\n{json.dumps(marshalled_response, indent=2)}") return marshalled_response diff --git a/installhelper.py b/installhelper.py index fa7067851b..552f2a844c 100644 --- a/installhelper.py +++ b/installhelper.py @@ -67,7 +67,7 @@ def update_version(package_json_path: str): data["version"] = get_chia_version() with open(package_json_path, "w") as w: - json.dump(data, indent=4, fp=w) + json.dump(data, indent=2, fp=w) if __name__ == "__main__": diff --git a/tools/manage_clvm.py b/tools/manage_clvm.py index 45b68de857..d69933e31f 100644 --- a/tools/manage_clvm.py +++ b/tools/manage_clvm.py @@ -98,7 +98,7 @@ def load_cache(file: typing.IO[str]) -> Cache: def dump_cache(cache: Cache, file: typing.IO[str]) -> None: - json.dump(cache, file, indent=4) + json.dump(cache, file, indent=2) def generate_hash_bytes(hex_bytes: bytes) -> bytes32: