Skip to content

Commit 434099e

Browse files
committed
Fix planemo test when TEMP env variable contain spaces
Reported by @pvanheus.
1 parent 48f6c18 commit 434099e

5 files changed

Lines changed: 47 additions & 51 deletions

File tree

planemo/galaxy/config.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
add_metaclass,
1818
iteritems
1919
)
20+
from six.moves import shlex_quote
2021

2122
from planemo import git
2223
from planemo.config import OptionSource
@@ -198,8 +199,6 @@ class = StreamHandler
198199

199200
DATABASE_LOCATION_TEMPLATE = "sqlite:///%s?isolation_level=IMMEDIATE"
200201

201-
PIP_INSTALL_CMD = "pip install %s"
202-
203202
COMMAND_STARTUP_COMMAND = "./scripts/common_startup.sh ${COMMON_STARTUP_ARGS}"
204203

205204
FAILED_TO_FIND_GALAXY_EXCEPTION = (
@@ -934,16 +933,15 @@ def startup_command(self, ctx, **kwds):
934933
daemon = kwds.get("daemon", False)
935934
# TODO: Allow running dockerized Galaxy here instead.
936935
setup_venv_command = setup_venv(ctx, kwds)
937-
run_script = os.path.join(self.galaxy_root, "run.sh")
938-
run_script += " $COMMON_STARTUP_ARGS"
936+
run_script = "%s $COMMON_STARTUP_ARGS" % shlex_quote(os.path.join(self.galaxy_root, "run.sh"))
939937
if daemon:
940938
run_script += " --daemon"
941939
self.env["GALAXY_RUN_ALL"] = "1"
942940
else:
943-
run_script += " --server-name '%s'" % self.server_name
941+
run_script += " --server-name %s" % shlex_quote(self.server_name)
944942
server_ini = os.path.join(self.config_directory, "galaxy.ini")
945943
self.env["GALAXY_CONFIG_FILE"] = server_ini
946-
cd_to_galaxy_command = "cd %s" % self.galaxy_root
944+
cd_to_galaxy_command = ['cd', self.galaxy_root]
947945
return shell_join(
948946
cd_to_galaxy_command,
949947
setup_venv_command,
@@ -1238,14 +1236,14 @@ def _install_with_command(ctx, config_directory, command, env, kwds):
12381236
# TODO: --watchdog
12391237
pip_installs = []
12401238
if pip_installs:
1241-
pip_install_command = PIP_INSTALL_CMD % " ".join(pip_installs)
1239+
pip_install_command = ['pip', 'install'] + pip_installs
12421240
else:
12431241
pip_install_command = ""
12441242
setup_venv_command = setup_venv(ctx, kwds)
12451243
install_cmd = shell_join(
1246-
"cd %s" % config_directory,
1244+
['cd', config_directory],
12471245
command,
1248-
"cd galaxy-dev",
1246+
['cd', 'galaxy-dev'],
12491247
setup_venv_command,
12501248
pip_install_command,
12511249
setup_common_startup_args(),

planemo/galaxy/run.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
import string
44

55
from galaxy.tools.deps.commands import shell
6+
from six.moves import shlex_quote
67

78
from planemo.io import info, shell_join
89
from planemo.virtualenv import create_command
910

1011

1112
# Activate galaxy's virtualenv if present (needed for tests say but not for
1213
# server because run.sh does this).
13-
ACTIVATE_COMMAND = "[ -e $GALAXY_VIRTUAL_ENV ] && . $GALAXY_VIRTUAL_ENV/bin/activate"
14+
ACTIVATE_COMMAND = '[ -e "$GALAXY_VIRTUAL_ENV" ] && . "$GALAXY_VIRTUAL_ENV"/bin/activate'
1415
CREATE_COMMAND_TEMPLATE = string.Template(
15-
'if [ ! -e $GALAXY_VIRTUAL_ENV ]; then $create_virtualenv; fi',
16+
'if [ ! -e "$GALAXY_VIRTUAL_ENV" ]; then $create_virtualenv; fi',
1617
)
1718
PRINT_VENV_COMMAND = shell_join(
1819
'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',
20+
('if [ -e "$GALAXY_VIRTUAL_ENV" ]; ',
21+
'then echo "Virtual environment directory exists."; ',
22+
'else echo "Virtual environment directory does not exist."; fi'),
2323
)
2424

2525

@@ -28,9 +28,9 @@
2828
"wget https://codeload.github.com/galaxyproject/galaxy/tar.gz/"
2929
)
3030

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")
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")
3434
UNCACHED_VIRTUAL_ENV_COMMAND = "GALAXY_VIRTUAL_ENV=.venv"
3535

3636

@@ -57,7 +57,7 @@ def locate_galaxy_virtualenv(ctx, kwds):
5757
shared_venv_path = os.path.join(workspace, "gx_venv")
5858
if galaxy_branch != "master":
5959
shared_venv_path = "%s_%s" % (shared_venv_path, galaxy_branch)
60-
venv_command = CACHED_VIRTUAL_ENV_COMMAND % shared_venv_path
60+
venv_command = CACHED_VIRTUAL_ENV_COMMAND % shlex_quote(shared_venv_path)
6161
else:
6262
venv_command = UNCACHED_VIRTUAL_ENV_COMMAND
6363
return shell_join(

planemo/galaxy/test/actions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def run_in_config(ctx, config, run=run_galaxy_command, **kwds):
6464
config.env["GALAXY_TEST_VERBOSE_ERRORS"] = "true"
6565
config.env["GALAXY_TEST_SAVE"] = job_output_files
6666

67-
cd_to_galaxy_command = "cd %s" % config.galaxy_root
67+
cd_to_galaxy_command = ['cd', config.galaxy_root]
6868
test_cmd = test_structures.GalaxyTestCommand(
6969
html_report_file,
7070
xunit_report_file,
@@ -74,9 +74,9 @@ def run_in_config(ctx, config, run=run_galaxy_command, **kwds):
7474
).build()
7575
setup_common_startup_args = ""
7676
if kwds.get("skip_venv", False):
77-
setup_common_startup_args = (
78-
'COMMON_STARTUP_ARGS=--skip-venv; '
79-
'export COMMON_STARTUP_ARGS; '
77+
setup_common_startup_args = shell_join(
78+
'COMMON_STARTUP_ARGS=--skip-venv'
79+
'export COMMON_STARTUP_ARGS'
8080
'echo "Set COMMON_STARTUP_ARGS to ${COMMON_STARTUP_ARGS}"'
8181
)
8282
setup_venv_command = setup_venv(ctx, kwds)

planemo/galaxy/test/structures.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
from collections import namedtuple
77
from xml.etree import ElementTree as ET
88

9+
from six.moves import shlex_quote
10+
911
from planemo.io import error
1012
from planemo.test.results import StructuredData as BaseStructuredData
1113

1214

13-
RUN_TESTS_CMD = (
14-
"sh run_tests.sh $COMMON_STARTUP_ARGS --report_file %s %s %s %s"
15-
)
16-
1715
NO_STRUCTURED_FILE = (
1816
"Warning: Problem with target Galaxy, it did not "
1917
"produce a structured test results file [%s] - summary "
@@ -41,24 +39,20 @@ def __init__(
4139
def build(self):
4240
xunit_report_file = self.xunit_report_file
4341
sd_report_file = self.structured_report_file
44-
html_report_file = self.html_report_file
42+
cmd = "sh run_tests.sh $COMMON_STARTUP_ARGS --report_file %s" % shlex_quote(self.html_report_file)
4543
if xunit_report_file:
46-
xunit_arg = "--xunit_report_file %s" % xunit_report_file
47-
else:
48-
xunit_arg = ""
44+
cmd += " --xunit_report_file %s" % shlex_quote(xunit_report_file)
4945
if sd_report_file:
50-
sd_arg = "--structured_data_report_file %s" % sd_report_file
51-
else:
52-
sd_arg = ""
46+
cmd += " --structured_data_report_file %s" % shlex_quote(sd_report_file)
5347
if self.installed:
54-
tests = "-installed"
48+
cmd += ' -installed'
49+
elif self.failed:
50+
sd = StructuredData(sd_report_file)
51+
tests = " ".join(sd.failed_ids)
52+
cmd += " %s" % tests
5553
else:
56-
tests = "functional.test_toolbox"
57-
if self.failed:
58-
sd = StructuredData(self.structured_report_file)
59-
failed_ids = sd.failed_ids
60-
tests = " ".join(failed_ids)
61-
return RUN_TESTS_CMD % (html_report_file, xunit_arg, sd_arg, tests)
54+
cmd += ' functional.test_toolbox'
55+
return cmd
6256

6357

6458
class StructuredData(BaseStructuredData):

planemo/io.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
import click
1616
from galaxy.tools.deps import commands
1717
from galaxy.tools.deps.commands import download_command
18-
from six import StringIO
18+
from six import (
19+
string_types,
20+
StringIO
21+
)
1922

2023
from .exit_codes import (
2124
EXIT_CODE_NO_SUCH_TARGET,
@@ -26,11 +29,15 @@
2629
IS_OS_X = _platform == "darwin"
2730

2831

29-
def communicate(cmds, **kwds):
30-
if isinstance(cmds, list):
31-
cmd_string = commands.argv_to_str(cmds)
32+
def args_to_str(args):
33+
if args is None or isinstance(args, string_types):
34+
return args
3235
else:
33-
cmd_string = cmds
36+
return commands.argv_to_str(args)
37+
38+
39+
def communicate(cmds, **kwds):
40+
cmd_string = args_to_str(cmds)
3441
info(cmd_string)
3542
p = commands.shell_process(cmds, **kwds)
3643
if kwds.get("stdout", None) is None and commands.redirecting_io(sys=sys):
@@ -46,10 +53,7 @@ def communicate(cmds, **kwds):
4653

4754

4855
def shell(cmds, **kwds):
49-
if isinstance(cmds, list):
50-
cmd_string = commands.argv_to_str(cmds)
51-
else:
52-
cmd_string = cmds
56+
cmd_string = args_to_str(cmds)
5357
info(cmd_string)
5458
return commands.shell(cmds, **kwds)
5559

@@ -81,7 +85,7 @@ def warn(message, *args):
8185

8286
def shell_join(*args):
8387
"""Join potentially empty commands together with ;."""
84-
return "; ".join([c for c in args if c])
88+
return "; ".join(args_to_str(_) for _ in args if _)
8589

8690

8791
def write_file(path, content, force=True):

0 commit comments

Comments
 (0)