23
23
from meshroom .core .graph import loadGraph
24
24
from meshroom .core import hashValue
25
25
26
- #where the executables are (eg meshroom compute)
26
+ #executables def
27
27
meshroomBinDir = os .path .abspath (os .path .join (meshroomFolder , ".." , "bin" ))
28
+ condaBin = "conda"
29
+ dockerBin = "docker"
28
30
29
31
class EnvType (Enum ):
30
32
"""
31
33
enum for the type of env used (by degree of encapsulation)
32
34
"""
33
35
NONE = 0
34
36
PIP = 1
37
+ REZ = 2
35
38
VENV = 10
36
39
CONDA = 20
37
40
DOCKER = 30
@@ -63,7 +66,7 @@ def _dockerImageExists(image_name, tag='latest'):
63
66
Check if the desired image:tag exists
64
67
"""
65
68
try :
66
- result = subprocess .run ( ['docker' , 'images' , image_name , '--format' , '{{.Repository}}:{{.Tag}}' ],
69
+ result = subprocess .run ( [dockerBin , 'images' , image_name , '--format' , '{{.Repository}}:{{.Tag}}' ],
67
70
stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
68
71
if result .returncode != 0 :
69
72
return False
@@ -84,8 +87,8 @@ def _condaEnvExist(envName):
84
87
"""
85
88
Checks if a specified env exists
86
89
"""
87
- cmd = "conda list --name "+ envName
88
- return os .system (cmd ) == 0
90
+ cmd = condaBin + " list --name "+ envName
91
+ return os .system (cmd ) == 0
89
92
90
93
def _formatPluginName (pluginName ):
91
94
"""
@@ -116,6 +119,23 @@ def _venvExists(envName):
116
119
"""
117
120
return os .path .isdir (getVenvPath (envName ))
118
121
122
+ def getActiveRezPackages ():
123
+ """
124
+ Returns a list containing the active explicit packages
125
+ """
126
+ packages = []
127
+ if 'REZ_REQUEST' in os .environ :
128
+ nondefpackages = [n .split ("-" )[0 ] for n in os .environ .get ('REZ_REQUEST' , '' ).split ()]
129
+ resolvedPackages = os .environ .get ('REZ_RESOLVE' , '' ).split ()
130
+ resolvedVersions = {}
131
+ for r in resolvedPackages :
132
+ if r .startswith ('~' ):
133
+ continue
134
+ v = r .split ('-' )
135
+ resolvedVersions [v [0 ]] = v [1 ]
136
+ packages = [p + "-" + resolvedVersions [p ] for p in resolvedVersions .keys () if p in nondefpackages ]
137
+ return packages
138
+
119
139
def installPlugin (pluginUrl ):
120
140
"""
121
141
Install plugin from an url or local path.
@@ -219,7 +239,7 @@ def isBuilt(nodeDesc):
219
239
"""
220
240
Check if the env needs to be build for a specific nodesc.
221
241
"""
222
- if nodeDesc .envType == EnvType .NONE :
242
+ if nodeDesc .envType in [ EnvType .NONE , EnvType . REZ ] :
223
243
return True
224
244
elif nodeDesc .envType == EnvType .PIP :
225
245
#NOTE: could find way to check for installed packages instead of rebuilding all the time
@@ -238,7 +258,7 @@ def build(nodeDesc):
238
258
if not hasattr (nodeDesc , 'envFile' ):
239
259
raise RuntimeError ("The nodedesc has no env file" )
240
260
returnValue = 0
241
- if nodeDesc .envType == EnvType .NONE :
261
+ if nodeDesc .envType in [ EnvType .NONE , EnvType . REZ ] :
242
262
pass
243
263
elif nodeDesc .envType == EnvType .PIP :
244
264
#install packages in the same python as meshroom
@@ -263,14 +283,14 @@ def build(nodeDesc):
263
283
elif nodeDesc .envType == EnvType .CONDA :
264
284
#build a conda env from a yaml file
265
285
logging .info ("Creating conda env " + nodeDesc ._envName + " from " + nodeDesc .envFile )
266
- makeEnvCommand = ( _cleanEnvVarsRez ()+ " conda config --set channel_priority strict ; "
267
- + " conda env create -v -v --name "+ nodeDesc ._envName
286
+ makeEnvCommand = ( _cleanEnvVarsRez ()+ condaBin + " config --set channel_priority strict ; "
287
+ + condaBin + " env create -v -v --name "+ nodeDesc ._envName
268
288
+ " --file " + nodeDesc .envFile + " " )
269
289
logging .info ("Making conda env" )
270
290
logging .info (makeEnvCommand )
271
291
returnValue = os .system (makeEnvCommand )
272
292
#find path to env's folder and add symlink to meshroom
273
- condaPythonExecudable = subprocess .check_output (_cleanEnvVarsRez ()+ "conda run -n "+ nodeDesc ._envName
293
+ condaPythonExecudable = subprocess .check_output (_cleanEnvVarsRez ()+ condaBin + " run -n "+ nodeDesc ._envName
274
294
+ " python -c \" import sys; print(sys.executable)\" " ,
275
295
shell = True ).strip ().decode ('UTF-8' )
276
296
condaPythonLibFolder = os .path .join (os .path .dirname (condaPythonExecudable ), '..' , 'lib' )
@@ -281,7 +301,7 @@ def build(nodeDesc):
281
301
elif nodeDesc .envType == EnvType .DOCKER :
282
302
#build docker image
283
303
logging .info ("Creating image " + nodeDesc ._envName + " from " + nodeDesc .envFile )
284
- buildCommand = "docker build -f "+ nodeDesc .envFile + " -t " + nodeDesc ._envName + " " + os .path .dirname (nodeDesc .envFile )
304
+ buildCommand = dockerBin + " build -f "+ nodeDesc .envFile + " -t " + nodeDesc ._envName + " " + os .path .dirname (nodeDesc .envFile )
285
305
logging .info ("Building with " + buildCommand + " ..." )
286
306
returnValue = os .system (buildCommand )
287
307
logging .info ("Done" )
@@ -316,9 +336,11 @@ def getCommandLine(chunk):
316
336
envExe = getVenvExe (envPath )
317
337
#make sure meshroom in in pythonpath and that we call the right python
318
338
cmdPrefix = _cleanEnvVarsRez ()+ pythonsetMeshroomPath + " " + envExe + " " + meshroomCompute + " "
339
+ elif nodeDesc .envType == EnvType .REZ :
340
+ cmdPrefix = "rez env " + " " .join (getActiveRezPackages ())+ " " + nodeDesc ._envName + " -- " + meshroomCompute + " "
319
341
elif nodeDesc .envType == EnvType .CONDA :
320
342
#NOTE: system env vars are not passed to conda run, we installed it 'manually' before
321
- cmdPrefix = _cleanEnvVarsRez ()+ " conda run --cwd "+ os .path .join (meshroomFolder , ".." )\
343
+ cmdPrefix = _cleanEnvVarsRez ()+ condaBin + " run --cwd "+ os .path .join (meshroomFolder , ".." )\
322
344
+ " --no-capture-output -n " + nodeDesc ._envName + " " + " python " + meshroomCompute
323
345
elif nodeDesc .envType == EnvType .DOCKER :
324
346
#path to the selected plugin
@@ -337,7 +359,7 @@ def getCommandLine(chunk):
337
359
if chunk .node .nodeDesc .gpu != desc .Level .NONE :
338
360
runtimeArg = "--runtime=nvidia --gpus all"
339
361
#compose cl
340
- cmdPrefix = "docker run -it --rm "+ runtimeArg + " " + mountCommand + " " + envCommand + " " + nodeDesc ._envName + " \" python /meshroomBinDir/meshroom_compute "
362
+ cmdPrefix = dockerBin + " run -it --rm "+ runtimeArg + " " + mountCommand + " " + envCommand + " " + nodeDesc ._envName + " \" python /meshroomBinDir/meshroom_compute "
341
363
meshroomComputeArgs = "--node " + chunk .node .name + " " + chunk .node .graph .filepath + "\" "
342
364
else :
343
365
raise RuntimeError ("NodeType not recognised" )
0 commit comments