Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions bin/meshroom_batch
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ graph = meshroom.core.graph.Graph(name=args.pipeline)

with meshroom.core.graph.GraphModification(graph):
# initialize template pipeline
loweredPipelineTemplates = dict((k.lower(), v) for k, v in meshroom.core.pipelineTemplates.items())
loweredPipelineTemplates = {k.lower(): v for k, v in meshroom.core.pipelineTemplates.items()}
if args.pipeline.lower() in loweredPipelineTemplates:
graph.initFromTemplate(loweredPipelineTemplates[args.pipeline.lower()], publishOutputs=True if args.output else False)
else:
Expand Down Expand Up @@ -232,15 +232,15 @@ with meshroom.core.graph.GraphModification(graph):
raise RuntimeError("meshroom_batch requires a pipeline graph with at least one Publish node, none found.")

if args.overrides:
with open(args.overrides, 'r', encoding='utf-8', errors='ignore') as f:
with open(args.overrides, encoding='utf-8', errors='ignore') as f:
data = json.load(f)
for nodeName, overrides in data.items():
for attrName, value in overrides.items():
graph.findNode(nodeName).attribute(attrName).value = value

if args.paramOverrides:
print("\n")
reExtract = re.compile('(\w+)([:.])(\w[\w.]*)=(.*)')
reExtract = re.compile(r'(\w+)([:.])(\w[\w.]*)=(.*)')
for p in args.paramOverrides:
result = reExtract.match(p)
if not result:
Expand All @@ -249,12 +249,12 @@ with meshroom.core.graph.GraphModification(graph):
if t == ':':
nodesOfType = graph.nodesOfType(node)
if not nodesOfType:
raise ValueError('No node with the type "{}" in the scene.'.format(node))
raise ValueError(f'No node with the type "{node}" in the scene.')
for n in nodesOfType:
print('Overrides {node}.{param}={value}'.format(node=node, param=param, value=value))
print(f'Overrides {node}.{param}={value}')
n.attribute(param).value = value
elif t == '.':
print('Overrides {node}.{param}={value}'.format(node=node, param=param, value=value))
print(f'Overrides {node}.{param}={value}')
graph.findNode(node).attribute(param).value = value
else:
raise ValueError('Invalid param override: ' + str(p))
Expand All @@ -265,10 +265,10 @@ with meshroom.core.graph.GraphModification(graph):

if args.save:
graph.save(args.save, setupProjectFile=not bool(args.cache))
print('File successfully saved: "{}"'.format(args.save))
print(f'File successfully saved: "{args.save}"')

if not args.output:
print('No output set, results will be available in the cache folder: "{}"'.format(graph.cacheDir))
print(f'No output set, results will be available in the cache folder: "{graph.cacheDir}"')

# find end nodes (None will compute all graph)
toNodes = graph.findNodes(args.toNode) if args.toNode else None
Expand Down
62 changes: 30 additions & 32 deletions bin/meshroom_newNodeType
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function

import argparse
import os
Expand All @@ -15,7 +14,7 @@ def trim(s):
"""
# regex to replace all space groups by a single space
# use split() to remove trailing space at beginning/end
return re.sub('\s+', ' ', s).strip()
return re.sub(r'\s+', ' ', s).strip()


def quotesForStrings(valueStr):
Expand All @@ -30,9 +29,9 @@ def quotesForStrings(valueStr):
float(valueStr)
except ValueError:
if "'" in valueStr:
v = "'''{}'''".format(valueStr)
v = f"'''{valueStr}'''"
else:
v = "'{}'".format(valueStr)
v = f"'{valueStr}'"
return v

def convertToLabel(name):
Expand Down Expand Up @@ -86,7 +85,7 @@ elif sys.stdin.isatty():

if not inputCmdLineDoc:
print('No input documentation.')
print('Usage: YOUR_COMMAND --help | {cmd}'.format(cmd=os.path.splitext(__file__)[0]))
print(f'Usage: YOUR_COMMAND --help | {os.path.splitext(__file__)[0]}')
sys.exit(-1)


Expand All @@ -104,39 +103,38 @@ print(inputCmdLineDoc)
args_re = None
if args.parser == 'boost':
args_re = re.compile(
'^\s+' # space(s)
'(?:-(?P<argShortName>\w+)\|?)?' # potential argument short name
'\s*\[?' # potential '['
'\s*--(?P<argLongName>\w+)' # argument long name
'(?:\s*\])?' # potential ']'
'(?:\s+(?P<arg>\w+)?)?' # potential arg
'(?:\s+\(\=(?P<defaultValue>.+)\))?' # potential default value
'\s+(?P<descriptionFirst>.*?)\n' # end of the line
'(?P<descriptionNext>(?:\s+[^-\s].+?\n)*)' # next documentation lines
'',
re.MULTILINE)
r'^\s+' # space(s)
r'(?:-(?P<argShortName>\w+)\|?)?' # potential argument short name
r'\s*\[?' # potential '['
r'\s*--(?P<argLongName>\w+)' # argument long name
r'(?:\s*\])?' # potential ']'
r'(?:\s+(?P<arg>\w+)?)?' # potential arg
r'(?:\s+\(\=(?P<defaultValue>.+)\))?' # potential default value
r'\s+(?P<descriptionFirst>.*?)\n' # end of the line
r'(?P<descriptionNext>(?:\s+[^-\s].+?\n)*)' # next documentation lines
, re.MULTILINE)
elif args.parser == 'cmdLineLib':
args_re = re.compile(
'^'
'\[' # '['
'-(?P<argShortName>\w+)' # argument short name
'\|'
'--(?P<argLongName>\w+)' # argument long name
'(?:\s+(?P<arg>\w+)?)?' # potential arg
'\]' # ']'
'()' # no default value
'(?P<descriptionFirst>.*?)?\n' # end of the line
'(?P<descriptionNext>(?:[^\[\w].+?\n)*)' # next documentation lines
r'\[' # '['
r'-(?P<argShortName>\w+)' # argument short name
r'\|'
r'--(?P<argLongName>\w+)' # argument long name
r'(?:\s+(?P<arg>\w+)?)?' # potential arg
r'\]' # ']'
r'()' # no default value
r'(?P<descriptionFirst>.*?)?\n' # end of the line
r'(?P<descriptionNext>(?:[^\[\w].+?\n)*)' # next documentation lines
, re.MULTILINE)
elif args.parser == 'basic':
args_re = re.compile('()--(?P<argLongName>\w+)()()()()')
args_re = re.compile(r'()--(?P<argLongName>\w+)()()()()')
else:
print('Error: Unknown input parser "{}"'.format(args.parser))
print(f'Error: Unknown input parser "{args.parser}"')
sys.exit(-1)

choiceValues1_re = re.compile('\* (?P<value>\w+):')
choiceValues2_re = re.compile('\((?P<value>.+?)\)')
choiceValues3_re = re.compile('\{(?P<value>.+?)\}')
choiceValues1_re = re.compile(r'\* (?P<value>\w+):')
choiceValues2_re = re.compile(r'\((?P<value>.+?)\)')
choiceValues3_re = re.compile(r'\{(?P<value>.+?)\}')

cmdLineArgs = args_re.findall(inputCmdLineDoc.decode('utf-8'))

Expand Down Expand Up @@ -286,10 +284,10 @@ fileStr += """
outputFilepath = os.path.join(args.output, args.node + '.py')

if not args.force and os.path.exists(outputFilepath):
print('Plugin "{}" already exists "{}".'.format(args.node, outputFilepath))
print(f'Plugin "{args.node}" already exists "{outputFilepath}".')
sys.exit(-1)

with open(outputFilepath, 'w') as pluginFile:
pluginFile.write(fileStr)

print('New node exported to: "{}"'.format(outputFilepath))
print(f'New node exported to: "{outputFilepath}"')
4 changes: 2 additions & 2 deletions bin/meshroom_statistics
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ parser.add_argument("--verbose", help="Print full status information",
args = parser.parse_args()

if not os.path.exists(args.graphFile):
print('ERROR: No graph file "{}".'.format(args.graphFile))
print(f'ERROR: No graph file "{args.graphFile}".')
sys.exit(-1)

graph = pg.loadGraph(args.graphFile)
Expand All @@ -64,7 +64,7 @@ else:

for node in nodes:
for chunk in node.chunks:
print('{}: {}\n'.format(chunk.name, chunk.statistics.toDict()))
print(f'{chunk.name}: {chunk.statistics.toDict()}\n')

if args.exportHtml:
with open(args.exportHtml, 'w') as fileObj:
Expand Down
8 changes: 4 additions & 4 deletions bin/meshroom_status
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ parser.add_argument("--verbose", help="Print full status information",
args = parser.parse_args()

if not os.path.exists(args.graphFile):
print('ERROR: No graph file "{}".'.format(args.node, args.graphFile))
print(f'ERROR: No graph file "{args.node}".')
sys.exit(-1)

graph = meshroom.core.graph.loadGraph(args.graphFile)
Expand All @@ -32,10 +32,10 @@ graph.update()
if args.node:
node = graph.node(args.node)
if node is None:
print('ERROR: node "{}" does not exist in file "{}".'.format(args.node, args.graphFile))
print(f'ERROR: node "{args.node}" does not exist in file "{args.graphFile}".')
sys.exit(-1)
for chunk in node.chunks:
print('{}: {}'.format(chunk.name, chunk.status.status.name))
print(f'{chunk.name}: {chunk.status.status.name}')
if args.verbose:
print('statusFile: ', node.statusFile)
pprint(node.status.toDict())
Expand All @@ -46,6 +46,6 @@ else:
nodes, edges = graph.dfsOnFinish(startNodes=startNodes)
for node in nodes:
for chunk in node.chunks:
print('{}: {}'.format(chunk.name, chunk.status.status.name))
print(f'{chunk.name}: {chunk.status.status.name}')
if args.verbose:
pprint([n.status.toDict() for n in nodes])
16 changes: 8 additions & 8 deletions meshroom/common/PySignal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
from weakref import WeakMethod


class Signal(object):
class Signal:
"""
The Signal is the core object that handles connection and emission .
"""

def __init__(self):
super(Signal, self).__init__()
super().__init__()
self._block = False
self._sender = None
self._slots = []
Expand Down Expand Up @@ -86,7 +86,7 @@
Connects the signal to any callable object
"""
if not callable(slot):
raise ValueError("Connection to non-callable '%s' object failed" % slot.__class__.__name__)
raise ValueError(f"Connection to non-callable '{slot.__class__.__name__}' object failed")

Check warning on line 89 in meshroom/common/PySignal.py

View check run for this annotation

Codecov / codecov/patch

meshroom/common/PySignal.py#L89

Added line #L89 was not covered by tests

if isinstance(slot, (partial, Signal)) or '<' in slot.__name__:
# If it's a partial, a Signal or a lambda. The '<' check is the only py2 and py3 compatible way I could find
Expand Down Expand Up @@ -151,7 +151,7 @@
return None


class ClassSignal(object):
class ClassSignal:
"""
The class signal allows a signal to be set on a class rather than an instance.
This emulates the behavior of a PyQt signal
Expand Down Expand Up @@ -199,7 +199,7 @@
Emits a signal by name if it exists. Any additional args or kwargs are passed to the signal
:param signalName: the signal name to emit
"""
assert signalName in self, "%s is not a registered signal" % signalName
assert signalName in self, f"{signalName} is not a registered signal"

Check warning on line 202 in meshroom/common/PySignal.py

View check run for this annotation

Codecov / codecov/patch

meshroom/common/PySignal.py#L202

Added line #L202 was not covered by tests
self[signalName].emit(*args, **kwargs)

def connect(self, signalName, slot):
Expand All @@ -208,7 +208,7 @@
:param signalName: the signal name to connect to
:param slot: the callable slot to register
"""
assert signalName in self, "%s is not a registered signal" % signalName
assert signalName in self, f"{signalName} is not a registered signal"

Check warning on line 211 in meshroom/common/PySignal.py

View check run for this annotation

Codecov / codecov/patch

meshroom/common/PySignal.py#L211

Added line #L211 was not covered by tests
self[signalName].connect(slot)

def block(self, signals=None, isBlocked=True):
Expand All @@ -230,11 +230,11 @@

for signal in signals:
if signal not in self:
raise RuntimeError("Could not find signal matching %s" % signal)
raise RuntimeError(f"Could not find signal matching {signal}")

Check warning on line 233 in meshroom/common/PySignal.py

View check run for this annotation

Codecov / codecov/patch

meshroom/common/PySignal.py#L233

Added line #L233 was not covered by tests
self[signal].block(isBlocked)


class ClassSignalFactory(object):
class ClassSignalFactory:
"""
The class signal allows a signal factory to be set on a class rather than an instance.
"""
Expand Down
6 changes: 3 additions & 3 deletions meshroom/common/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ def func_wrapper(*f_args, **f_kwargs):

class CoreProperty(property):
def __init__(self, ptype, fget=None, fset=None, **kwargs):
super(CoreProperty, self).__init__(fget, fset)
super().__init__(fget, fset)


class CoreObject(object):
class CoreObject:

def __init__(self, parent=None, *args, **kwargs):
super(CoreObject, self).__init__()
super().__init__()
self._parent = parent
# Note: we do not use ClassSignal, as it can not be used in __del__.
self.destroyed = PySignal.Signal()
Expand Down
14 changes: 7 additions & 7 deletions meshroom/common/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

def __init__(self, keyAttrName='', parent=None):
""" Constructs an object list model with the given parent. """
super(QObjectListModel, self).__init__(parent)
super().__init__(parent)

self._objects = list() # Internal list of objects
self._keyAttrName = keyAttrName
Expand Down Expand Up @@ -279,7 +279,7 @@
if key is None:
return
if key in self._objectByKey:
raise ValueError("Object key {}:{} is not unique".format(self._keyAttrName, key))
raise ValueError(f"Object key {self._keyAttrName}:{key} is not unique")

Check warning on line 282 in meshroom/common/qt.py

View check run for this annotation

Codecov / codecov/patch

meshroom/common/qt.py#L282

Added line #L282 was not covered by tests

self._objectByKey[key] = item

Expand Down Expand Up @@ -322,7 +322,7 @@
# TODO: handle notify signal to emit dataChanged signal

def __init__(self, keyAttrName="name", T=QtCore.QObject, parent=None):
super(QTypedObjectListModel, self).__init__(keyAttrName, parent)
super().__init__(keyAttrName, parent)

self._T = T
blacklist = ["id", "index", "class", "model", "modelData"]
Expand All @@ -340,7 +340,7 @@
print("Reserved role name: " + prop.name())

def data(self, index, role):
obj = super(QTypedObjectListModel, self).data(index, self.ObjectRole)
obj = super().data(index, self.ObjectRole)
if role == self.ObjectRole:
return obj
if obj:
Expand All @@ -355,15 +355,15 @@
if item.staticMetaObject != self._metaObject:
raise TypeError("Invalid object type: expected {}, got {}".format(
self._metaObject.className(), item.staticMetaObject.className()))
super(QTypedObjectListModel, self)._referenceItem(item)
super()._referenceItem(item)


class SortedModelByReference(QtCore.QSortFilterProxyModel):
""" Sort a source model based on the ordered list (reference) of the same elements.
This proxy is useful if the model needs to be sorted a certain way for a specific use.
"""
def __init__(self, parent):
super(SortedModelByReference, self).__init__(parent)
super().__init__(parent)

Check warning on line 366 in meshroom/common/qt.py

View check run for this annotation

Codecov / codecov/patch

meshroom/common/qt.py#L366

Added line #L366 was not covered by tests
self._reference = []

def setReference(self, iterable):
Expand All @@ -385,7 +385,7 @@

def sort(self):
""" Sort the proxy and call invalidate() """
super(SortedModelByReference, self).sort(0, QtCore.Qt.AscendingOrder)
super().sort(0, QtCore.Qt.AscendingOrder)

Check warning on line 388 in meshroom/common/qt.py

View check run for this annotation

Codecov / codecov/patch

meshroom/common/qt.py#L388

Added line #L388 was not covered by tests
self.invalidate()


Expand Down
Loading