Skip to content

Commit

Permalink
If virtualenv not on PATH, have Planemo create one for Galaxy.
Browse files Browse the repository at this point in the history
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
....
  • Loading branch information
jmchilton committed Nov 20, 2015
1 parent 01584c5 commit 5b97f2e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
24 changes: 24 additions & 0 deletions planemo/commands/cmd_virtualenv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import click

from planemo.cli import pass_context
from planemo import virtualenv

VIRTUALENV_PATH_TYPE = click.Path(
exists=False,
writable=True,
resolve_path=True,
)


@click.command("virtualenv")
@click.argument("virtualenv_path",
metavar="VIRTUALENV_PATH",
type=VIRTUALENV_PATH_TYPE)
@pass_context
def cli(ctx, virtualenv_path):
"""Create a virtualenv.
Use virtualenv as library to create a virtualenv for Galaxy if virtualenv
is not available on the PATH.
"""
virtualenv.create_and_exit(virtualenv_path)
13 changes: 7 additions & 6 deletions planemo/galaxy_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
import string

from planemo.io import info, shell_join
from planemo.virtualenv import create_command
from galaxy.tools.deps.commands import shell


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


def setup_venv(ctx, kwds):
create_template_params = {
'create_virtualenv': create_command("$GALAXY_VIRTUAL_ENV")
}
return shell_join(
locate_galaxy_virtualenv(ctx, kwds),
PRINT_VENV_COMMAND if ctx.verbose else None,
CREATE_COMMAND,
CREATE_COMMAND_TEMPLATE.safe_substitute(create_template_params),
PRINT_VENV_COMMAND if ctx.verbose else None,
ACTIVATE_COMMAND,
)
Expand Down
26 changes: 26 additions & 0 deletions planemo/virtualenv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
""" Utilities for using virtualenv as library and planemo command.
"""
from __future__ import absolute_import

import os
import sys

import virtualenv
from galaxy.tools.deps.commands import which


def create_and_exit(virtualenv_path):
sys.argv = ["virtualenv", virtualenv_path]
return virtualenv.main()


def create_command(virtualenv_path):
""" If virtualenv is on Planemo's path use it, otherwise use the planemo
subcommand virtualenv to create the virtualenv.
"""
planemo_path = os.path.abspath(sys.argv[0])
virtualenv_on_path = which("virtualenv")
if virtualenv_on_path:
return " ".join([os.path.abspath(virtualenv_on_path), virtualenv_path])
else:
return " ".join([planemo_path, "virtualenv", virtualenv_path])
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ docutils
jinja2
glob2
cwltool
virtualenv
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'PyGithub',
'bioblend',
'glob2',
'virtualenv',
]

# Only import cwltool for Python 2.7.
Expand Down

0 comments on commit 5b97f2e

Please sign in to comment.