Skip to content

Commit 60afd8b

Browse files
authored
Merge pull request #989 from nsoranzo/shell_without_shell_True
Reduce use of `shell=True` in subprocesses
2 parents 526ed74 + 8d030d6 commit 60afd8b

File tree

5 files changed

+19
-27
lines changed

5 files changed

+19
-27
lines changed

planemo/commands/cmd_travis_before_install.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
def cli(ctx):
2222
"""Internal command for GitHub/TravisCI testing.
2323
24-
This command is used internally by planemo to assist in contineous testing
24+
This command is used internally by planemo to assist in continuous testing
2525
of tools with Travis CI (https://travis-ci.org/).
2626
"""
2727
build_dir = os.environ.get("TRAVIS_BUILD_DIR", None)
@@ -58,7 +58,6 @@ def cli(ctx):
5858
shell(['sudo', 'dpkg', '-i', SAMTOOLS_DEB])
5959
setup_file = os.path.join(build_travis_dir, SETUP_FILE_NAME)
6060
if os.path.exists(setup_file):
61-
shell(
62-
". %s && bash -x %s" % (build_env_path, setup_file),
63-
env=template_vars
64-
)
61+
env = template_vars
62+
env['PATH'] = build_bin_dir
63+
shell(['bash', '-x', setup_file], env=env)

planemo/galaxy/config.py

+7-14
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
kill_pid_file,
3030
shell,
3131
shell_join,
32+
untar_to,
3233
wait_on,
3334
warn,
3435
write_file,
@@ -185,11 +186,6 @@ class = StreamHandler
185186
DEFAULT_GALAXY_SOURCE = "https://github.com/galaxyproject/galaxy"
186187
CWL_GALAXY_SOURCE = "https://github.com/common-workflow-language/galaxy"
187188

188-
# TODO: Mac-y curl variant of this.
189-
DOWNLOAD_GALAXY = (
190-
"wget -q https://codeload.github.com/galaxyproject/galaxy/tar.gz/"
191-
)
192-
193189
DATABASE_LOCATION_TEMPLATE = "sqlite:///%s?isolation_level=IMMEDIATE"
194190

195191
COMMAND_STARTUP_COMMAND = "./scripts/common_startup.sh ${COMMON_STARTUP_ARGS}"
@@ -1082,18 +1078,17 @@ def _install_galaxy(ctx, galaxy_root, env, kwds):
10821078

10831079

10841080
def _install_galaxy_via_download(ctx, galaxy_root, env, kwds):
1085-
tmpdir = mkdtemp()
10861081
branch = _galaxy_branch(kwds)
1087-
command = DOWNLOAD_GALAXY + "%s -O - | tar -C '%s' -xvz | tail && mv '%s' '%s'" % \
1088-
(branch, tmpdir, os.path.join(tmpdir, 'galaxy-' + branch), galaxy_root)
1089-
_install_with_command(ctx, command, galaxy_root, env, kwds)
1082+
untar_to("https://codeload.github.com/galaxyproject/galaxy/tar.gz/" + branch, tar_args=['-xvzf', '-', 'galaxy-' + branch], dest_dir=galaxy_root)
1083+
_install_with_command(ctx, galaxy_root, env, kwds)
10901084

10911085

10921086
def _install_galaxy_via_git(ctx, galaxy_root, env, kwds):
10931087
gx_repo = _ensure_galaxy_repository_available(ctx, kwds)
10941088
branch = _galaxy_branch(kwds)
10951089
command = git.command_clone(ctx, gx_repo, galaxy_root, branch=branch)
1096-
_install_with_command(ctx, command, galaxy_root, env, kwds)
1090+
shell(command, env=env)
1091+
_install_with_command(ctx, galaxy_root, env, kwds)
10971092

10981093

10991094
def _build_eggs_cache(ctx, env, kwds):
@@ -1128,17 +1123,15 @@ def _galaxy_source(kwds):
11281123
return source
11291124

11301125

1131-
def _install_with_command(ctx, command, galaxy_root, env, kwds):
1126+
def _install_with_command(ctx, galaxy_root, env, kwds):
11321127
setup_venv_command = setup_venv(ctx, kwds)
11331128
env['__PYVENV_LAUNCHER__'] = ''
11341129
install_cmd = shell_join(
1135-
command,
1136-
['cd', galaxy_root],
11371130
setup_venv_command,
11381131
setup_common_startup_args(),
11391132
COMMAND_STARTUP_COMMAND,
11401133
)
1141-
shell(install_cmd, env=env)
1134+
shell(install_cmd, cwd=galaxy_root, env=env)
11421135

11431136

11441137
def _ensure_galaxy_repository_available(ctx, kwds):

planemo/git.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ def rev(ctx, directory):
109109

110110
def is_rev_dirty(ctx, directory):
111111
"""Check if specified git repository has uncommitted changes."""
112-
# TODO: Use ENV instead of cd.
113-
cmd = "cd '%s' && git diff --quiet" % directory
114-
return io.shell(cmd) != 0
112+
return io.shell(['git', 'diff', '--quiet'], cwd=directory) != 0
115113

116114

117115
def rev_if_git(ctx, directory):

planemo/io.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ def untar_to(url, tar_args=None, path=None, dest_dir=None):
103103
if dest_dir:
104104
if not os.path.exists(dest_dir):
105105
os.makedirs(dest_dir)
106-
tar_args.extend(['-C', dest_dir])
106+
tar_args[0:0] = ['-C', dest_dir]
107107
if path:
108-
tar_args.append('-O')
108+
tar_args.insert(0, '-O')
109109

110110
download_cmd = download_command(url)
111111
download_p = commands.shell_process(download_cmd, stdout=subprocess.PIPE)

planemo/shed/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,12 @@ def _diff_in(ctx, working, realized_repository, **kwds):
415415
else:
416416
xml_diff = diff_and_remove(working, label_a, label_b, sys.stdout)
417417

418-
cmd = 'cd "%s"; diff -r %s %s' % (working, label_a, label_b)
418+
cmd = ['diff', '-r', label_a, label_b]
419419
if output:
420-
cmd += " >> '%s'" % output
421-
raw_diff = shell(cmd)
420+
with open(output, 'ab') as fh:
421+
raw_diff = shell(cmd, cwd=working, stdout=fh)
422+
else:
423+
raw_diff = shell(cmd, cwd=working)
422424
exit = raw_diff or xml_diff
423425
if not raw:
424426
if xml_diff:

0 commit comments

Comments
 (0)