1717import webbrowser
1818import subprocess
1919from distutils .version import StrictVersion
20+ from distutils import dir_util
2021
2122from maya import mel
2223from maya import cmds
3132 os .path .join (cmds .internalVar (userScriptDir = True ), 'azure-batch-libs' ))
3233sys .path .append (INSTALL_DIR )
3334
34- REQUIREMENTS = [
35- "pathlib==1.0.1" ,
36- ]
37-
38- NAMESPACE_PACKAGES = [
39- "azure-mgmt-batch==4.0.0" ,
40- "azure-mgmt-storage==1.0.0" ,
41- "azure-common==1.1.5" ,
42- "azure-batch==3.0.0" ,
43- "azure-storage==0.32.0" ,
44- ]
35+ REQUIREMENTS = {
36+ "pathlib==1.0.1" : "pathlib" ,
37+ "msrestazure==0.4.11" : "msrestazure" ,
38+ "azure-common==1.1.8" : "azure.common" ,
39+ }
40+
41+ NAMESPACE_PACKAGES = {
42+ "azure-mgmt-batch==4.0.0" : "azure.mgmt.batch" ,
43+ "azure-mgmt-storage==1.0.0" : "azure.mgmt.storage" ,
44+ "azure-batch==3.0.0" : "azure.batch" ,
45+ "azure-storage==0.32.0" : "azure.storage" ,
46+ "azure-batch-extensions==0.2.0" : "azure.batch_extensions" ,
47+ "futures==3.1.1" : "concurrent.futures"
48+ }
4549
4650VERSION = "0.10.0"
4751EULA_PREF = "AzureBatch_EULA"
@@ -327,20 +331,21 @@ def remove_ui(clientData):
327331 print ("Failed to load" , (str (e )))
328332
329333
330- def dependency_installed (package ):
334+ def dependency_installed (package , namespace ):
331335 """Check if the specified package is installed and up-to-date.
332336 :param str package: A pip-formatted package reference.
333337 """
334338 try :
335339 package_ref = package .split ('==' )
336- module = importlib .import_module (package_ref [ 0 ]. replace ( '-' , '.' ) )
340+ module = importlib .import_module (namespace )
337341 if hasattr (module , '__version__' ) and len (package_ref ) > 1 :
338342 if StrictVersion (package_ref [1 ]) > StrictVersion (getattr (module , '__version__' )):
339343 raise ImportError ("Installed package out of date" )
340- except ImportError :
341- print ("Unable to load {}" .format (package ))
344+ except ImportError as error :
345+ print ("Unable to load {}: {} " .format (package , error ))
342346 return False
343347 else :
348+ print ("Successfully loaded {} from path: {}" .format (package , module .__file__ ))
344349 return True
345350
346351
@@ -351,15 +356,19 @@ def install_pkg(package):
351356 TODO: Check if there's a better way to bypass the verification error.
352357 TODO: Check if this works for package upgrades
353358 """
359+ if not os .path .isdir (INSTALL_DIR ):
360+ os .makedirs (INSTALL_DIR )
354361 pip_cmds = ['mayapy' , os .path .join (INSTALL_DIR , 'pip' ),
355362 'install' , package ,
356363 '--target' , INSTALL_DIR ,
357364 '--index-url' , 'http://pypi.python.org/simple/' ,
358365 '--trusted-host' , 'pypi.python.org' ]
359366 print (pip_cmds )
360- installer = subprocess .Popen (pip_cmds )
367+ installer = subprocess .Popen (pip_cmds , stdout = subprocess . PIPE , stderr = subprocess . PIPE )
361368 installer .wait ()
362369 if installer .returncode != 0 :
370+ print (installer .stdout .read ())
371+ print (installer .stderr .read ())
363372 raise RuntimeError ("Failed to install package: {}" .format (package ))
364373
365374
@@ -372,23 +381,30 @@ def install_namespace_pkg(package, namespace):
372381 :param str namespace: The package namespace to unpack to.
373382 """
374383 temp_target = os .path .join (INSTALL_DIR , 'temp-target' )
384+ if not os .path .isdir (temp_target ):
385+ os .makedirs (temp_target )
375386 pip_cmds = ['mayapy' , os .path .join (INSTALL_DIR , 'pip' ),
376387 'install' , package ,
377388 '--no-deps' ,
378389 '--target' , temp_target ,
379390 '--index-url' , 'http://pypi.python.org/simple/' ,
380391 '--trusted-host' , 'pypi.python.org' ]
381- installer = subprocess .Popen (pip_cmds )
392+ print (pip_cmds )
393+ installer = subprocess .Popen (pip_cmds , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
382394 installer .wait ()
383395 if installer .returncode == 0 :
384396 try :
385- shutil . copytree (os .path .join (temp_target , namespace ), os .path .join (INSTALL_DIR , namespace ))
386- except Exception as e :
387- print (e )
397+ dir_util . copy_tree (os .path .join (temp_target , namespace ), os .path .join (INSTALL_DIR , namespace ))
398+ except Exception as exp :
399+ print (exp )
388400 try :
389401 shutil .rmtree (temp_target )
390- except Exception as e :
391- print (e )
402+ except Exception as exp :
403+ print (exp )
404+ else :
405+ print (installer .stdout .read ())
406+ print (installer .stderr .read ())
407+ raise RuntimeError ("Failed to install package: {}" .format (package ))
392408
393409
394410def initializePlugin (obj ):
@@ -410,11 +426,13 @@ def initializePlugin(obj):
410426
411427 print ("Checking for dependencies..." )
412428 missing_libs = []
429+ python_path = os .environ ['PYTHONPATH' ].lstrip (os .pathsep )
430+ os .environ ['PYTHONPATH' ] = INSTALL_DIR + os .pathsep + python_path
413431 for package in REQUIREMENTS :
414- if not dependency_installed (package ):
432+ if not dependency_installed (package , REQUIREMENTS [ package ] ):
415433 missing_libs .append (package )
416434 for package in NAMESPACE_PACKAGES :
417- if not dependency_installed (package ):
435+ if not dependency_installed (package , NAMESPACE_PACKAGES [ package ] ):
418436 missing_libs .append (package )
419437 if missing_libs :
420438 message = ("One or more dependencies are missing or out-of-date."
@@ -433,22 +451,26 @@ def initializePlugin(obj):
433451
434452 print ("Attempting to install dependencies via Pip." )
435453 try :
436- os .environ ['PYTHONPATH' ] = INSTALL_DIR + os .pathsep + os .environ ['PYTHONPATH' ]
437454 install_script = os .path .normpath (os .path .join ( os .environ ['AZUREBATCH_TOOLS' ], 'install_pip.py' ))
438- installer = subprocess .Popen (["mayapy" , install_script , '--target' , INSTALL_DIR ])
455+ installer = subprocess .Popen (["mayapy" , install_script , '--target' , INSTALL_DIR ],
456+ stdout = subprocess .PIPE , stderr = subprocess .PIPE )
439457 installer .wait ()
440458 if installer .returncode != 0 :
459+ print (installer .stdout .read ())
460+ print (installer .stderr .read ())
441461 raise RuntimeError ("Failed to install pip" )
442462 except BaseException as exp :
443463 print ("Failed to install Pip. Please install dependencies manually to continue." )
444464 raise
445465 try :
446466 print ("Installing dependencies" )
447467 for package in missing_libs :
448- install_pkg (package )
449468 if package in NAMESPACE_PACKAGES :
450- package_path = package . split ( '==' )[ 0 ].split ('- ' )
469+ package_path = NAMESPACE_PACKAGES [ package ].split ('. ' )
451470 install_namespace_pkg (package , os .path .join (* package_path ))
471+ else :
472+ install_pkg (package )
473+ shutil .copy (os .path .join (INSTALL_DIR , 'azure' , '__init__.py' ), os .path .join (INSTALL_DIR , 'azure' , 'mgmt' , '__init__.py' ))
452474 except :
453475 error = "Failed to install dependencies - please install manually"
454476 cmds .confirmDialog (message = error , button = 'OK' )
0 commit comments