Skip to content

Commit e0577e7

Browse files
committed
When creating a virtualenv for Galaxy, prefer python 2.7.
1 parent eba74e5 commit e0577e7

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

planemo/commands/cmd_virtualenv.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111

1212

1313
@click.command("virtualenv")
14+
@click.option("-p", "--python",
15+
metavar="PYTHON_EXE")
1416
@click.argument("virtualenv_path",
1517
metavar="VIRTUALENV_PATH",
1618
type=VIRTUALENV_PATH_TYPE)
1719
@pass_context
18-
def cli(ctx, virtualenv_path):
20+
def cli(ctx, virtualenv_path, **kwds):
1921
"""Create a virtualenv.
2022
2123
Use virtualenv as library to create a virtualenv for Galaxy if virtualenv
2224
is not available on the PATH.
2325
"""
24-
virtualenv.create_and_exit(virtualenv_path)
26+
virtualenv.create_and_exit(virtualenv_path, **kwds)

planemo/virtualenv.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
from 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

Comments
 (0)