Permalink
Browse files

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
....
  • Loading branch information...
jmchilton committed Nov 20, 2015
1 parent 01584c5 commit 5b97f2e3c50bad02df770d7d0dc0bea6fa33d553
Showing with 59 additions and 6 deletions.
  1. +24 −0 planemo/commands/cmd_virtualenv.py
  2. +7 −6 planemo/galaxy_run.py
  3. +26 −0 planemo/virtualenv.py
  4. +1 −0 requirements.txt
  5. +1 −0 setup.py
@@ -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)
@@ -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"',
@@ -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,
)
@@ -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])
@@ -6,3 +6,4 @@ docutils
jinja2
glob2
cwltool
virtualenv
@@ -23,6 +23,7 @@
'PyGithub',
'bioblend',
'glob2',
'virtualenv',
]

# Only import cwltool for Python 2.7.

0 comments on commit 5b97f2e

Please sign in to comment.