From 79e96e610dfb4dc6ce53ec39fe294ddde1600651 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Fri, 10 Nov 2017 17:29:38 +0000 Subject: [PATCH] Run `hg clone` in a subprocess instead of using Mercurial API Using the API is discouraged by upstream, see: https://www.mercurial-scm.org/wiki/MercurialApi Moreover, the old code randomly causes the following error when installing big ToolShed repositories (e.g. any qiime tool) through the admin UI: tool_shed.util.hg_util DEBUG 2017-11-03 17:36:45,950 Error cloning repository: signal only works in main thread This error occurs when Galaxy runs under Paste and also when it runs under uWSGI with multiple threads per process. --- lib/tool_shed/util/hg_util.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/tool_shed/util/hg_util.py b/lib/tool_shed/util/hg_util.py index a50e96ac132..f979e73c8cc 100644 --- a/lib/tool_shed/util/hg_util.py +++ b/lib/tool_shed/util/hg_util.py @@ -2,6 +2,7 @@ import json import logging import os import struct +import subprocess import tempfile from datetime import datetime from time import gmtime @@ -10,7 +11,6 @@ from mercurial import cmdutil, commands, hg, ui from mercurial.changegroup import readexactly from mercurial.exchange import readbundle -from galaxy.util import listify from tool_shed.util import basic_util log = logging.getLogger(__name__) @@ -55,15 +55,12 @@ def clone_repository(repository_clone_url, repository_file_dir, ctx_rev): present in the cloned repository. """ try: - commands.clone(get_configured_ui(), - str(repository_clone_url), - dest=str(repository_file_dir), - pull=True, - noupdate=False, - rev=listify(str(ctx_rev))) + stdouterr = subprocess.check_output(['hg', 'clone', '-r', ctx_rev, repository_clone_url, repository_file_dir], stderr=subprocess.STDOUT) return True, None except Exception as e: - error_message = 'Error cloning repository: %s' % str(e) + error_message = 'Error cloning repository: %s' % e + if isinstance(e, subprocess.CalledProcessError): + error_message += "\nOutput was:\n%s" % stdouterr log.debug(error_message) return False, error_message