From 22f4b8dc0340ed4a45421588119e9d0cb5f88670 Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Mon, 18 Mar 2019 12:13:30 -0400 Subject: [PATCH] Settings Dispatcher: move it to its own module This avoids the circular import that was originally a problem, and removes the "weird" SettingsDispatcher assignment to itself, while still adding documentation to keep this and the other dispatchers "linked". Reference: https://github.com/avocado-framework/avocado/issues/3065 Signed-off-by: Cleber Rosa --- avocado/core/dispatcher.py | 14 +++++----- avocado/core/settings.py | 19 +------------ avocado/core/settings_dispatcher.py | 41 +++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 25 deletions(-) create mode 100644 avocado/core/settings_dispatcher.py diff --git a/avocado/core/dispatcher.py b/avocado/core/dispatcher.py index 06f51a6c..690adbf9 100644 --- a/avocado/core/dispatcher.py +++ b/avocado/core/dispatcher.py @@ -12,7 +12,13 @@ # Copyright: Red Hat Inc. 2015 # Author: Cleber Rosa -"""Extensions/plugins dispatchers.""" +""" +Extensions/plugins dispatchers + +Besides the dispatchers listed here, there's also a lower level +dispatcher that these depend upon: +:class:`avocado.core.settings_dispatcher.SettingsDispatcher` +""" import copy import sys @@ -21,16 +27,10 @@ from stevedore import EnabledExtensionManager from .settings import settings from .settings import SettingsError -from .settings import SettingsDispatcher from .output import LOG_UI from ..utils import stacktrace -#: Settings dispatcher is simplified and has to be available before the -#: settings object. Let's include it here for consistency -SettingsDispatcher = SettingsDispatcher - - class Dispatcher(EnabledExtensionManager): """ diff --git a/avocado/core/settings.py b/avocado/core/settings.py index 73c54d9c..6ef45889 100644 --- a/avocado/core/settings.py +++ b/avocado/core/settings.py @@ -27,28 +27,11 @@ except ImportError: from pkg_resources import resource_filename from pkg_resources import resource_isdir from pkg_resources import resource_listdir -from stevedore import ExtensionManager +from .settings_dispatcher import SettingsDispatcher from ..utils import path -class SettingsDispatcher(ExtensionManager): - - """ - Dispatchers that allows plugins to modify settings - - It's not the standard "avocado.core.dispatcher" because that one depends - on settings. This dispatcher is the bare-stevedore dispatcher which is - executed before settings is parsed. - """ - - def __init__(self): - super(SettingsDispatcher, self).__init__('avocado.plugins.settings', - invoke_on_load=True, - invoke_kwds={}, - propagate_map_exceptions=True) - - class SettingsError(Exception): """ Base settings error. diff --git a/avocado/core/settings_dispatcher.py b/avocado/core/settings_dispatcher.py new file mode 100644 index 00000000..10443545 --- /dev/null +++ b/avocado/core/settings_dispatcher.py @@ -0,0 +1,41 @@ +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# See LICENSE for more details. +# +# Copyright: Red Hat Inc. 2018-2019 + +""" +Settings Dispatcher + +This is a special case for the dispatchers that can be found in +:mod:`avocado.core.dispatcher`. This one deals with settings that +will be read by the other dispatchers, while still being a dispatcher +for configuration sources. +""" + + +from stevedore import ExtensionManager + + +class SettingsDispatcher(ExtensionManager): + + """ + Dispatchers that allows plugins to modify settings + + It's not the standard "avocado.core.dispatcher" because that one depends + on settings. This dispatcher is the bare-stevedore dispatcher which is + executed before settings is parsed. + """ + + def __init__(self): + super(SettingsDispatcher, self).__init__('avocado.plugins.settings', + invoke_on_load=True, + invoke_kwds={}, + propagate_map_exceptions=True) -- GitLab