From 51b4def4ec005b136707bff38611ed09ba6db2ff Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Mon, 27 Aug 2018 13:54:53 -0400 Subject: [PATCH 1/4] Allow running scripts/galaxy-main without Galaxy on $PYTHONPATH --- scripts/galaxy-main | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/galaxy-main b/scripts/galaxy-main index 1eb5d2c1941..ad0c21c6715 100755 --- a/scripts/galaxy-main +++ b/scripts/galaxy-main @@ -33,7 +33,10 @@ from logging.config import fileConfig from six.moves.configparser import ConfigParser -from galaxy.util import unicodify +try: + from galaxy.util import unicodify +except ImportError: + unicodify = None try: from daemonize import Daemonize @@ -239,6 +242,10 @@ def main(): except Exception: log.exception("Failed to add Galaxy to sys.path") raise + global unicodify + if unicodify is None: + _util = __import__('galaxy.util', globals(), locals(), ['unicodify']) + unicodify = _util.unicodify GalaxyConfigBuilder.populate_options(arg_parser) args = arg_parser.parse_args() if args.ini_path and not args.config_file: From 4ed9df9a947563a5fca4e07caad1b6a19cd6a845 Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Mon, 27 Aug 2018 14:03:39 -0400 Subject: [PATCH 2/4] Set config builder attributes before they're referenced in app_kwds() --- scripts/galaxy-main | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/galaxy-main b/scripts/galaxy-main index ad0c21c6715..d577480b895 100755 --- a/scripts/galaxy-main +++ b/scripts/galaxy-main @@ -170,6 +170,8 @@ class GalaxyConfigBuilder(object): """ def __init__(self, args=None, **kwds): + self.config_file = None + self.config_section = None self.app_name = kwds.get("app") or (args and args.app) or DEFAULT_CONFIG_SECTION config_file = kwds.get("config_file", None) or (args and args.config_file) # If given app_conf_path - use that - else we need to ensure we have a From 923ed2ed493a9575473b58da52d80de2d58ab41a Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Wed, 5 Sep 2018 19:46:50 +0100 Subject: [PATCH 3/4] Simplify importing from galaxy lib --- scripts/galaxy-main | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/scripts/galaxy-main b/scripts/galaxy-main index d577480b895..b67829aad99 100755 --- a/scripts/galaxy-main +++ b/scripts/galaxy-main @@ -33,11 +33,6 @@ from logging.config import fileConfig from six.moves.configparser import ConfigParser -try: - from galaxy.util import unicodify -except ImportError: - unicodify = None - try: from daemonize import Daemonize except ImportError: @@ -48,13 +43,21 @@ try: except ImportError: uwsgi = None -REQUIRES_DAEMONIZE_MESSAGE = "Attempted to use Galaxy in daemon mode, but daemonize is unavailable." - log = logging.getLogger(__name__) real_file = os.path.realpath(__file__) GALAXY_ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(real_file), os.pardir)) GALAXY_LIB_DIR = os.path.join(GALAXY_ROOT_DIR, "lib") +try: + sys.path.insert(1, GALAXY_LIB_DIR) +except Exception: + log.exception("Failed to add Galaxy to sys.path") + raise +from galaxy.util import unicodify +from galaxy.web.stack import get_app_kwds + +REQUIRES_DAEMONIZE_MESSAGE = "Attempted to use Galaxy in daemon mode, but daemonize is unavailable." + DEFAULT_INI_APP = "main" DEFAULT_CONFIG_SECTION = "galaxy" DEFAULT_INIS = ["config/galaxy.yml", "config/galaxy.ini", "universe_wsgi.ini", "config/galaxy.yml.sample"] @@ -206,7 +209,6 @@ class GalaxyConfigBuilder(object): return self.config_file.endswith('.ini') or self.config_file.endswith('.ini.sample') def app_kwds(self): - from galaxy.web.stack import get_app_kwds kwds = get_app_kwds(self.app_name, app_name=self.app_name) if 'config_file' not in kwds: kwds['config_file'] = self.config_file @@ -239,15 +241,6 @@ class GalaxyConfigBuilder(object): def main(): arg_parser = ArgumentParser(description=DESCRIPTION) - try: - sys.path.insert(1, GALAXY_LIB_DIR) - except Exception: - log.exception("Failed to add Galaxy to sys.path") - raise - global unicodify - if unicodify is None: - _util = __import__('galaxy.util', globals(), locals(), ['unicodify']) - unicodify = _util.unicodify GalaxyConfigBuilder.populate_options(arg_parser) args = arg_parser.parse_args() if args.ini_path and not args.config_file: From e14b871eb9ce577a8ee107728e4acb41028ddaa1 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Thu, 6 Sep 2018 11:00:08 +0100 Subject: [PATCH 4/4] Add test for scripts/galaxy-main --- test/integration/test_scripts.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/integration/test_scripts.py b/test/integration/test_scripts.py index d96f24a0cef..9eaa1e742eb 100644 --- a/test/integration/test_scripts.py +++ b/test/integration/test_scripts.py @@ -160,6 +160,9 @@ class ScriptsIntegrationTestCase(integration_util.IntegrationTestCase): # TODO: test creating a smaller database - e.g. tool install database based on fresh # config file. + def test_galaxy_main(self): + self._scripts_check_argparse_help("galaxy-main") + def test_runtime_stats(self): self._skip_if_not_postgres() self._scripts_check_argparse_help("runtime_stats.py")