1111
1212@dataclass
1313class Blueprint :
14- """
15- Represents a reusable blueprint for hierarchical sub-topologies.
14+ """Represents a reusable blueprint for hierarchical sub-topologies.
1615
1716 A blueprint may contain multiple groups of nodes (each can have a node_count
1817 and a name_template), plus adjacency rules describing how those groups connect.
@@ -35,8 +34,7 @@ class Blueprint:
3534
3635@dataclass
3736class DSLExpansionContext :
38- """
39- Carries the blueprint definitions and the final Network instance
37+ """Carries the blueprint definitions and the final Network instance
4038 to be populated during DSL expansion.
4139
4240 Attributes:
@@ -49,8 +47,7 @@ class DSLExpansionContext:
4947
5048
5149def expand_network_dsl (data : Dict [str , Any ]) -> Network :
52- """
53- Expands a combined blueprint + network DSL into a complete Network object.
50+ """Expands a combined blueprint + network DSL into a complete Network object.
5451
5552 Overall flow:
5653 1) Parse "blueprints" into Blueprint objects.
@@ -164,8 +161,7 @@ def _expand_group(
164161 group_def : Dict [str , Any ],
165162 inherited_risk_groups : Set [str ] | None = None ,
166163) -> None :
167- """
168- Expands a single group definition into either:
164+ """Expands a single group definition into either:
169165 - Another blueprint's subgroups, or
170166 - A direct node group (with node_count, etc.),
171167 - Possibly replicating itself if group_name has bracket expansions.
@@ -319,8 +315,7 @@ def _expand_blueprint_adjacency(
319315 adj_def : Dict [str , Any ],
320316 parent_path : str ,
321317) -> None :
322- """
323- Expands adjacency definitions from within a blueprint, using parent_path
318+ """Expands adjacency definitions from within a blueprint, using parent_path
324319 as the local root. This also handles optional expand_vars for repeated adjacency.
325320
326321 Recognized adjacency keys:
@@ -352,8 +347,7 @@ def _expand_blueprint_adjacency(
352347
353348
354349def _expand_adjacency (ctx : DSLExpansionContext , adj_def : Dict [str , Any ]) -> None :
355- """
356- Expands a top-level adjacency definition from 'network.adjacency'. If 'expand_vars'
350+ """Expands a top-level adjacency definition from 'network.adjacency'. If 'expand_vars'
357351 is provided, we expand the source/target as templates repeatedly.
358352
359353 Recognized adjacency keys:
@@ -388,8 +382,7 @@ def _expand_adjacency(ctx: DSLExpansionContext, adj_def: Dict[str, Any]) -> None
388382def _expand_adjacency_with_variables (
389383 ctx : DSLExpansionContext , adj_def : Dict [str , Any ], parent_path : str
390384) -> None :
391- """
392- Handles adjacency expansions when 'expand_vars' is provided.
385+ """Handles adjacency expansions when 'expand_vars' is provided.
393386 We substitute variables into the 'source' and 'target' templates to produce
394387 multiple adjacency expansions. Then each expansion is passed to _expand_adjacency_pattern.
395388
@@ -451,8 +444,7 @@ def _expand_adjacency_pattern(
451444 link_params : Dict [str , Any ],
452445 link_count : int = 1 ,
453446) -> None :
454- """
455- Generates Link objects for the chosen adjacency pattern among matched nodes.
447+ """Generates Link objects for the chosen adjacency pattern among matched nodes.
456448
457449 Supported Patterns:
458450 * "mesh": Connect every source node to every target node
@@ -531,8 +523,7 @@ def _create_link(
531523 link_params : Dict [str , Any ],
532524 link_count : int = 1 ,
533525) -> None :
534- """
535- Creates and adds one or more Links to the network, applying capacity, cost,
526+ """Creates and adds one or more Links to the network, applying capacity, cost,
536527 disabled, risk_groups, and attrs from link_params if present.
537528
538529 Args:
@@ -566,8 +557,7 @@ def _create_link(
566557
567558
568559def _process_direct_nodes (net : Network , network_data : Dict [str , Any ]) -> None :
569- """
570- Processes direct node definitions (network_data["nodes"]) and adds them to the network
560+ """Processes direct node definitions (network_data["nodes"]) and adds them to the network
571561 if they do not already exist. If the node name already exists, we do nothing.
572562
573563 Allowed top-level keys for each node: {"disabled", "attrs", "risk_groups"}.
@@ -609,8 +599,7 @@ def _process_direct_nodes(net: Network, network_data: Dict[str, Any]) -> None:
609599
610600
611601def _process_direct_links (net : Network , network_data : Dict [str , Any ]) -> None :
612- """
613- Processes direct link definitions (network_data["links"]) and adds them to the network.
602+ """Processes direct link definitions (network_data["links"]) and adds them to the network.
614603
615604 Each link dict must contain {"source", "target"} plus optionally
616605 {"link_params", "link_count"}. No other top-level keys allowed.
@@ -653,8 +642,7 @@ def _process_direct_links(net: Network, network_data: Dict[str, Any]) -> None:
653642
654643
655644def _process_link_overrides (net : Network , network_data : Dict [str , Any ]) -> None :
656- """
657- Processes the 'link_overrides' section of the network DSL, updating
645+ """Processes the 'link_overrides' section of the network DSL, updating
658646 existing links with new parameters. Overrides are applied in order if
659647 multiple items match the same link.
660648
@@ -691,8 +679,7 @@ def _process_link_overrides(net: Network, network_data: Dict[str, Any]) -> None:
691679
692680
693681def _process_node_overrides (net : Network , network_data : Dict [str , Any ]) -> None :
694- """
695- Processes the 'node_overrides' section of the network DSL, updating
682+ """Processes the 'node_overrides' section of the network DSL, updating
696683 existing nodes with new attributes in bulk. Overrides are applied in order
697684 if multiple items match the same node.
698685
@@ -740,8 +727,7 @@ def _update_links(
740727 link_params : Dict [str , Any ],
741728 any_direction : bool = True ,
742729) -> None :
743- """
744- Updates all Link objects between nodes matching 'source' and 'target' paths
730+ """Updates all Link objects between nodes matching 'source' and 'target' paths
745731 with new parameters (capacity, cost, disabled, risk_groups, attrs).
746732
747733 If any_direction=True, both (source->target) and (target->source) links
@@ -802,8 +788,7 @@ def _update_nodes(
802788 disabled_val : Any = None ,
803789 risk_groups_val : Any = None ,
804790) -> None :
805- """
806- Updates attributes on all nodes matching a given path pattern.
791+ """Updates attributes on all nodes matching a given path pattern.
807792
808793 - If 'disabled_val' is not None, sets node.disabled to that boolean value.
809794 - If 'risk_groups_val' is not None, *replaces* the node's risk_groups with that new set.
@@ -833,8 +818,7 @@ def _update_nodes(
833818def _apply_parameters (
834819 subgroup_name : str , subgroup_def : Dict [str , Any ], params_overrides : Dict [str , Any ]
835820) -> Dict [str , Any ]:
836- """
837- Applies user-provided parameter overrides to a blueprint subgroup.
821+ """Applies user-provided parameter overrides to a blueprint subgroup.
838822
839823 Example:
840824 If 'spine.node_count' = 6 is in params_overrides,
@@ -864,8 +848,7 @@ def _apply_parameters(
864848def _apply_nested_path (
865849 node_def : Dict [str , Any ], path_parts : List [str ], value : Any
866850) -> None :
867- """
868- Recursively applies a path like ["attrs", "role"] to set node_def["attrs"]["role"] = value.
851+ """Recursively applies a path like ["attrs", "role"] to set node_def["attrs"]["role"] = value.
869852 Creates intermediate dicts as needed.
870853
871854 Args:
@@ -888,8 +871,7 @@ def _apply_nested_path(
888871
889872
890873def _expand_name_patterns (name : str ) -> List [str ]:
891- """
892- Parses and expands bracketed expressions in a group name. For example:
874+ """Parses and expands bracketed expressions in a group name. For example:
893875
894876 "fa[1-3]" -> ["fa1", "fa2", "fa3"]
895877 "dc[1,3,5-6]" -> ["dc1", "dc3", "dc5", "dc6"]
@@ -930,8 +912,7 @@ def _expand_name_patterns(name: str) -> List[str]:
930912
931913
932914def _parse_range_expr (expr : str ) -> List [str ]:
933- """
934- Parses a bracket expression that might have commas, single values, and dash ranges.
915+ """Parses a bracket expression that might have commas, single values, and dash ranges.
935916 For example: "1-3,5,7-9" -> ["1", "2", "3", "5", "7", "8", "9"].
936917
937918 Args:
@@ -955,8 +936,7 @@ def _parse_range_expr(expr: str) -> List[str]:
955936
956937
957938def _join_paths (parent_path : str , rel_path : str ) -> str :
958- """
959- Joins two path segments according to NetGraph's DSL conventions:
939+ """Joins two path segments according to NetGraph's DSL conventions:
960940
961941 - If rel_path starts with '/', we strip the leading slash and treat it as
962942 appended to parent_path if parent_path is not empty.
@@ -983,8 +963,7 @@ def _join_paths(parent_path: str, rel_path: str) -> str:
983963def _check_no_extra_keys (
984964 data_dict : Dict [str , Any ], allowed : set [str ], context : str
985965) -> None :
986- """
987- Checks that data_dict only has keys in 'allowed'. Raises ValueError if not.
966+ """Checks that data_dict only has keys in 'allowed'. Raises ValueError if not.
988967
989968 Args:
990969 data_dict (Dict[str, Any]): The dict to check.
@@ -1000,8 +979,7 @@ def _check_no_extra_keys(
1000979
1001980
1002981def _check_adjacency_keys (adj_def : Dict [str , Any ], context : str ) -> None :
1003- """
1004- Ensures adjacency definitions only contain recognized keys.
982+ """Ensures adjacency definitions only contain recognized keys.
1005983
1006984 Recognized adjacency keys are:
1007985 {"source", "target", "pattern", "link_count", "link_params",
@@ -1025,9 +1003,8 @@ def _check_adjacency_keys(adj_def: Dict[str, Any], context: str) -> None:
10251003
10261004
10271005def _check_link_params (link_params : Dict [str , Any ], context : str ) -> None :
1028- """
1029- Checks that link_params only has recognized keys:
1030- {"capacity", "cost", "disabled", "risk_groups", "attrs"}.
1006+ """Checks that link_params only has recognized keys:
1007+ {"capacity", "cost", "disabled", "risk_groups", "attrs"}.
10311008 """
10321009 recognized = {"capacity" , "cost" , "disabled" , "risk_groups" , "attrs" }
10331010 extra = set (link_params .keys ()) - recognized
0 commit comments