mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-16 07:19:13 +08:00
Move relodable options into a function
The previous version loaded these into a constant. As a result, importing the module implied reading a file specified by a path (in the GALAXY_APP App named_tuple) which broke building the docs (relative path became incorrect when module executed as script called from the Makefile that is inside doc/ Also, modified unit tests accordingly. (assertions are grouped for performance)
This commit is contained in:
@@ -97,18 +97,6 @@ LOGGING_CONFIG_DEFAULT = {
|
||||
"""Default value for logging configuration, passed to :func:`logging.config.dictConfig`"""
|
||||
|
||||
|
||||
# These are core config options that can be safely reloaded without a restart.
|
||||
# To enable dynamic reloading, set watch_core_config in galaxy.yml.
|
||||
# To make option foo reloadable:
|
||||
# 1. Update tests in test/unit/config/test_reloadable_properties.py
|
||||
# 2. Add 'reloadable: true' to foo in config_schema.yml
|
||||
# 3. If setting foo requires additional processing (like admin_users),
|
||||
# self.foo must contain the initially loaded value. Otherwise it
|
||||
# will be impossible to determine at runtime whether foo has been
|
||||
# modified and needs to be reloaded.
|
||||
RELOADABLE_CONFIG_OPTIONS = GALAXY_APP.schema.get_reloadable_option_defaults()
|
||||
|
||||
|
||||
def resolve_path(path, root):
|
||||
"""If 'path' is relative make absolute by prepending 'root'"""
|
||||
if not os.path.isabs(path):
|
||||
@@ -806,13 +794,15 @@ class GalaxyAppConfiguration(BaseAppConfiguration):
|
||||
}
|
||||
|
||||
def _set_reloadable_properties(self, kwargs):
|
||||
for key, default_value in RELOADABLE_CONFIG_OPTIONS.items():
|
||||
reloadable_config_options = get_reloadable_config_options()
|
||||
for key, default_value in reloadable_config_options.items():
|
||||
value = kwargs.get(key) or default_value
|
||||
setattr(self, key, value)
|
||||
|
||||
def update_reloadable_property(self, key, value):
|
||||
if key in RELOADABLE_CONFIG_OPTIONS: # check again because this is critical
|
||||
setattr(self, key, value)
|
||||
# TODO: after config_schema.yml is read only once at startup, add this:
|
||||
# "if key in reloadable_config_options" (just a safety measure)
|
||||
setattr(self, key, value)
|
||||
|
||||
@property
|
||||
def admin_users(self):
|
||||
@@ -1004,13 +994,18 @@ Configuration = GalaxyAppConfiguration
|
||||
def reload_config_options(current_config, path=None):
|
||||
""" Reload modified reloadable config options """
|
||||
modified_config = read_properties_from_file(current_config.config_file)
|
||||
for option in RELOADABLE_CONFIG_OPTIONS:
|
||||
reloadable_config_options = get_reloadable_config_options()
|
||||
for option in reloadable_config_options:
|
||||
if option in modified_config:
|
||||
if getattr(current_config, option) != modified_config[option]:
|
||||
current_config.update_reloadable_property(option, modified_config[option])
|
||||
log.info('Reloaded %s' % option)
|
||||
|
||||
|
||||
def get_reloadable_config_options():
|
||||
return GALAXY_APP.schema.get_reloadable_option_defaults()
|
||||
|
||||
|
||||
def get_database_engine_options(kwargs, model_prefix=''):
|
||||
"""
|
||||
Allow options for the SQLAlchemy database engine to be passed by using
|
||||
|
||||
@@ -3,7 +3,6 @@ from galaxy.config import reload_config_options
|
||||
|
||||
|
||||
R1, R2, N1, N2 = 'reloadable1', 'reloadable2', 'nonrelodable1', 'nonreloadable2' # config options
|
||||
MOCK_RELOADABLE_CONFIG_OPTIONS = {R1: None, R2: None}
|
||||
|
||||
|
||||
class MockGalaxyAppConfiguration():
|
||||
@@ -25,7 +24,10 @@ def test_update_property(monkeypatch):
|
||||
def mock_read_properties_from_file(values):
|
||||
return {R1: 1, R2: 42, N1: 99} # edits: R2, N1 modified
|
||||
|
||||
monkeypatch.setattr(config, 'RELOADABLE_CONFIG_OPTIONS', MOCK_RELOADABLE_CONFIG_OPTIONS)
|
||||
def mock_get_reloadable_config_options():
|
||||
return {R1: None, R2: None}
|
||||
|
||||
monkeypatch.setattr(config, 'get_reloadable_config_options', mock_get_reloadable_config_options)
|
||||
monkeypatch.setattr(config, 'read_properties_from_file', mock_read_properties_from_file)
|
||||
|
||||
assert getattr(appconfig, R1) == 1
|
||||
@@ -48,7 +50,10 @@ def test_cant_delete_property(monkeypatch):
|
||||
def mock_read_properties_from_file(values):
|
||||
return {R1: 1, N1: 3} # edits: R2, N2 deleted
|
||||
|
||||
monkeypatch.setattr(config, 'RELOADABLE_CONFIG_OPTIONS', MOCK_RELOADABLE_CONFIG_OPTIONS)
|
||||
def mock_get_reloadable_config_options():
|
||||
return {R1: None, R2: None}
|
||||
|
||||
monkeypatch.setattr(config, 'get_reloadable_config_options', mock_get_reloadable_config_options)
|
||||
monkeypatch.setattr(config, 'read_properties_from_file', mock_read_properties_from_file)
|
||||
|
||||
assert getattr(appconfig, R1) == 1
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from galaxy.config import (
|
||||
GalaxyAppConfiguration,
|
||||
RELOADABLE_CONFIG_OPTIONS,
|
||||
)
|
||||
from galaxy.config import GalaxyAppConfiguration, get_reloadable_config_options
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -16,22 +13,22 @@ def mock_configuration_init(monkeypatch):
|
||||
|
||||
def test_load_default_values(mock_configuration_init):
|
||||
appconfig = GalaxyAppConfiguration()
|
||||
|
||||
assert len(RELOADABLE_CONFIG_OPTIONS) == 14
|
||||
assert appconfig.message_box_content == RELOADABLE_CONFIG_OPTIONS['message_box_content']
|
||||
assert appconfig.welcome_url == RELOADABLE_CONFIG_OPTIONS['welcome_url']
|
||||
assert appconfig.tool_name_boost == RELOADABLE_CONFIG_OPTIONS['tool_name_boost']
|
||||
assert appconfig.tool_section_boost == RELOADABLE_CONFIG_OPTIONS['tool_section_boost']
|
||||
assert appconfig.tool_description_boost == RELOADABLE_CONFIG_OPTIONS['tool_description_boost']
|
||||
assert appconfig.tool_label_boost == RELOADABLE_CONFIG_OPTIONS['tool_label_boost']
|
||||
assert appconfig.tool_stub_boost == RELOADABLE_CONFIG_OPTIONS['tool_stub_boost']
|
||||
assert appconfig.tool_help_boost == RELOADABLE_CONFIG_OPTIONS['tool_help_boost']
|
||||
assert appconfig.tool_search_limit == RELOADABLE_CONFIG_OPTIONS['tool_search_limit']
|
||||
assert appconfig.tool_enable_ngram_search == RELOADABLE_CONFIG_OPTIONS['tool_enable_ngram_search']
|
||||
assert appconfig.tool_ngram_minsize == RELOADABLE_CONFIG_OPTIONS['tool_ngram_minsize']
|
||||
assert appconfig.tool_ngram_maxsize == RELOADABLE_CONFIG_OPTIONS['tool_ngram_maxsize']
|
||||
assert appconfig.admin_users == RELOADABLE_CONFIG_OPTIONS['admin_users']
|
||||
assert appconfig.cleanup_job == RELOADABLE_CONFIG_OPTIONS['cleanup_job']
|
||||
reloadable_config_options = get_reloadable_config_options()
|
||||
assert len(reloadable_config_options) == 14
|
||||
assert appconfig.message_box_content == reloadable_config_options['message_box_content']
|
||||
assert appconfig.welcome_url == reloadable_config_options['welcome_url']
|
||||
assert appconfig.tool_name_boost == reloadable_config_options['tool_name_boost']
|
||||
assert appconfig.tool_section_boost == reloadable_config_options['tool_section_boost']
|
||||
assert appconfig.tool_description_boost == reloadable_config_options['tool_description_boost']
|
||||
assert appconfig.tool_label_boost == reloadable_config_options['tool_label_boost']
|
||||
assert appconfig.tool_stub_boost == reloadable_config_options['tool_stub_boost']
|
||||
assert appconfig.tool_help_boost == reloadable_config_options['tool_help_boost']
|
||||
assert appconfig.tool_search_limit == reloadable_config_options['tool_search_limit']
|
||||
assert appconfig.tool_enable_ngram_search == reloadable_config_options['tool_enable_ngram_search']
|
||||
assert appconfig.tool_ngram_minsize == reloadable_config_options['tool_ngram_minsize']
|
||||
assert appconfig.tool_ngram_maxsize == reloadable_config_options['tool_ngram_maxsize']
|
||||
assert appconfig.admin_users == reloadable_config_options['admin_users']
|
||||
assert appconfig.cleanup_job == reloadable_config_options['cleanup_job']
|
||||
|
||||
|
||||
def test_load_value_from_kwargs(mock_configuration_init):
|
||||
@@ -40,85 +37,34 @@ def test_load_value_from_kwargs(mock_configuration_init):
|
||||
|
||||
|
||||
def test_update_reloadable_property__message_box_content(mock_configuration_init):
|
||||
appconfig = GalaxyAppConfiguration()
|
||||
appconfig.update_reloadable_property('message_box_content', 'foo')
|
||||
assert appconfig.message_box_content == 'foo'
|
||||
|
||||
|
||||
def test_update_reloadable_property__welcome_url(mock_configuration_init):
|
||||
appconfig = GalaxyAppConfiguration()
|
||||
appconfig.update_reloadable_property('welcome_url', 'foo')
|
||||
assert appconfig.welcome_url == 'foo'
|
||||
|
||||
|
||||
def test_update_reloadable_property__tool_name_boost(mock_configuration_init):
|
||||
appconfig = GalaxyAppConfiguration()
|
||||
appconfig.update_reloadable_property('tool_name_boost', 42)
|
||||
assert appconfig.tool_name_boost == 42
|
||||
|
||||
|
||||
def test_update_reloadable_property__tool_section_boost(mock_configuration_init):
|
||||
appconfig = GalaxyAppConfiguration()
|
||||
appconfig.update_reloadable_property('tool_section_boost', 42)
|
||||
assert appconfig.tool_section_boost == 42
|
||||
|
||||
|
||||
def test_update_reloadable_property__tool_description_boost(mock_configuration_init):
|
||||
appconfig = GalaxyAppConfiguration()
|
||||
appconfig.update_reloadable_property('tool_description_boost', 42)
|
||||
assert appconfig.tool_description_boost == 42
|
||||
|
||||
|
||||
def test_update_reloadable_property__tool_label_boost(mock_configuration_init):
|
||||
appconfig = GalaxyAppConfiguration()
|
||||
appconfig.update_reloadable_property('tool_label_boost', 42)
|
||||
assert appconfig.tool_label_boost == 42
|
||||
|
||||
|
||||
def test_update_reloadable_property__tool_stub_boost(mock_configuration_init):
|
||||
appconfig = GalaxyAppConfiguration()
|
||||
appconfig.update_reloadable_property('tool_stub_boost', 42)
|
||||
assert appconfig.tool_stub_boost == 42
|
||||
|
||||
|
||||
def test_update_reloadable_property__tool_help_boost(mock_configuration_init):
|
||||
appconfig = GalaxyAppConfiguration()
|
||||
appconfig.update_reloadable_property('tool_help_boost', 42)
|
||||
assert appconfig.tool_help_boost == 42
|
||||
|
||||
|
||||
def test_update_reloadable_property__tool_search_limit(mock_configuration_init):
|
||||
appconfig = GalaxyAppConfiguration()
|
||||
appconfig.update_reloadable_property('tool_search_limit', 42)
|
||||
assert appconfig.tool_search_limit == 42
|
||||
|
||||
|
||||
def test_update_reloadable_property__tool_enable_ngram_search(mock_configuration_init):
|
||||
appconfig = GalaxyAppConfiguration()
|
||||
appconfig.update_reloadable_property('message_box_content', 'bar')
|
||||
appconfig.update_reloadable_property('tool_name_boost', 1)
|
||||
appconfig.update_reloadable_property('tool_section_boost', 2)
|
||||
appconfig.update_reloadable_property('tool_description_boost', 3)
|
||||
appconfig.update_reloadable_property('tool_label_boost', 4)
|
||||
appconfig.update_reloadable_property('tool_stub_boost', 5)
|
||||
appconfig.update_reloadable_property('tool_help_boost', 6)
|
||||
appconfig.update_reloadable_property('tool_search_limit', 7)
|
||||
appconfig.update_reloadable_property('tool_enable_ngram_search', True)
|
||||
assert appconfig.tool_enable_ngram_search is True
|
||||
|
||||
|
||||
def test_update_reloadable_property__tool_ngram_minsize(mock_configuration_init):
|
||||
appconfig = GalaxyAppConfiguration()
|
||||
appconfig.update_reloadable_property('tool_ngram_minsize', 42)
|
||||
assert appconfig.tool_ngram_minsize == 42
|
||||
|
||||
|
||||
def test_update_reloadable_property__tool_ngram_maxsize(mock_configuration_init):
|
||||
appconfig = GalaxyAppConfiguration()
|
||||
appconfig.update_reloadable_property('tool_ngram_maxsize', 42)
|
||||
assert appconfig.tool_ngram_maxsize == 42
|
||||
|
||||
|
||||
def test_update_reloadable_property__admin_users(mock_configuration_init):
|
||||
appconfig = GalaxyAppConfiguration()
|
||||
appconfig.update_reloadable_property('tool_ngram_minsize', 8)
|
||||
appconfig.update_reloadable_property('tool_ngram_maxsize', 9)
|
||||
appconfig.update_reloadable_property('admin_users', 'tuor@gondolin.net, ulmo@valinor.gov')
|
||||
appconfig.update_reloadable_property('cleanup_job', 'never')
|
||||
|
||||
assert appconfig.welcome_url == 'foo'
|
||||
assert appconfig.message_box_content == 'bar'
|
||||
assert appconfig.tool_name_boost == 1
|
||||
assert appconfig.tool_section_boost == 2
|
||||
assert appconfig.tool_description_boost == 3
|
||||
assert appconfig.tool_label_boost == 4
|
||||
assert appconfig.tool_stub_boost == 5
|
||||
assert appconfig.tool_help_boost == 6
|
||||
assert appconfig.tool_search_limit == 7
|
||||
assert appconfig.tool_enable_ngram_search is True
|
||||
assert appconfig.tool_ngram_minsize == 8
|
||||
assert appconfig.tool_ngram_maxsize == 9
|
||||
assert appconfig.admin_users == 'tuor@gondolin.net, ulmo@valinor.gov'
|
||||
assert appconfig.admin_users_list == ['tuor@gondolin.net', 'ulmo@valinor.gov']
|
||||
|
||||
|
||||
def test_update_reloadable_property__cleanup_job(mock_configuration_init):
|
||||
appconfig = GalaxyAppConfiguration()
|
||||
appconfig.update_reloadable_property('cleanup_job', 'never')
|
||||
assert appconfig.cleanup_job == 'never'
|
||||
|
||||
Reference in New Issue
Block a user