Skip to content

Commit fab1b8e

Browse files
author
Matthieu Hog
committed
moved plugin logic to nodeDesc instead of class
added build badge
1 parent d38fe56 commit fab1b8e

13 files changed

+407
-236
lines changed

meshroom/core/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
pass
2020

2121
from meshroom.core.submitter import BaseSubmitter
22-
from . import desc
22+
from meshroom.core import desc
2323

2424
# Setup logging
2525
logging.basicConfig(format='[%(asctime)s][%(levelname)s] %(message)s', level=logging.INFO)

meshroom/core/desc.py

+55-1
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,53 @@ class Node(object):
717717
documentation = ''
718718
category = 'Other'
719719

720+
_isPlugin = True
721+
720722
def __init__(self):
721723
super(Node, self).__init__()
722724
self.hasDynamicOutputAttribute = any(output.isDynamicValue for output in self.outputs)
725+
try:
726+
self.envFile
727+
self.envType
728+
except:
729+
self._isPlugin=False
730+
731+
@property
732+
def envType(cls):
733+
from core.plugin import EnvType #lazy import for plugin to avoid circular dependency
734+
return EnvType.NONE
735+
736+
@property
737+
def envFile(cls):
738+
"""
739+
Env file used to build the environement, you may overwrite this to custom the behaviour
740+
"""
741+
raise NotImplementedError("You must specify an env file")
742+
743+
@property
744+
def _envName(cls):
745+
"""
746+
Get the env name by hashing the env files, overwrite this to use a custom pre-build env
747+
"""
748+
with open(cls.envFile, 'r') as file:
749+
envContent = file.read()
750+
from meshroom.core.plugin import getEnvName #lazy import as to avoid circular dep
751+
return getEnvName(envContent)
752+
753+
@property
754+
def isPlugin(self):
755+
"""
756+
Tests if the node is a valid plugin node
757+
"""
758+
return self._isPlugin
759+
760+
@property
761+
def isBuilt(self):
762+
"""
763+
Tests if the environnement is built
764+
"""
765+
from meshroom.core.plugin import isBuilt
766+
return self._isPlugin and isBuilt(self)
723767

724768
def upgradeAttributeValues(self, attrValues, fromVersion):
725769
return attrValues
@@ -790,7 +834,17 @@ def buildCommandLine(self, chunk):
790834
if chunk.node.isParallelized and chunk.node.size > 1:
791835
cmdSuffix = ' ' + self.commandLineRange.format(**chunk.range.toDict())
792836

793-
return cmdPrefix + chunk.node.nodeDesc.commandLine.format(**chunk.node._cmdVars) + cmdSuffix
837+
cmd=cmdPrefix + chunk.node.nodeDesc.commandLine.format(**chunk.node._cmdVars) + cmdSuffix
838+
839+
#the process in Popen does not seem to use the right python, even if meshroom_compute is called within the env
840+
#so in the case of command line using python, we have to make sure it is using the correct python
841+
from meshroom.core.plugin import EnvType, getVenvPath, getVenvExe #lazy import to prevent circular dep
842+
if self.isPlugin and self.envType == EnvType.VENV:
843+
envPath = getVenvPath(self._envName)
844+
envExe = getVenvExe(envPath)
845+
cmd=cmd.replace("python", envExe)
846+
847+
return cmd
794848

795849
def stopProcess(self, chunk):
796850
# The same node could exists several times in the graph and

meshroom/core/node.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from meshroom.core.attribute import attributeFactory, ListAttribute, GroupAttribute, Attribute
2222
from meshroom.core.exception import NodeUpgradeError, UnknownNodeTypeError
2323

24-
2524
def getWritingFilepath(filepath):
2625
return filepath + '.writing.' + str(uuid.uuid4())
2726

@@ -406,13 +405,14 @@ def process(self, forceCompute=False):
406405

407406
#if plugin node and if first call call meshroom_compute inside the env on 'host' so that the processchunk
408407
# of the node will be ran into the env
409-
if hasattr(self.node.nodeDesc, 'envFile') and self._status.status!=Status.FIRST_RUN:
408+
if self.node.nodeDesc.isPlugin and self._status.status!=Status.FIRST_RUN:
410409
try:
411-
if not self.node.nodeDesc.isBuild():
410+
from meshroom.core.plugin import isBuilt, build, getCommandLine #lazy import to avoid circular dep
411+
if not isBuilt(self.node.nodeDesc):
412412
self.upgradeStatusTo(Status.BUILD)
413-
self.node.nodeDesc.build()
413+
build(self.node.nodeDesc)
414414
self.upgradeStatusTo(Status.FIRST_RUN)
415-
command = self.node.nodeDesc.getCommandLine(self)
415+
command = getCommandLine(self)
416416
#NOTE: docker returns 0 even if mount fail (it fails on the deamon side)
417417
logging.info("Running plugin node with "+command)
418418
status = os.system(command)
@@ -482,6 +482,7 @@ def isExtern(self):
482482
statusNodeName = Property(str, lambda self: self._status.nodeName, constant=True)
483483

484484
elapsedTime = Property(float, lambda self: self._status.elapsedTime, notify=statusChanged)
485+
485486

486487

487488
# Simple structure for storing node position
@@ -1413,6 +1414,8 @@ def has3DOutputAttribute(self):
14131414
hasSequenceOutput = Property(bool, hasSequenceOutputAttribute, notify=outputAttrEnabledChanged)
14141415
has3DOutput = Property(bool, has3DOutputAttribute, notify=outputAttrEnabledChanged)
14151416

1417+
isPlugin = Property(bool, lambda self: self.nodeDesc.isPlugin, constant=True)
1418+
isBuilt = Property(bool, lambda self: self.nodeDesc.isBuilt, constant=True)
14161419

14171420
class Node(BaseNode):
14181421
"""

0 commit comments

Comments
 (0)