Skip to content

Commit 5b97f2e

Browse files
committed
If virtualenv not on PATH, have Planemo create one for Galaxy.
http://dev.list.galaxyproject.org/Planemo-0-20-0-and-xunit-td4668334.html $ cd project_templates/demo $ which virtualenv virtualenv not found $ ../../.venv/bin/planemo s cat.xml git --git-dir /home/john/.planemo/gx_repo fetch >/dev/null 2>&1 cd /tmp/tmpfBhxgp; git clone --branch 'dev' '/home/john/.planemo/gx_repo' 'galaxy-dev'; cd galaxy-dev; if [ -d .venv ] || [ -f dist-eggs.ini ]; then GALAXY_VIRTUAL_ENV=.venv; else GALAXY_VIRTUAL_ENV=/home/john/.planemo/gx_venv; fi; export GALAXY_VIRTUAL_ENV; if [ ! -e $GALAXY_VIRTUAL_ENV ]; then /home/john/workspace/planemo/.venv/bin/planemo virtualenv $GALAXY_VIRTUAL_ENV; fi; [ -e $GALAXY_VIRTUAL_ENV ] && . $GALAXY_VIRTUAL_ENV/bin/activate; COMMON_STARTUP_ARGS=; $(grep -q 'skip-venv' run_tests.sh) && COMMON_STARTUP_ARGS="--skip-venv --dev-wheels"; export COMMON_STARTUP_ARGS; echo "Set COMMON_STARTUP_ARGS to ${COMMON_STARTUP_ARGS}"; ./scripts/common_startup.sh ${COMMON_STARTUP_ARGS} Cloning into 'galaxy-dev'... done. Using real prefix '/usr' New python executable in /home/john/.planemo/gx_venv/bin/python Installing setuptools, pip, wheel...done. Set COMMON_STARTUP_ARGS to --skip-venv --dev-wheels ....
1 parent 01584c5 commit 5b97f2e

File tree

5 files changed

+59
-6
lines changed

5 files changed

+59
-6
lines changed

planemo/commands/cmd_virtualenv.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import click
2+
3+
from planemo.cli import pass_context
4+
from planemo import virtualenv
5+
6+
VIRTUALENV_PATH_TYPE = click.Path(
7+
exists=False,
8+
writable=True,
9+
resolve_path=True,
10+
)
11+
12+
13+
@click.command("virtualenv")
14+
@click.argument("virtualenv_path",
15+
metavar="VIRTUALENV_PATH",
16+
type=VIRTUALENV_PATH_TYPE)
17+
@pass_context
18+
def cli(ctx, virtualenv_path):
19+
"""Create a virtualenv.
20+
21+
Use virtualenv as library to create a virtualenv for Galaxy if virtualenv
22+
is not available on the PATH.
23+
"""
24+
virtualenv.create_and_exit(virtualenv_path)

planemo/galaxy_run.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
import string
33

44
from planemo.io import info, shell_join
5+
from planemo.virtualenv import create_command
56
from galaxy.tools.deps.commands import shell
67

78

89
# Activate galaxy's virtualenv if present (needed for tests say but not for
910
# server because run.sh does this).
1011
ACTIVATE_COMMAND = "[ -e $GALAXY_VIRTUAL_ENV ] && . $GALAXY_VIRTUAL_ENV/bin/activate"
11-
CREATE_COMMAND = shell_join(
12-
'if [ ! -e $GALAXY_VIRTUAL_ENV ]',
13-
' then type virtualenv >/dev/null 2>&1 && virtualenv $GALAXY_VIRTUAL_ENV',
14-
' else echo "Reusing existing virtualenv $GALAXY_VIRTUAL_ENV"',
15-
' fi',
12+
CREATE_COMMAND_TEMPLATE = string.Template(
13+
'if [ ! -e $GALAXY_VIRTUAL_ENV ]; then $create_virtualenv; fi',
1614
)
1715
PRINT_VENV_COMMAND = shell_join(
1816
'echo "Set \$GALAXY_VIRTUAL_ENV to $GALAXY_VIRTUAL_ENV"',
@@ -35,10 +33,13 @@
3533

3634

3735
def setup_venv(ctx, kwds):
36+
create_template_params = {
37+
'create_virtualenv': create_command("$GALAXY_VIRTUAL_ENV")
38+
}
3839
return shell_join(
3940
locate_galaxy_virtualenv(ctx, kwds),
4041
PRINT_VENV_COMMAND if ctx.verbose else None,
41-
CREATE_COMMAND,
42+
CREATE_COMMAND_TEMPLATE.safe_substitute(create_template_params),
4243
PRINT_VENV_COMMAND if ctx.verbose else None,
4344
ACTIVATE_COMMAND,
4445
)

planemo/virtualenv.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
""" Utilities for using virtualenv as library and planemo command.
2+
"""
3+
from __future__ import absolute_import
4+
5+
import os
6+
import sys
7+
8+
import virtualenv
9+
from galaxy.tools.deps.commands import which
10+
11+
12+
def create_and_exit(virtualenv_path):
13+
sys.argv = ["virtualenv", virtualenv_path]
14+
return virtualenv.main()
15+
16+
17+
def create_command(virtualenv_path):
18+
""" If virtualenv is on Planemo's path use it, otherwise use the planemo
19+
subcommand virtualenv to create the virtualenv.
20+
"""
21+
planemo_path = os.path.abspath(sys.argv[0])
22+
virtualenv_on_path = which("virtualenv")
23+
if virtualenv_on_path:
24+
return " ".join([os.path.abspath(virtualenv_on_path), virtualenv_path])
25+
else:
26+
return " ".join([planemo_path, "virtualenv", virtualenv_path])

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ docutils
66
jinja2
77
glob2
88
cwltool
9+
virtualenv

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'PyGithub',
2424
'bioblend',
2525
'glob2',
26+
'virtualenv',
2627
]
2728

2829
# Only import cwltool for Python 2.7.

0 commit comments

Comments
 (0)