Skip to content

Commit d755fe7

Browse files
committed
Enable caching on --install_galaxy by default.
It now clones Galaxy on the first use to ~/.planemo/gx_repo and fetches updates on subsequent uses. Added new option --no_cache_galaxy to use the previous speedier download option (more appropriate for one time use). Eggs are still downloaded each time - and probably take longer(?).
1 parent 39fedd2 commit d755fe7

File tree

9 files changed

+89
-17
lines changed

9 files changed

+89
-17
lines changed

planemo/cli.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@
2525
class Context(object):
2626

2727
def __init__(self):
28-
self.verbose = False
2928
self.home = os.getcwd()
3029
self._global_config = None
30+
# Will be set by planemo CLI driver
31+
self.verbose = False
32+
self.planemo_config = None
33+
self.planemo_directory = None
3134

3235
@property
3336
def global_config(self):
3437
if self._global_config is None:
35-
self._global_config = read_global_config()
38+
self._global_config = read_global_config(self.planemo_config)
3639
return self._global_config
3740

3841
def log(self, msg, *args):
@@ -46,6 +49,19 @@ def vlog(self, msg, *args):
4649
if self.verbose:
4750
self.log(msg, *args)
4851

52+
@property
53+
def workspace(self):
54+
if not self.planemo_directory:
55+
raise Exception("No planemo workspace defined.")
56+
workspace = self.planemo_directory
57+
if not os.path.exists(workspace):
58+
os.makedirs(workspace)
59+
if not os.path.isdir(workspace):
60+
template = "Planemo workspace directory [%s] unavailable."
61+
message = template % workspace
62+
raise Exception(message)
63+
return workspace
64+
4965

5066
pass_context = click.make_pass_decorator(Context, ensure=True)
5167
cmd_folder = os.path.abspath(os.path.join(os.path.dirname(__file__),
@@ -89,7 +105,15 @@ def get_command(self, ctx, name):
89105
@click.version_option(__version__)
90106
@click.option('-v', '--verbose', is_flag=True,
91107
help='Enables verbose mode.')
108+
@click.option('--config',
109+
default="~/.planemo.yml",
110+
help="Planemo configuration YAML file.")
111+
@click.option('--directory',
112+
default="~/.planemo",
113+
help="Workspace for planemo.")
92114
@pass_context
93-
def planemo(ctx, verbose):
115+
def planemo(ctx, config, directory, verbose):
94116
"""Utilities to assist with the development of Galaxy tools."""
95117
ctx.verbose = verbose
118+
ctx.planemo_config = os.path.expanduser(config)
119+
ctx.planemo_directory = os.path.expanduser(directory)

planemo/commands/cmd_serve.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@options.optional_tools_arg()
1010
@options.galaxy_root_option()
1111
@options.install_galaxy_option()
12+
@options.no_cache_galaxy_option()
1213
@options.no_cleanup_option()
1314
@options.test_data_option()
1415
@options.dependency_resolvers_option()

planemo/commands/cmd_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
)
8585
@options.galaxy_root_option()
8686
@options.install_galaxy_option()
87+
@options.no_cache_galaxy_option()
8788
@options.no_cleanup_option()
8889
@options.test_data_option()
8990
@options.tool_data_table_option()

planemo/commands/cmd_tool_factory.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@click.command('tool_factory')
1010
@options.galaxy_root_option()
1111
@options.install_galaxy_option()
12+
@options.no_cache_galaxy_option()
1213
@options.no_cleanup_option()
1314
@options.test_data_option()
1415
@options.dependency_resolvers_option()

planemo/config.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
}
66

77

8-
def global_config_path():
9-
config_path = os.environ.get(
10-
"PLANEMO_GLOBAL_CONFIG_PATH",
11-
"~/.planemo.yml"
12-
)
13-
config_path = os.path.expanduser(config_path)
8+
def global_config_path(config_path):
9+
if not config_path:
10+
config_path = os.environ.get(
11+
"PLANEMO_GLOBAL_CONFIG_PATH",
12+
"~/.planemo.yml"
13+
)
14+
config_path = os.path.expanduser(config_path)
1415
return config_path
1516

1617

17-
def read_global_config():
18-
config_path = global_config_path()
18+
def read_global_config(config_path):
19+
config_path = global_config_path(config_path)
1920
if not os.path.exists(config_path):
2021
return DEFAULT_CONFIG
2122

planemo/galaxy_config.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def config_join(*args):
103103
config_directory = mkdtemp()
104104
try:
105105
latest_galaxy = False
106-
if _install_galaxy_if_needed(config_directory, kwds):
106+
if _install_galaxy_if_needed(ctx, config_directory, kwds):
107107
latest_galaxy = True
108108
galaxy_root = config_join("galaxy-dev")
109109

@@ -309,26 +309,52 @@ def _tool_conf_entry_for(tool_path):
309309
return tool_definition
310310

311311

312-
def _install_galaxy_if_needed(config_directory, kwds):
312+
def _install_galaxy_if_needed(ctx, config_directory, kwds):
313313
installed = False
314314
if kwds.get("install_galaxy", None):
315-
_install_galaxy_via_download(config_directory, kwds)
315+
if not kwds.get("no_cache_galaxy", False):
316+
_install_galaxy_via_git(ctx, config_directory, kwds)
317+
else:
318+
_install_galaxy_via_download(config_directory, kwds)
316319
installed = True
317320
return installed
318321

319322

320323
def _install_galaxy_via_download(config_directory, kwds):
324+
command = galaxy_run.DOWNLOAD_GALAXY + "; tar -zxvf dev | tail"
325+
_install_with_command(config_directory, command)
326+
327+
328+
def _install_galaxy_via_git(ctx, config_directory, kwds):
329+
_ensure_galaxy_repository_available(ctx)
330+
workspace = ctx.workspace
331+
gx_repo = os.path.join(workspace, "gx_repo")
332+
command = "git clone %s galaxy-dev" % (gx_repo)
333+
_install_with_command(config_directory, command)
334+
335+
336+
def _install_with_command(config_directory, command):
321337
install_cmds = [
322338
"cd %s" % config_directory,
323-
galaxy_run.DOWNLOAD_GALAXY,
324-
"tar -zxvf master | tail",
339+
command,
325340
"cd galaxy-dev",
326341
"type virtualenv >/dev/null 2>&1 && virtualenv .venv",
327342
galaxy_run.ACTIVATE_COMMAND,
328343
]
329344
shell(";".join(install_cmds))
330345

331346

347+
def _ensure_galaxy_repository_available(ctx):
348+
workspace = ctx.workspace
349+
gx_repo = os.path.join(workspace, "gx_repo")
350+
if os.path.exists(gx_repo):
351+
# Attempt fetch - but don't fail if not interweb, etc...
352+
shell("git --git-dir %s fetch >/dev/null 2>&1" % gx_repo)
353+
else:
354+
remote_repo = "https://github.com/galaxyproject/galaxy"
355+
shell("git clone --bare %s %s" % (remote_repo, gx_repo))
356+
357+
332358
def _build_env_for_galaxy(properties, template_args):
333359
env = {}
334360
for key, value in properties.iteritems():

planemo/options.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ def install_galaxy_option():
9292
)
9393

9494

95+
def no_cache_galaxy_option():
96+
return click.option(
97+
"--no_cache_galaxy",
98+
is_flag=True,
99+
help=("Skip caching of downloaded Galaxy obtained with "
100+
"--install_galaxy. Not caching this results in faster "
101+
"downloads (no git) - so is better on throw away instances such "
102+
"with TravisCI. ")
103+
)
104+
105+
95106
def brew_option():
96107
return click.option(
97108
'--brew',

scripts/travis_test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ virtualenv planemo-venv
55
pip install planemo
66
planemo travis_before_install
77
. ${TRAVIS_BUILD_DIR}/.travis/env.sh # source environment created by planemo
8+
# TODO: Add --no_cache_galaxy once planemo 0.7.0 is available
9+
# on PyPI.
810
planemo test --install_galaxy ${TRAVIS_BUILD_DIR}

tests/test_init_and_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@ def test_init_and_test(self):
77
with self._isolate():
88
init_cmd = ["project_init", "--template", "demo", "basic"]
99
self._check_exit_code(init_cmd)
10-
test_cmd = ["test", "--install_galaxy", "basic/cat.xml"]
10+
test_cmd = [
11+
"test",
12+
"--no_cache_galaxy",
13+
"--install_galaxy",
14+
"basic/cat.xml"
15+
]
1116
self._check_exit_code(test_cmd)

0 commit comments

Comments
 (0)