mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-24 13:20:19 +08:00
Use fstrings instead of '%' formatting syntax
This commit is contained in:
parent
03394ace8c
commit
a0bf532558
@ -269,12 +269,9 @@ class LRUCache(BasicCache):
|
|||||||
self.generation += 1
|
self.generation += 1
|
||||||
for node_id in node_ids:
|
for node_id in node_ids:
|
||||||
self._mark_used(node_id)
|
self._mark_used(node_id)
|
||||||
print("LRUCache: Now at generation %d" % self.generation)
|
|
||||||
|
|
||||||
def clean_unused(self):
|
def clean_unused(self):
|
||||||
print("LRUCache: Cleaning unused. Current size: %d/%d" % (len(self.cache), self.max_size))
|
|
||||||
while len(self.cache) > self.max_size and self.min_generation < self.generation:
|
while len(self.cache) > self.max_size and self.min_generation < self.generation:
|
||||||
print("LRUCache: Evicting generation %d" % self.min_generation)
|
|
||||||
self.min_generation += 1
|
self.min_generation += 1
|
||||||
to_remove = [key for key in self.cache if self.used_generation[key] < self.min_generation]
|
to_remove = [key for key in self.cache if self.used_generation[key] < self.min_generation]
|
||||||
for key in to_remove:
|
for key in to_remove:
|
||||||
|
|||||||
@ -76,10 +76,10 @@ class TopologicalSort:
|
|||||||
def make_input_strong_link(self, to_node_id, to_input):
|
def make_input_strong_link(self, to_node_id, to_input):
|
||||||
inputs = self.dynprompt.get_node(to_node_id)["inputs"]
|
inputs = self.dynprompt.get_node(to_node_id)["inputs"]
|
||||||
if to_input not in inputs:
|
if to_input not in inputs:
|
||||||
raise Exception("Node %s says it needs input %s, but there is no input to that node at all" % (to_node_id, to_input))
|
raise Exception(f"Node {to_node_id} says it needs input {to_input}, but there is no input to that node at all")
|
||||||
value = inputs[to_input]
|
value = inputs[to_input]
|
||||||
if not is_link(value):
|
if not is_link(value):
|
||||||
raise Exception("Node %s says it needs input %s, but that value is a constant" % (to_node_id, to_input))
|
raise Exception(f"Node {to_node_id} says it needs input {to_input}, but that value is a constant")
|
||||||
from_node_id, from_socket = value
|
from_node_id, from_socket = value
|
||||||
self.add_strong_link(from_node_id, from_socket, to_node_id)
|
self.add_strong_link(from_node_id, from_socket, to_node_id)
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,7 @@ class GraphBuilder:
|
|||||||
call_index = GraphBuilder._default_prefix_call_index
|
call_index = GraphBuilder._default_prefix_call_index
|
||||||
if graph_index is None:
|
if graph_index is None:
|
||||||
graph_index = GraphBuilder._default_prefix_graph_index
|
graph_index = GraphBuilder._default_prefix_graph_index
|
||||||
result = "%s.%d.%d." % (root, call_index, graph_index)
|
result = f"{root}.{call_index}.{graph_index}."
|
||||||
GraphBuilder._default_prefix_graph_index += 1
|
GraphBuilder._default_prefix_graph_index += 1
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
@ -299,7 +299,7 @@ def execute(server, dynprompt, caches, current_item, extra_data, executed, promp
|
|||||||
"node_type": class_type,
|
"node_type": class_type,
|
||||||
"executed": list(executed),
|
"executed": list(executed),
|
||||||
|
|
||||||
"exception_message": "Execution Blocked: %s" % block.message,
|
"exception_message": f"Execution Blocked: {block.message}",
|
||||||
"exception_type": "ExecutionBlocked",
|
"exception_type": "ExecutionBlocked",
|
||||||
"traceback": [],
|
"traceback": [],
|
||||||
"current_inputs": [],
|
"current_inputs": [],
|
||||||
@ -337,7 +337,7 @@ def execute(server, dynprompt, caches, current_item, extra_data, executed, promp
|
|||||||
# Check for conflicts
|
# Check for conflicts
|
||||||
for node_id in new_graph.keys():
|
for node_id in new_graph.keys():
|
||||||
if dynprompt.get_node(node_id) is not None:
|
if dynprompt.get_node(node_id) is not None:
|
||||||
raise Exception("Attempt to add duplicate node %s. Ensure node ids are unique and deterministic or use graph_utils.GraphBuilder." % node_id)
|
raise Exception(f"Attempt to add duplicate node {node_id}. Ensure node ids are unique and deterministic or use graph_utils.GraphBuilder.")
|
||||||
for node_id, node_info in new_graph.items():
|
for node_id, node_info in new_graph.items():
|
||||||
new_node_ids.append(node_id)
|
new_node_ids.append(node_id)
|
||||||
display_id = node_info.get("override_display_id", unique_id)
|
display_id = node_info.get("override_display_id", unique_id)
|
||||||
|
|||||||
@ -18,11 +18,11 @@ class TestWhileLoopOpen:
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for i in range(NUM_FLOW_SOCKETS):
|
for i in range(NUM_FLOW_SOCKETS):
|
||||||
inputs["optional"]["initial_value%d" % i] = ("*",)
|
inputs["optional"][f"initial_value{i}"] = ("*",)
|
||||||
return inputs
|
return inputs
|
||||||
|
|
||||||
RETURN_TYPES = tuple(["FLOW_CONTROL"] + ["*"] * NUM_FLOW_SOCKETS)
|
RETURN_TYPES = tuple(["FLOW_CONTROL"] + ["*"] * NUM_FLOW_SOCKETS)
|
||||||
RETURN_NAMES = tuple(["FLOW_CONTROL"] + ["value%d" % i for i in range(NUM_FLOW_SOCKETS)])
|
RETURN_NAMES = tuple(["FLOW_CONTROL"] + [f"value{i}" for i in range(NUM_FLOW_SOCKETS)])
|
||||||
FUNCTION = "while_loop_open"
|
FUNCTION = "while_loop_open"
|
||||||
|
|
||||||
CATEGORY = "Testing/Flow"
|
CATEGORY = "Testing/Flow"
|
||||||
@ -30,7 +30,7 @@ class TestWhileLoopOpen:
|
|||||||
def while_loop_open(self, condition, **kwargs):
|
def while_loop_open(self, condition, **kwargs):
|
||||||
values = []
|
values = []
|
||||||
for i in range(NUM_FLOW_SOCKETS):
|
for i in range(NUM_FLOW_SOCKETS):
|
||||||
values.append(kwargs.get("initial_value%d" % i, None))
|
values.append(kwargs.get(f"initial_value{i}", None))
|
||||||
return tuple(["stub"] + values)
|
return tuple(["stub"] + values)
|
||||||
|
|
||||||
@VariantSupport()
|
@VariantSupport()
|
||||||
@ -53,11 +53,11 @@ class TestWhileLoopClose:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i in range(NUM_FLOW_SOCKETS):
|
for i in range(NUM_FLOW_SOCKETS):
|
||||||
inputs["optional"]["initial_value%d" % i] = ("*",)
|
inputs["optional"][f"initial_value{i}"] = ("*",)
|
||||||
return inputs
|
return inputs
|
||||||
|
|
||||||
RETURN_TYPES = tuple(["*"] * NUM_FLOW_SOCKETS)
|
RETURN_TYPES = tuple(["*"] * NUM_FLOW_SOCKETS)
|
||||||
RETURN_NAMES = tuple(["value%d" % i for i in range(NUM_FLOW_SOCKETS)])
|
RETURN_NAMES = tuple([f"value{i}" for i in range(NUM_FLOW_SOCKETS)])
|
||||||
FUNCTION = "while_loop_close"
|
FUNCTION = "while_loop_close"
|
||||||
|
|
||||||
CATEGORY = "Testing/Flow"
|
CATEGORY = "Testing/Flow"
|
||||||
@ -89,7 +89,7 @@ class TestWhileLoopClose:
|
|||||||
# We're done with the loop
|
# We're done with the loop
|
||||||
values = []
|
values = []
|
||||||
for i in range(NUM_FLOW_SOCKETS):
|
for i in range(NUM_FLOW_SOCKETS):
|
||||||
values.append(kwargs.get("initial_value%d" % i, None))
|
values.append(kwargs.get(f"initial_value{i}", None))
|
||||||
return tuple(values)
|
return tuple(values)
|
||||||
|
|
||||||
# We want to loop
|
# We want to loop
|
||||||
@ -124,7 +124,7 @@ class TestWhileLoopClose:
|
|||||||
new_open = graph.lookup_node(open_node)
|
new_open = graph.lookup_node(open_node)
|
||||||
assert new_open is not None
|
assert new_open is not None
|
||||||
for i in range(NUM_FLOW_SOCKETS):
|
for i in range(NUM_FLOW_SOCKETS):
|
||||||
key = "initial_value%d" % i
|
key = f"initial_value{i}"
|
||||||
new_open.set_input(key, kwargs.get(key, None))
|
new_open.set_input(key, kwargs.get(key, None))
|
||||||
my_clone = graph.lookup_node("Recurse")
|
my_clone = graph.lookup_node("Recurse")
|
||||||
assert my_clone is not None
|
assert my_clone is not None
|
||||||
|
|||||||
@ -242,7 +242,7 @@ class TestForLoopOpen:
|
|||||||
"remaining": ("INT", {"default": 1, "min": 0, "max": 100000, "step": 1}),
|
"remaining": ("INT", {"default": 1, "min": 0, "max": 100000, "step": 1}),
|
||||||
},
|
},
|
||||||
"optional": {
|
"optional": {
|
||||||
"initial_value%d" % i: ("*",) for i in range(1, NUM_FLOW_SOCKETS)
|
f"initial_value{i}": ("*",) for i in range(1, NUM_FLOW_SOCKETS)
|
||||||
},
|
},
|
||||||
"hidden": {
|
"hidden": {
|
||||||
"initial_value0": ("*",)
|
"initial_value0": ("*",)
|
||||||
@ -250,7 +250,7 @@ class TestForLoopOpen:
|
|||||||
}
|
}
|
||||||
|
|
||||||
RETURN_TYPES = tuple(["FLOW_CONTROL", "INT",] + ["*"] * (NUM_FLOW_SOCKETS-1))
|
RETURN_TYPES = tuple(["FLOW_CONTROL", "INT",] + ["*"] * (NUM_FLOW_SOCKETS-1))
|
||||||
RETURN_NAMES = tuple(["flow_control", "remaining"] + ["value%d" % i for i in range(1, NUM_FLOW_SOCKETS)])
|
RETURN_NAMES = tuple(["flow_control", "remaining"] + [f"value{i}" for i in range(1, NUM_FLOW_SOCKETS)])
|
||||||
FUNCTION = "for_loop_open"
|
FUNCTION = "for_loop_open"
|
||||||
|
|
||||||
CATEGORY = "Testing/Flow"
|
CATEGORY = "Testing/Flow"
|
||||||
@ -259,8 +259,8 @@ class TestForLoopOpen:
|
|||||||
graph = GraphBuilder()
|
graph = GraphBuilder()
|
||||||
if "initial_value0" in kwargs:
|
if "initial_value0" in kwargs:
|
||||||
remaining = kwargs["initial_value0"]
|
remaining = kwargs["initial_value0"]
|
||||||
while_open = graph.node("TestWhileLoopOpen", condition=remaining, initial_value0=remaining, **{("initial_value%d" % i): kwargs.get("initial_value%d" % i, None) for i in range(1, NUM_FLOW_SOCKETS)})
|
while_open = graph.node("TestWhileLoopOpen", condition=remaining, initial_value0=remaining, **{(f"initial_value{i}"): kwargs.get(f"initial_value{i}", None) for i in range(1, NUM_FLOW_SOCKETS)})
|
||||||
outputs = [kwargs.get("initial_value%d" % i, None) for i in range(1, NUM_FLOW_SOCKETS)]
|
outputs = [kwargs.get(f"initial_value{i}", None) for i in range(1, NUM_FLOW_SOCKETS)]
|
||||||
return {
|
return {
|
||||||
"result": tuple(["stub", remaining] + outputs),
|
"result": tuple(["stub", remaining] + outputs),
|
||||||
"expand": graph.finalize(),
|
"expand": graph.finalize(),
|
||||||
@ -278,12 +278,12 @@ class TestForLoopClose:
|
|||||||
"flow_control": ("FLOW_CONTROL", {"rawLink": True}),
|
"flow_control": ("FLOW_CONTROL", {"rawLink": True}),
|
||||||
},
|
},
|
||||||
"optional": {
|
"optional": {
|
||||||
"initial_value%d" % i: ("*",{"rawLink": True}) for i in range(1, NUM_FLOW_SOCKETS)
|
f"initial_value{i}": ("*",{"rawLink": True}) for i in range(1, NUM_FLOW_SOCKETS)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN_TYPES = tuple(["*"] * (NUM_FLOW_SOCKETS-1))
|
RETURN_TYPES = tuple(["*"] * (NUM_FLOW_SOCKETS-1))
|
||||||
RETURN_NAMES = tuple(["value%d" % i for i in range(1, NUM_FLOW_SOCKETS)])
|
RETURN_NAMES = tuple([f"value{i}" for i in range(1, NUM_FLOW_SOCKETS)])
|
||||||
FUNCTION = "for_loop_close"
|
FUNCTION = "for_loop_close"
|
||||||
|
|
||||||
CATEGORY = "Testing/Flow"
|
CATEGORY = "Testing/Flow"
|
||||||
@ -293,7 +293,7 @@ class TestForLoopClose:
|
|||||||
while_open = flow_control[0]
|
while_open = flow_control[0]
|
||||||
sub = graph.node("TestIntMathOperation", operation="subtract", a=[while_open,1], b=1)
|
sub = graph.node("TestIntMathOperation", operation="subtract", a=[while_open,1], b=1)
|
||||||
cond = graph.node("TestToBoolNode", value=sub.out(0))
|
cond = graph.node("TestToBoolNode", value=sub.out(0))
|
||||||
input_values = {("initial_value%d" % i): kwargs.get("initial_value%d" % i, None) for i in range(1, NUM_FLOW_SOCKETS)}
|
input_values = {f"initial_value{i}": kwargs.get(f"initial_value{i}", None) for i in range(1, NUM_FLOW_SOCKETS)}
|
||||||
while_close = graph.node("TestWhileLoopClose",
|
while_close = graph.node("TestWhileLoopClose",
|
||||||
flow_control=flow_control,
|
flow_control=flow_control,
|
||||||
condition=cond.out(0),
|
condition=cond.out(0),
|
||||||
@ -317,7 +317,7 @@ class TestMakeListNode:
|
|||||||
"value1": ("*",),
|
"value1": ("*",),
|
||||||
},
|
},
|
||||||
"optional": {
|
"optional": {
|
||||||
"value%d" % i: ("*",) for i in range(1, NUM_LIST_SOCKETS)
|
f"value{i}": ("*",) for i in range(1, NUM_LIST_SOCKETS)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,8 +330,8 @@ class TestMakeListNode:
|
|||||||
def make_list(self, **kwargs):
|
def make_list(self, **kwargs):
|
||||||
result = []
|
result = []
|
||||||
for i in range(NUM_LIST_SOCKETS):
|
for i in range(NUM_LIST_SOCKETS):
|
||||||
if "value%d" % i in kwargs:
|
if f"value{i}" in kwargs:
|
||||||
result.append(kwargs["value%d" % i])
|
result.append(kwargs[f"value{i}"])
|
||||||
return (result,)
|
return (result,)
|
||||||
|
|
||||||
UTILITY_NODE_CLASS_MAPPINGS = {
|
UTILITY_NODE_CLASS_MAPPINGS = {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user