From 47530f7830ef83a1dedfca988225aade642ce2ba Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson <oscar.gustafsson@gmail.com> Date: Mon, 23 Jan 2023 21:45:13 +0100 Subject: [PATCH] Fix string formatting --- b_asic/GUI/properties_window.py | 8 ++++---- b_asic/GUI/simulate_sfg_window.py | 4 ++-- b_asic/operation.py | 4 ++-- b_asic/save_load_structure.py | 6 +----- b_asic/signal_flow_graph.py | 17 ++++++++--------- 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/b_asic/GUI/properties_window.py b/b_asic/GUI/properties_window.py index 490d4b70..84576d8b 100644 --- a/b_asic/GUI/properties_window.py +++ b/b_asic/GUI/properties_window.py @@ -80,7 +80,7 @@ class PropertiesWindow(QDialog): x += 1 y = 0 - input_label = QLabel("in" + str(i)) + input_label = QLabel(f"in{i}") input_layout.addWidget(input_label) input_value = QLineEdit() try: @@ -93,7 +93,7 @@ class PropertiesWindow(QDialog): int_valid.setBottom(-1) input_value.setValidator(int_valid) input_value.setFixedWidth(50) - self.latency_fields["in" + str(i)] = input_value + self.latency_fields[f"in{i}"] = input_value input_layout.addWidget(input_value) input_layout.addStretch() input_layout.setSpacing(10) @@ -119,7 +119,7 @@ class PropertiesWindow(QDialog): x += 1 y = 0 - input_label = QLabel("out" + str(i)) + input_label = QLabel(f"out{i}") input_layout.addWidget(input_label) input_value = QLineEdit() try: @@ -132,7 +132,7 @@ class PropertiesWindow(QDialog): int_valid.setBottom(-1) input_value.setValidator(int_valid) input_value.setFixedWidth(50) - self.latency_fields["out" + str(i)] = input_value + self.latency_fields[f"out{i}"] = input_value input_layout.addWidget(input_value) input_layout.addStretch() input_layout.setSpacing(10) diff --git a/b_asic/GUI/simulate_sfg_window.py b/b_asic/GUI/simulate_sfg_window.py index ab91d5d7..792132db 100644 --- a/b_asic/GUI/simulate_sfg_window.py +++ b/b_asic/GUI/simulate_sfg_window.py @@ -80,10 +80,10 @@ class SimulateSFGWindow(QDialog): x += 1 y = 0 - input_label = QLabel("in" + str(i)) + input_label = QLabel(f"in{i}") input_layout.addWidget(input_label) input_value = QLineEdit() - input_value.setPlaceholderText("e.g 0, 0, 0") + input_value.setPlaceholderText("e.g. 0, 0, 0") input_value.setFixedWidth(100) input_layout.addWidget(input_value) input_layout.addStretch() diff --git a/b_asic/operation.py b/b_asic/operation.py index 18f0b83f..f26ff285 100644 --- a/b_asic/operation.py +++ b/b_asic/operation.py @@ -877,10 +877,10 @@ class AbstractOperation(Operation, AbstractGraphComponent): latency_offsets = {} for i, inp in enumerate(self.inputs): - latency_offsets["in" + str(i)] = inp.latency_offset + latency_offsets[f"in{i}"] = inp.latency_offset for i, outp in enumerate(self.outputs): - latency_offsets["out" + str(i)] = outp.latency_offset + latency_offsets[f"out{i}"] = outp.latency_offset return latency_offsets diff --git a/b_asic/save_load_structure.py b/b_asic/save_load_structure.py index b37c1692..802afa6b 100644 --- a/b_asic/save_load_structure.py +++ b/b_asic/save_load_structure.py @@ -89,11 +89,7 @@ def sfg_to_python(sfg: SFG, counter: int = 0, suffix: str = None) -> str: "[" + ", ".join(op.graph_id for op in sfg.output_operations) + "]" ) sfg_name = ( - sfg.name - if sfg.name - else "sfg" + str(counter) - if counter > 0 - else "sfg" + sfg.name if sfg.name else f"sfg{counter}" if counter > 0 else "sfg" ) sfg_name_var = sfg_name.replace(" ", "_") result += ( diff --git a/b_asic/signal_flow_graph.py b/b_asic/signal_flow_graph.py index 4a88a098..ab8d096a 100644 --- a/b_asic/signal_flow_graph.py +++ b/b_asic/signal_flow_graph.py @@ -289,7 +289,7 @@ class SFG(AbstractOperation): string_io.write(line) for operation in self.get_operations_topological_order(): - string_io.write(str(operation) + "\n") + string_io.write(f"{operation}\n") string_io.write(line) @@ -720,16 +720,15 @@ class SFG(AbstractOperation): # Creates nodes for each output port in the precedence list for i in range(len(p_list)): ports = p_list[i] - with pg.subgraph(name="cluster_" + str(i)) as sub: - sub.attr(label="N" + str(i + 1)) + with pg.subgraph(name=f"cluster_{i}") as sub: + sub.attr(label=f"N{i+1}") for port in ports: + portstr = f"{port.operation.graph_id}.{port.index}" if port.operation.output_count > 1: - sub.node( - port.operation.graph_id + "." + str(port.index) - ) + sub.node(portstr) else: sub.node( - port.operation.graph_id + "." + str(port.index), + portstr, label=port.operation.graph_id, ) # Creates edges for each output port and creates nodes for each operation and edges for them as well @@ -747,7 +746,7 @@ class SFG(AbstractOperation): else: dest_node = signal.destination.operation.graph_id dest_label = signal.destination.operation.graph_id - node_node = port.operation.graph_id + "." + str(port.index) + node_node = f"{port.operation.graph_id}.{port.index}" pg.edge(node_node, dest_node) pg.node(dest_node, label=dest_label, shape="square") if port.operation.type_name() == Delay.type_name(): @@ -755,7 +754,7 @@ class SFG(AbstractOperation): else: source_node = port.operation.graph_id source_label = port.operation.graph_id - node_node = port.operation.graph_id + "." + str(port.index) + node_node = f"{port.operation.graph_id}.{port.index}" pg.edge(source_node, node_node) pg.node(source_node, label=source_label, shape="square") -- GitLab