99from galaxy .tools .deps .commands import which
1010
1111
12- def create_and_exit (virtualenv_path ):
12+ def create_and_exit (virtualenv_path , ** kwds ):
1313 sys .argv = ["virtualenv" , virtualenv_path ]
14+ python = kwds .get ("python" , None )
15+ if python :
16+ sys .argv .extend (["--python" , python ])
1417 return virtualenv .main ()
1518
1619
@@ -21,6 +24,21 @@ def create_command(virtualenv_path):
2124 planemo_path = os .path .abspath (sys .argv [0 ])
2225 virtualenv_on_path = which ("virtualenv" )
2326 if virtualenv_on_path :
24- return " " .join ([os .path .abspath (virtualenv_on_path ), virtualenv_path ])
27+ base_command = [
28+ os .path .abspath (virtualenv_on_path ),
29+ ]
2530 else :
26- return " " .join ([planemo_path , "virtualenv" , virtualenv_path ])
31+ base_command = [
32+ planemo_path , "virtualenv" ,
33+ ]
34+
35+ command = base_command
36+
37+ # If planemo is running in a Python 3 environment but Python 2.7
38+ # is available for Galaxy, use it.
39+ python27 = which ("python2.7" )
40+ if python27 :
41+ python27 = os .path .abspath (python27 )
42+ command .extend (["-p" , python27 ])
43+ command .append (virtualenv_path )
44+ return " " .join (command )
0 commit comments