Skip to content

Commit

Permalink
moved plugin logic to nodeDesc instead of class
Browse files Browse the repository at this point in the history
added build badge
  • Loading branch information
Matthieu Hog committed Sep 16, 2024
1 parent d38fe56 commit fab1b8e
Show file tree
Hide file tree
Showing 13 changed files with 407 additions and 236 deletions.
2 changes: 1 addition & 1 deletion meshroom/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
pass

from meshroom.core.submitter import BaseSubmitter
from . import desc
from meshroom.core import desc

# Setup logging
logging.basicConfig(format='[%(asctime)s][%(levelname)s] %(message)s', level=logging.INFO)
Expand Down
56 changes: 55 additions & 1 deletion meshroom/core/desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,9 +717,53 @@ class Node(object):
documentation = ''
category = 'Other'

_isPlugin = True

def __init__(self):
super(Node, self).__init__()
self.hasDynamicOutputAttribute = any(output.isDynamicValue for output in self.outputs)
try:
self.envFile
self.envType
except:

Check notice on line 728 in meshroom/core/desc.py

View check run for this annotation

codefactor.io / CodeFactor

meshroom/core/desc.py#L728

Do not use bare 'except'. (E722)
self._isPlugin=False

@property
def envType(cls):
from core.plugin import EnvType #lazy import for plugin to avoid circular dependency
return EnvType.NONE

@property
def envFile(cls):
"""
Env file used to build the environement, you may overwrite this to custom the behaviour
"""
raise NotImplementedError("You must specify an env file")

@property
def _envName(cls):
"""
Get the env name by hashing the env files, overwrite this to use a custom pre-build env
"""
with open(cls.envFile, 'r') as file:
envContent = file.read()
from meshroom.core.plugin import getEnvName #lazy import as to avoid circular dep
return getEnvName(envContent)

@property
def isPlugin(self):
"""
Tests if the node is a valid plugin node
"""
return self._isPlugin

@property
def isBuilt(self):
"""
Tests if the environnement is built
"""
from meshroom.core.plugin import isBuilt
return self._isPlugin and isBuilt(self)

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

return cmdPrefix + chunk.node.nodeDesc.commandLine.format(**chunk.node._cmdVars) + cmdSuffix
cmd=cmdPrefix + chunk.node.nodeDesc.commandLine.format(**chunk.node._cmdVars) + cmdSuffix

#the process in Popen does not seem to use the right python, even if meshroom_compute is called within the env
#so in the case of command line using python, we have to make sure it is using the correct python
from meshroom.core.plugin import EnvType, getVenvPath, getVenvExe #lazy import to prevent circular dep
if self.isPlugin and self.envType == EnvType.VENV:
envPath = getVenvPath(self._envName)
envExe = getVenvExe(envPath)
cmd=cmd.replace("python", envExe)

return cmd

def stopProcess(self, chunk):
# The same node could exists several times in the graph and
Expand Down
13 changes: 8 additions & 5 deletions meshroom/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from meshroom.core.attribute import attributeFactory, ListAttribute, GroupAttribute, Attribute
from meshroom.core.exception import NodeUpgradeError, UnknownNodeTypeError


def getWritingFilepath(filepath):
return filepath + '.writing.' + str(uuid.uuid4())

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

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

elapsedTime = Property(float, lambda self: self._status.elapsedTime, notify=statusChanged)



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

isPlugin = Property(bool, lambda self: self.nodeDesc.isPlugin, constant=True)
isBuilt = Property(bool, lambda self: self.nodeDesc.isBuilt, constant=True)

Check notice on line 1418 in meshroom/core/node.py

View check run for this annotation

codefactor.io / CodeFactor

meshroom/core/node.py#L1418

Multiple spaces before operator. (E221)

Check notice on line 1418 in meshroom/core/node.py

View check run for this annotation

codefactor.io / CodeFactor

meshroom/core/node.py#L1418

Multiple spaces after ','. (E241)

class Node(BaseNode):
"""
Expand Down
Loading

0 comments on commit fab1b8e

Please sign in to comment.