mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-07-26 04:57:18 +02:00
[core] Add 'strictCompatibility' mode for loadGraph function
Provide a way to control how to handle node compatibility issues when loading a Graph with the `strictCompatibility` parameter. Introduce a new error type, GraphCompatibilityError, to be raised when loading a Graph with compatibility issues with strictCompatibility enabled.
This commit is contained in:
parent
c3bb55a414
commit
c09a0d2327
2 changed files with 33 additions and 2 deletions
|
@ -15,7 +15,7 @@ import meshroom.core
|
|||
from meshroom.common import BaseObject, DictModel, Slot, Signal, Property
|
||||
from meshroom.core import Version
|
||||
from meshroom.core.attribute import Attribute, ListAttribute, GroupAttribute
|
||||
from meshroom.core.exception import StopGraphVisit, StopBranchVisit
|
||||
from meshroom.core.exception import GraphCompatibilityError, StopGraphVisit, StopBranchVisit
|
||||
from meshroom.core.node import nodeFactory, Status, Node, CompatibilityNode
|
||||
|
||||
# Replace default encoder to support Enums
|
||||
|
@ -1633,11 +1633,27 @@ class Graph(BaseObject):
|
|||
canComputeLeaves = Property(bool, lambda self: self._canComputeLeaves, notify=canComputeLeavesChanged)
|
||||
|
||||
|
||||
def loadGraph(filepath):
|
||||
def loadGraph(filepath, strictCompatibility: bool = False) -> Graph:
|
||||
"""
|
||||
Load a Graph from a Meshroom Graph (.mg) file.
|
||||
|
||||
Args:
|
||||
filepath: The path to the Meshroom Graph file.
|
||||
strictCompatibility: If True, raise a GraphCompatibilityError if the loaded Graph has node compatibility issues.
|
||||
|
||||
Returns:
|
||||
Graph: The loaded Graph instance.
|
||||
|
||||
Raises:
|
||||
GraphCompatibilityError: If the Graph has node compatibility issues and `strictCompatibility` is False.
|
||||
"""
|
||||
graph = Graph("")
|
||||
graph.load(filepath)
|
||||
|
||||
compatibilityIssues = len(graph.compatibilityNodes) > 0
|
||||
if compatibilityIssues and strictCompatibility:
|
||||
raise GraphCompatibilityError(filepath, {n.name: str(n.issue) for n in graph.compatibilityNodes})
|
||||
|
||||
graph.update()
|
||||
return graph
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue