Skip to content

Commit 25ef0d5

Browse files
committed
Update planemo for Galaxy wheels.
That got out of hand quickly.
1 parent cbc2806 commit 25ef0d5

File tree

6 files changed

+115
-22
lines changed

6 files changed

+115
-22
lines changed

planemo/galaxy_config.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from planemo import galaxy_run
1717
from planemo.io import warn
1818
from planemo.io import shell
19+
from planemo.io import shell_join
1920
from planemo.io import write_file
2021
from planemo.io import kill_pid_file
2122
from planemo.io import wait_on
@@ -92,7 +93,9 @@
9293
DOWNLOADABLE_MIGRATION_VERSIONS = [127, 120, 117]
9394
LATEST_URL = DOWNLOADS_URL + "latest.sqlite"
9495

95-
PIP_INSTALL_CMD = "[ -d .venv ] && . .venv/bin/activate && pip install %s"
96+
PIP_INSTALL_CMD = "pip install %s"
97+
98+
COMMAND_STARTUP_COMMAND = "./scripts/common_startup.sh ${COMMON_STARTUP_ARGS}"
9699

97100
FAILED_TO_FIND_GALAXY_EXCEPTION = (
98101
"Failed to find Galaxy root directory - please explicitly specify one "
@@ -523,21 +526,21 @@ def _install_galaxy(ctx, config_directory, kwds):
523526
if not kwds.get("no_cache_galaxy", False):
524527
_install_galaxy_via_git(ctx, config_directory, kwds)
525528
else:
526-
_install_galaxy_via_download(config_directory, kwds)
529+
_install_galaxy_via_download(ctx, config_directory, kwds)
527530

528531

529-
def _install_galaxy_via_download(config_directory, kwds):
532+
def _install_galaxy_via_download(ctx, config_directory, kwds):
530533
branch = _galaxy_branch(kwds)
531534
tar_cmd = "tar -zxvf %s" % branch
532535
command = galaxy_run.DOWNLOAD_GALAXY + "; %s | tail" % tar_cmd
533-
_install_with_command(config_directory, command, kwds)
536+
_install_with_command(ctx, config_directory, command, kwds)
534537

535538

536539
def _install_galaxy_via_git(ctx, config_directory, kwds):
537540
gx_repo = _ensure_galaxy_repository_available(ctx, kwds)
538541
branch = _galaxy_branch(kwds)
539542
command = git.command_clone(ctx, gx_repo, "galaxy-dev", branch=branch)
540-
_install_with_command(config_directory, command, kwds)
543+
_install_with_command(ctx, config_directory, command, kwds)
541544

542545

543546
def _build_eggs_cache(ctx, env, kwds):
@@ -557,7 +560,7 @@ def _galaxy_branch(kwds):
557560
return branch
558561

559562

560-
def _install_with_command(config_directory, command, kwds):
563+
def _install_with_command(ctx, config_directory, command, kwds):
561564
# TODO: --watchdog
562565
pip_installs = []
563566
if kwds.get("cwl", False):
@@ -566,15 +569,17 @@ def _install_with_command(config_directory, command, kwds):
566569
pip_install_command = PIP_INSTALL_CMD % " ".join(pip_installs)
567570
else:
568571
pip_install_command = ""
569-
install_cmds = [
572+
setup_venv_command = galaxy_run.setup_venv(ctx, kwds)
573+
install_cmd = shell_join(
570574
"cd %s" % config_directory,
571575
command,
572576
"cd galaxy-dev",
573-
"type virtualenv >/dev/null 2>&1 && virtualenv .venv",
577+
setup_venv_command,
574578
pip_install_command,
575-
galaxy_run.ACTIVATE_COMMAND,
576-
]
577-
shell(";".join([c for c in install_cmds if c]))
579+
galaxy_run.setup_common_startup_args(),
580+
COMMAND_STARTUP_COMMAND,
581+
)
582+
shell(install_cmd)
578583

579584

580585
def _ensure_galaxy_repository_available(ctx, kwds):

planemo/galaxy_run.py

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,88 @@
1-
from planemo.io import info
1+
import os
2+
import string
3+
4+
from planemo.io import info, shell_join
25
from galaxy.tools.deps.commands import shell
36

47

58
# Activate galaxy's virtualenv if present (needed for tests say but not for
69
# server because run.sh does this).
7-
ACTIVATE_COMMAND = "[ -e .venv ] && . .venv/bin/activate"
10+
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',
16+
)
17+
PRINT_VENV_COMMAND = shell_join(
18+
'echo "Set \$GALAXY_VIRTUAL_ENV to $GALAXY_VIRTUAL_ENV"',
19+
'if [ -e $GALAXY_VIRTUAL_ENV ]',
20+
'then echo "Virtual environment directory exists."',
21+
'else echo "Virtual environment directory does not exist."',
22+
'fi',
23+
)
24+
825

926
# TODO: Mac-y curl variant of this.
1027
DOWNLOAD_GALAXY = (
1128
"wget https://codeload.github.com/galaxyproject/galaxy/tar.gz/dev"
1229
)
1330

31+
CACHED_VIRTUAL_ENV_COMMAND = ("if [ -d .venv ] || [ -f dist-eggs.ini ];"
32+
" then GALAXY_VIRTUAL_ENV=.venv; "
33+
" else GALAXY_VIRTUAL_ENV=%s; fi")
34+
UNCACHED_VIRTUAL_ENV_COMMAND = "GALAXY_VIRTUAL_ENV=.venv"
35+
36+
37+
def setup_venv(ctx, kwds):
38+
return shell_join(
39+
locate_galaxy_virtualenv(ctx, kwds),
40+
PRINT_VENV_COMMAND if ctx.verbose else None,
41+
CREATE_COMMAND,
42+
PRINT_VENV_COMMAND if ctx.verbose else None,
43+
ACTIVATE_COMMAND,
44+
)
45+
46+
47+
def locate_galaxy_virtualenv(ctx, kwds):
48+
if not kwds.get("no_cache_galaxy", False):
49+
workspace = ctx.workspace
50+
shared_venv_path = os.path.join(workspace, "gx_venv")
51+
venv_command = CACHED_VIRTUAL_ENV_COMMAND % shared_venv_path
52+
else:
53+
venv_command = UNCACHED_VIRTUAL_ENV_COMMAND
54+
return shell_join(
55+
venv_command,
56+
"export GALAXY_VIRTUAL_ENV",
57+
)
58+
59+
60+
def shell_if_wheels(command):
61+
""" Take a shell command and convert it to shell command that runs
62+
only if Galaxy is new enough to use wheels.
63+
"""
64+
return "$(grep -q 'skip-venv' run_tests.sh) && %s" % command
65+
66+
67+
def setup_common_startup_args():
68+
return set_variable_if_wheels(
69+
"COMMON_STARTUP_ARGS", "--skip-venv --dev-wheels"
70+
)
71+
72+
73+
def set_variable_if_wheels(var, if_wheels_val, else_val=""):
74+
var_command = '${var}=${else_val}; '
75+
var_command += shell_if_wheels(
76+
'${var}="${if_wheels_val}"; '
77+
)
78+
var_command += "export ${var}"
79+
var_command += '; echo "Set ${var} to ${${var}}"'
80+
return string.Template(var_command).safe_substitute(
81+
var=var,
82+
if_wheels_val=if_wheels_val,
83+
else_val=else_val,
84+
)
85+
1486

1587
def run_galaxy_command(ctx, command, env, action, daemon=False):
1688
message = "%s with command [%s]" % (action, command)

planemo/galaxy_serve.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,26 @@ def serve(ctx, paths, **kwds):
1717

1818
with galaxy_config.galaxy_config(ctx, paths, **kwds) as config:
1919
# TODO: Allow running dockerized Galaxy here instead.
20+
setup_common_startup_args = galaxy_run.set_variable_if_wheels(
21+
"COMMON_STARTUP_ARGS", "--skip-venv"
22+
)
23+
setup_venv_command = galaxy_run.setup_venv(ctx, kwds)
2024
run_script = os.path.join(config.galaxy_root, "run.sh")
25+
run_script += " $COMMON_STARTUP_ARGS"
2126
if daemon:
2227
run_script += " --daemon --wait"
2328
config.env["GALAXY_RUN_ALL"] = "1"
2429
else:
2530
run_script += " --server-name '%s' --reload" % config.server_name
2631
server_ini = os.path.join(config.config_directory, "galaxy.ini")
2732
config.env["GALAXY_CONFIG_FILE"] = server_ini
28-
cmds = [
33+
cd_to_galaxy_command = "cd %s" % config.galaxy_root
34+
cmd = io.shell_join(
35+
cd_to_galaxy_command,
36+
setup_common_startup_args,
37+
setup_venv_command,
2938
run_script,
30-
]
31-
cmd = "; ".join(cmds)
39+
)
3240
action = "Starting galaxy"
3341
galaxy_run.run_galaxy_command(
3442
ctx,

planemo/galaxy_test/actions.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import click
44

55
from . import structures as test_structures
6-
from planemo.io import info, warn
6+
from planemo.io import info, warn, shell_join
77
from planemo import galaxy_run
88
from planemo.reports import build_report
99

@@ -51,12 +51,16 @@ def run_in_config(ctx, config, **kwds):
5151
failed=kwds.get("failed", False),
5252
installed=kwds.get("installed", False),
5353
).build()
54-
cmd = "; ".join([
54+
setup_common_startup_args = galaxy_run.set_variable_if_wheels(
55+
"COMMON_STARTUP_ARGS", "--skip-venv --skip-common-startup"
56+
)
57+
setup_venv_command = galaxy_run.setup_venv(ctx, kwds)
58+
cmd = shell_join(
5559
cd_to_galaxy_command,
56-
galaxy_run.ACTIVATE_COMMAND, # TODO: this should be moved to
57-
# run_tests.sh to match run.sh.
60+
setup_common_startup_args,
61+
setup_venv_command,
5862
test_cmd,
59-
])
63+
)
6064
action = "Testing tools"
6165
return_code = galaxy_run.run_galaxy_command(
6266
ctx,

planemo/galaxy_test/structures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from planemo.io import error
1111

1212
RUN_TESTS_CMD = (
13-
"sh run_tests.sh --report_file %s %s %s %s"
13+
"sh run_tests.sh $COMMON_STARTUP_ARGS --report_file %s %s %s %s"
1414
)
1515

1616

planemo/io.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ def _echo(message, err=False):
6767
print(message)
6868

6969

70+
def shell_join(*args):
71+
return "; ".join([c for c in args if c])
72+
73+
7074
def write_file(path, content):
7175
with open(path, "w") as f:
7276
f.write(content)

0 commit comments

Comments
 (0)