30
30
31
31
INSTALL_DIR = os .path .normpath (
32
32
os .path .join (cmds .internalVar (userScriptDir = True ), 'azure-batch-libs' ))
33
- sys .path .append ( INSTALL_DIR )
33
+ sys .path .insert ( 0 , INSTALL_DIR )
34
34
35
35
REQUIREMENTS = {
36
36
"pathlib==1.0.1" : "pathlib" ,
47
47
"azure-batch-extensions==1.0.1" : "azure.batch_extensions"
48
48
}
49
49
50
- VERSION = "0.16 .0"
50
+ VERSION = "0.17 .0"
51
51
EULA_PREF = "AzureBatch_EULA"
52
52
SHELF_FILE = "shelf_AzureBatch.mel"
53
53
cmd_name = "AzureBatch"
@@ -269,6 +269,7 @@ def set_environment(plugin_path):
269
269
sys .path .append (modpath )
270
270
sys .path .append (srcpath )
271
271
sys .path .append (os .path .join (srcpath , "ui" ))
272
+ sys .path .append (tolpath )
272
273
273
274
script_dirs = os .environ ["MAYA_SCRIPT_PATH" ] + os .pathsep
274
275
os .environ ["AZUREBATCH_ICONS" ] = AzureBatchSetup .clean (icnpath )
@@ -349,7 +350,7 @@ def dependency_installed(package, namespace):
349
350
return True
350
351
351
352
352
- def install_pkg (package ):
353
+ def install_pkg (pip , package ):
353
354
"""Install the specified package by shelling out to pip.
354
355
:param str package: A pip-formatted package reference.
355
356
@@ -358,9 +359,7 @@ def install_pkg(package):
358
359
"""
359
360
if not os .path .isdir (INSTALL_DIR ):
360
361
os .makedirs (INSTALL_DIR )
361
- pip_cmds = ['mayapy' , os .path .join (INSTALL_DIR , 'pip' ),
362
- 'install' , package ,
363
- '--target' , INSTALL_DIR ]
362
+ pip_cmds = ['mayapy' , pip , 'install' , package , '--target' , INSTALL_DIR ]
364
363
print (pip_cmds )
365
364
installer = subprocess .Popen (pip_cmds , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
366
365
installer .wait ()
@@ -370,7 +369,7 @@ def install_pkg(package):
370
369
raise RuntimeError ("Failed to install package: {}" .format (package ))
371
370
372
371
373
- def install_namespace_pkg (package , namespace ):
372
+ def install_namespace_pkg (pip , package , namespace ):
374
373
"""Azure packages have issues installing one by one as they don't
375
374
unpackage correctly into the namespace directory. So we have to install
376
375
to a temp directory and move it to the right place.
@@ -381,10 +380,7 @@ def install_namespace_pkg(package, namespace):
381
380
temp_target = os .path .join (INSTALL_DIR , 'temp-target' )
382
381
if not os .path .isdir (temp_target ):
383
382
os .makedirs (temp_target )
384
- pip_cmds = ['mayapy' , os .path .join (INSTALL_DIR , 'pip' ),
385
- 'install' , package ,
386
- '--no-deps' ,
387
- '--target' , temp_target ]
383
+ pip_cmds = ['mayapy' , pip , 'install' , package , '--no-deps' , '--target' , temp_target ]
388
384
print (pip_cmds )
389
385
installer = subprocess .Popen (pip_cmds , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
390
386
installer .wait ()
@@ -447,25 +443,39 @@ def initializePlugin(obj):
447
443
448
444
print ("Attempting to install dependencies via Pip." )
449
445
try :
450
- install_script = os .path .normpath (os .path .join ( os .environ ['AZUREBATCH_TOOLS' ], 'install_pip.py' ))
451
- installer = subprocess .Popen (["mayapy" , install_script , '--target' , INSTALL_DIR ],
452
- stdout = subprocess .PIPE , stderr = subprocess .PIPE )
453
- installer .wait ()
454
- if installer .returncode != 0 :
446
+ import pip
447
+ if StrictVersion (pip .__version__ ) < StrictVersion ("9.0.0" ):
448
+ print ("Found out-of-date pip ({}) - attempting to upgrade." .format (pip .__version__ ))
449
+ raise ImportError
450
+ print ("Found pip installed, version: {}" .format (pip .__version__ ))
451
+ pip_location = os .path .dirname (pip .__file__ )
452
+ except ImportError :
453
+ try :
454
+ import getpip
455
+ print ("Running getpip command" )
456
+ install_script = getpip .__file__
457
+ args = ["mayapy" , install_script , "--target" , INSTALL_DIR ]
458
+ print (args )
459
+ installer = subprocess .Popen (args , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
460
+ installer .wait ()
455
461
print (installer .stdout .read ())
456
462
print (installer .stderr .read ())
457
- raise RuntimeError ("Failed to install pip" )
458
- except BaseException as exp :
459
- print ("Failed to install Pip. Please install dependencies manually to continue." )
460
- raise
463
+ if installer .returncode != 0 :
464
+ raise RuntimeError ("Failed to install pip" )
465
+ except ImportError as e :
466
+ print ("Unable to load getpip" )
467
+ raise
468
+ else :
469
+ print ("Getpip complete" )
470
+ pip_location = os .path .join (INSTALL_DIR , "pip" )
461
471
try :
462
- print ("Installing dependencies" )
472
+ print ("Installing dependencies using {}" . format ( pip_location ) )
463
473
for package in missing_libs :
464
474
if package in NAMESPACE_PACKAGES :
465
475
package_path = NAMESPACE_PACKAGES [package ].split ('.' )
466
- install_namespace_pkg (package , os .path .join (* package_path ))
476
+ install_namespace_pkg (pip_location , package , os .path .join (* package_path ))
467
477
else :
468
- install_pkg (package )
478
+ install_pkg (pip_location , package )
469
479
shutil .copy (os .path .join (INSTALL_DIR , 'azure' , '__init__.py' ), os .path .join (INSTALL_DIR , 'azure' , 'mgmt' , '__init__.py' ))
470
480
except :
471
481
error = "Failed to install dependencies - please install manually"
@@ -521,6 +531,7 @@ def uninitializePlugin(obj):
521
531
try :
522
532
sys .path .extend (os .environ ["AZUREBATCH_SCRIPTS" ].split (os .pathsep ))
523
533
sys .path .append (os .environ ['AZUREBATCH_MODULES' ])
534
+ sys .path .append (os .environ ['AZUREBATCH_TOOLS' ])
524
535
except KeyError as e :
525
536
print ("Couldn't find Azure Batch environment, setting up now..." )
526
537
setup_module ()
0 commit comments