Skip to content

Commit

Permalink
Allow selection of python version when starting managed Galaxy
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Sep 29, 2018
1 parent 911ac8c commit f1b9c9d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
10 changes: 8 additions & 2 deletions planemo/galaxy/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from six.moves import shlex_quote

from planemo.io import info, shell_join
from planemo.virtualenv import create_command
from planemo.virtualenv import (
create_command,
DEFAULT_PYTHON_VERSION,
)


# Activate galaxy's virtualenv if present (needed for tests say but not for
Expand Down Expand Up @@ -39,7 +42,7 @@ def setup_venv(ctx, kwds):
return ""

create_template_params = {
'create_virtualenv': create_command("$GALAXY_VIRTUAL_ENV")
'create_virtualenv': create_command("$GALAXY_VIRTUAL_ENV", kwds.get('galaxy_python_version', None))
}
return shell_join(
locate_galaxy_virtualenv(ctx, kwds),
Expand All @@ -55,6 +58,9 @@ def locate_galaxy_virtualenv(ctx, kwds):
workspace = ctx.workspace
galaxy_branch = kwds.get("galaxy_branch") or "master"
shared_venv_path = os.path.join(workspace, "gx_venv")
galaxy_python_version = kwds.get('galaxy_python_version', DEFAULT_PYTHON_VERSION)
if galaxy_python_version != DEFAULT_PYTHON_VERSION:
shared_venv_path = "%s_%s" % (shared_venv_path, galaxy_python_version)
if galaxy_branch != "master":
shared_venv_path = "%s_%s" % (shared_venv_path, galaxy_branch)
venv_command = CACHED_VIRTUAL_ENV_COMMAND % shlex_quote(shared_venv_path)
Expand Down
11 changes: 11 additions & 0 deletions planemo/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ def galaxy_email_option():
)


def galaxy_python_version():
return planemo_option(
'--galaxy_python_version',
use_global_config=True,
default='2.7',
type=click.Choice(['2', '2.7', '3', '3.3', '3.4', '3.5', '3.6', '3.7']),
help="Python version to start Galaxy under",
)


def galaxy_root_option():
return planemo_option(
"--galaxy_root",
Expand Down Expand Up @@ -1059,6 +1069,7 @@ def galaxy_config_options():
def galaxy_target_options():
return _compose(
galaxy_root_option(),
galaxy_python_version(),
galaxy_database_seed_option(),
extra_tools_option(),
install_galaxy_option(),
Expand Down
19 changes: 12 additions & 7 deletions planemo/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from galaxy.tools.deps.commands import which


DEFAULT_PYTHON_VERSION = "2.7"


def create_and_exit(virtualenv_path, **kwds):
sys.argv = ["virtualenv", virtualenv_path]
python = kwds.get("python", None)
Expand All @@ -17,7 +20,7 @@ def create_and_exit(virtualenv_path, **kwds):
return virtualenv.main()


def create_command(virtualenv_path):
def create_command(virtualenv_path, galaxy_python_version=None):
""" If virtualenv is on Planemo's path use it, otherwise use the planemo
subcommand virtualenv to create the virtualenv.
"""
Expand All @@ -34,11 +37,13 @@ def create_command(virtualenv_path):

command = base_command

# If planemo is running in a Python 3 environment but Python 2.7
# is available for Galaxy, use it.
python27 = which("python2.7")
if python27:
python27 = os.path.abspath(python27)
command.extend(["-p", python27])
# Create a virtualenv with the selected python version.
# default to 2.7
if galaxy_python_version is None:
galaxy_python_version = DEFAULT_PYTHON_VERSION
python = which("python%s" % galaxy_python_version)
if python:
python = os.path.abspath(python)
command.extend(["-p", python])
command.append(virtualenv_path)
return " ".join(command)
7 changes: 7 additions & 0 deletions tests/test_cmd_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
PROJECT_TEMPLATES_DIR,
skip_if_environ,
skip_unless_environ,
skip_unless_executable,
target_galaxy_branch,
TEST_DATA_DIR,
TEST_REPOS_DIR,
Expand All @@ -28,6 +29,12 @@ class ServeTestCase(CliTestCase):
def test_serve(self):
self._launch_thread_and_wait(self._run)

@skip_if_environ("PLANEMO_SKIP_GALAXY_TEST")
@skip_unless_executable("python3")
def test_serve_python3(self):
extra_args = ['--galaxy_python_version', '3', '--galaxy_branch', 'release_18.09']
self._launch_thread_and_wait(self._run, extra_args)

@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS")
@mark.tests_galaxy_branch
def test_serve_daemon(self):
Expand Down

0 comments on commit f1b9c9d

Please sign in to comment.