-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathutils.py
More file actions
60 lines (44 loc) · 1.63 KB
/
Copy pathutils.py
File metadata and controls
60 lines (44 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from contextlib import contextmanager
from unittest.mock import patch
import meshroom
from meshroom.core import desc, pluginManager, loadPluginFolder
from meshroom.core.plugins import NodePlugin, NodePluginStatus
import os
@contextmanager
def registeredNodeTypes(nodeTypes: list[type[desc.Node]]):
nodePluginsList = {}
for nodeType in nodeTypes:
nodePlugin = NodePlugin(nodeType)
pluginManager.registerNode(nodePlugin)
nodePluginsList[nodeType] = nodePlugin
yield
for nodeType in nodeTypes:
pluginManager.unregisterNode(nodePluginsList[nodeType])
@contextmanager
def overrideNodeTypeVersion(nodeType: type[desc.Node], version: str):
""" Helper context manager to override the version of a given node type. """
unpatchedFunc = meshroom.core.nodeVersion
with patch.object(
meshroom.core,
"nodeVersion",
side_effect=lambda type: version if type is nodeType else unpatchedFunc(type),
):
yield
def registerNodeDesc(nodeDesc: type[desc.Node]):
name = nodeDesc.__name__
if not pluginManager.isRegistered(name):
pluginManager._nodePlugins[name] = NodePlugin(nodeDesc)
def unregisterNodeDesc(nodeDesc: type[desc.Node]):
name = nodeDesc.__name__
if pluginManager.isRegistered(name):
del pluginManager._nodePlugins[name]
@contextmanager
def registeredPlugins(folder: str):
plugins = loadPluginFolder(folder)
yield
for plugin in plugins:
pluginManager.removePlugin(plugin)
@contextmanager
def overrideOsEnvironmentVariables(envVariables: dict):
with patch.dict(os.environ, envVariables, clear=False):
yield