From ccb0bbdd9e9a218c552a29017fdd30304d504f52 Mon Sep 17 00:00:00 2001 From: avdudchenko <33663878+avdudchenko@users.noreply.github.com> Date: Mon, 10 Nov 2025 22:30:48 -0500 Subject: [PATCH 1/2] Update parse_json.py --- pype_schema/parse_json.py | 41 +++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/pype_schema/parse_json.py b/pype_schema/parse_json.py index fa08a95..03f8f31 100644 --- a/pype_schema/parse_json.py +++ b/pype_schema/parse_json.py @@ -12,13 +12,15 @@ from . import utils -class JSONParser: +class NetworkParser: """A parser to convert a JSON file into a `Network` object Parameters ---------- - path : str - path to the JSON file to load + config_dict : dict + dictionary that defines network + network_name: str + name of the network being parsed Attributes ---------- @@ -32,14 +34,12 @@ class JSONParser: Python representation of the JSON file """ - def __init__(self, path): - f = open(path) - self.path = path - self.config = json.load(f) + def __init__(self, config_dict, network_name): + self.network_name = network_name + self.config = config_dict self.network_obj = node.Network( "ParentNetwork", None, None, tags={}, nodes={}, connections={} ) - f.close() def initialize_network(self, verbose=False): """Converts a dictionary into a `Network` object @@ -58,7 +58,9 @@ def initialize_network(self, verbose=False): for node_id in self.config["nodes"]: # check that node exists in dictionary (NameError) if node_id not in self.config: - raise NameError("Node " + node_id + " not found in " + self.path) + raise NameError( + "Node " + node_id + " not found in " + self.network_name + ) if verbose: print(f"Initializing network, adding node {node_id}...") self.network_obj.add_node(self.create_node(node_id)) @@ -67,7 +69,9 @@ def initialize_network(self, verbose=False): print(f"Initializing network, adding connection {connection_id}...") # check that connection exists in dictionary (NameError) if connection_id not in self.config: - raise NameError(f"Connection {connection_id} not found in {self.path}") + raise NameError( + f"Connection {connection_id} not found in {self.network_name}" + ) self.network_obj.add_connection( self.create_connection(connection_id, self.network_obj) ) @@ -210,7 +214,9 @@ def merge_network(self, old_network, inplace=False): ) for node_id in self.config["nodes"]: if node_id not in self.config: - raise NameError("Node " + node_id + " not found in " + self.path) + raise NameError( + "Node " + node_id + " not found in " + self.network_name + ) # delete existing node before creating the new one if necessary elif hasattr(old_network, "nodes") and node_id in old_network.nodes.keys(): old_network.remove_node(node_id) @@ -218,7 +224,7 @@ def merge_network(self, old_network, inplace=False): for connection_id in self.config["connections"]: if connection_id not in self.config: raise NameError( - "Connection " + connection_id + " not found in " + self.path + "Connection " + connection_id + " not found in " + self.network_name ) # delete existing connection before creating the new one if necessary if ( @@ -2219,3 +2225,14 @@ def to_json(network, file_path=None, indent=4, verbose=False): json.dump(result, file, indent=indent) return result + + +class JSONParser(NetworkParser): + """A parser to convert a JSON file into a `Network` object""" + + def __init__(self, path): + f = open(path) + path = path + config = json.load(f) + f.close() + super().__init__(config, path) From 29d9d4b8319babb391059369ec893f14e06d610c Mon Sep 17 00:00:00 2001 From: avdudchenko <33663878+avdudchenko@users.noreply.github.com> Date: Mon, 10 Nov 2025 22:32:42 -0500 Subject: [PATCH 2/2] Update parse_json.py --- pype_schema/parse_json.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/pype_schema/parse_json.py b/pype_schema/parse_json.py index 03f8f31..243f38d 100644 --- a/pype_schema/parse_json.py +++ b/pype_schema/parse_json.py @@ -13,7 +13,7 @@ class NetworkParser: - """A parser to convert a JSON file into a `Network` object + """A parser to convert a dict file into a `Network` object Parameters ---------- @@ -2228,9 +2228,29 @@ def to_json(network, file_path=None, indent=4, verbose=False): class JSONParser(NetworkParser): - """A parser to convert a JSON file into a `Network` object""" + """A parser to convert a JSON file into a `Network` object + + Parameters + ---------- + config_dict : dict + dictionary that defines network + network_name: str + name of the network being parsed + + Attributes + ---------- + path : str + path to the JSON file to load + + config : dict + dictionary with the contents the JSON file + + network_obj : Network + Python representation of the JSON file + """ def __init__(self, path): + f = open(path) path = path config = json.load(f)