mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-07-30 23:08:25 +02:00
Modernize to python-3.9+ with pyupgrade (--py39-plus)
This commit is contained in:
parent
22b2161ddd
commit
41738f7f40
26 changed files with 148 additions and 157 deletions
|
@ -1,10 +1,9 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from typing import Any, Iterable, Optional
|
||||
from typing import Any, Optional
|
||||
from collections.abc import Iterable
|
||||
import weakref
|
||||
from collections import defaultdict, OrderedDict
|
||||
from contextlib import contextmanager
|
||||
|
@ -63,7 +62,7 @@ def GraphModification(graph):
|
|||
class Edge(BaseObject):
|
||||
|
||||
def __init__(self, src, dst, parent=None):
|
||||
super(Edge, self).__init__(parent)
|
||||
super().__init__(parent)
|
||||
self._src = weakref.ref(src)
|
||||
self._dst = weakref.ref(dst)
|
||||
self._repr = f"<Edge> {self._src()} -> {self._dst()}"
|
||||
|
@ -85,13 +84,13 @@ GRAY = 1
|
|||
BLACK = 2
|
||||
|
||||
|
||||
class Visitor(object):
|
||||
class Visitor:
|
||||
"""
|
||||
Base class for Graph Visitors that does nothing.
|
||||
Sub-classes can override any method to implement specific algorithms.
|
||||
"""
|
||||
def __init__(self, reverse, dependenciesOnly):
|
||||
super(Visitor, self).__init__()
|
||||
super().__init__()
|
||||
self.reverse = reverse
|
||||
self.dependenciesOnly = dependenciesOnly
|
||||
|
||||
|
@ -197,7 +196,7 @@ class Graph(BaseObject):
|
|||
"""
|
||||
|
||||
def __init__(self, name: str = "", parent: BaseObject = None):
|
||||
super(Graph, self).__init__(parent)
|
||||
super().__init__(parent)
|
||||
self.name: str = name
|
||||
self._loading: bool = False
|
||||
self._saving: bool = False
|
||||
|
@ -339,7 +338,7 @@ class Graph(BaseObject):
|
|||
uidOccurrences = uidPattern.findall(updatedFileData)
|
||||
for occ in uidOccurrences:
|
||||
uid = occ.split("\"")[-2] # UID is second to last element
|
||||
newUidStr = r'"uid": "{}"'.format(uid)
|
||||
newUidStr = fr'"uid": "{uid}"'
|
||||
updatedFileData = updatedFileData.replace(occ, newUidStr)
|
||||
graphContent = json.loads(updatedFileData)
|
||||
|
||||
|
@ -856,11 +855,11 @@ class Graph(BaseObject):
|
|||
return self._edges.get(dstAttributeName)
|
||||
|
||||
def getLeafNodes(self, dependenciesOnly):
|
||||
nodesWithOutputLink = set([edge.src.node for edge in self.getEdges(dependenciesOnly)])
|
||||
nodesWithOutputLink = {edge.src.node for edge in self.getEdges(dependenciesOnly)}
|
||||
return set(self._nodes) - nodesWithOutputLink
|
||||
|
||||
def getRootNodes(self, dependenciesOnly):
|
||||
nodesWithInputLink = set([edge.dst.node for edge in self.getEdges(dependenciesOnly)])
|
||||
nodesWithInputLink = {edge.dst.node for edge in self.getEdges(dependenciesOnly)}
|
||||
return set(self._nodes) - nodesWithInputLink
|
||||
|
||||
@changeTopology
|
||||
|
@ -910,7 +909,7 @@ class Graph(BaseObject):
|
|||
return minDepth if minimal else maxDepth
|
||||
|
||||
def getInputEdges(self, node, dependenciesOnly):
|
||||
return set([edge for edge in self.getEdges(dependenciesOnly=dependenciesOnly) if edge.dst.node is node])
|
||||
return {edge for edge in self.getEdges(dependenciesOnly=dependenciesOnly) if edge.dst.node is node}
|
||||
|
||||
def _getInputEdgesPerNode(self, dependenciesOnly):
|
||||
nodeEdges = defaultdict(set)
|
||||
|
@ -1167,7 +1166,7 @@ class Graph(BaseObject):
|
|||
:return:
|
||||
"""
|
||||
nodesStack = []
|
||||
edgesScore = defaultdict(lambda: 0)
|
||||
edgesScore = defaultdict(int)
|
||||
visitor = Visitor(reverse=False, dependenciesOnly=dependenciesOnly)
|
||||
|
||||
def finishEdge(edge, graph):
|
||||
|
@ -1223,7 +1222,7 @@ class Graph(BaseObject):
|
|||
def getInputNodes(self, node, recursive, dependenciesOnly):
|
||||
""" Return either the first level input nodes of a node or the whole chain. """
|
||||
if not recursive:
|
||||
return set([edge.src.node for edge in self.getEdges(dependenciesOnly) if edge.dst.node is node])
|
||||
return {edge.src.node for edge in self.getEdges(dependenciesOnly) if edge.dst.node is node}
|
||||
|
||||
inputNodes, edges = self.dfsOnDiscover(startNodes=[node], filterTypes=None, reverse=False)
|
||||
return inputNodes[1:] # exclude current node
|
||||
|
@ -1231,7 +1230,7 @@ class Graph(BaseObject):
|
|||
def getOutputNodes(self, node, recursive, dependenciesOnly):
|
||||
""" Return either the first level output nodes of a node or the whole chain. """
|
||||
if not recursive:
|
||||
return set([edge.dst.node for edge in self.getEdges(dependenciesOnly) if edge.src.node is node])
|
||||
return {edge.dst.node for edge in self.getEdges(dependenciesOnly) if edge.src.node is node}
|
||||
|
||||
outputNodes, edges = self.dfsOnDiscover(startNodes=[node], filterTypes=None, reverse=True)
|
||||
return outputNodes[1:] # exclude current node
|
||||
|
@ -1253,7 +1252,7 @@ class Graph(BaseObject):
|
|||
|
||||
class SCVisitor(Visitor):
|
||||
def __init__(self, reverse, dependenciesOnly):
|
||||
super(SCVisitor, self).__init__(reverse, dependenciesOnly)
|
||||
super().__init__(reverse, dependenciesOnly)
|
||||
|
||||
canCompute = True
|
||||
canSubmit = True
|
||||
|
@ -1611,7 +1610,7 @@ def executeGraph(graph, toNodes=None, forceCompute=False, forceStatus=False):
|
|||
chunksInConflict = getAlreadySubmittedChunks(nodes)
|
||||
|
||||
if chunksInConflict:
|
||||
chunksStatus = set([chunk.status.status.name for chunk in chunksInConflict])
|
||||
chunksStatus = {chunk.status.status.name for chunk in chunksInConflict}
|
||||
chunksName = [node.name for node in chunksInConflict]
|
||||
msg = 'WARNING: Some nodes are already submitted with status: {}\nNodes: {}'.format(
|
||||
', '.join(chunksStatus),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue