# HG changeset patch # User Thomas De Schampheleire # Date 2017-03-18 20:37:27 # Node ID 69cd0c056aa18a1b533af8fe04892e67a22834ec # Parent b4c27fe6438c262ba95bd26a0e1c2c7ac9b1dbbb config: initialize routes directly from RootController Let RootController directly initialize routes instead of app_cfg injecting the mapper. For test initialization, we also need a handle to the mapper. We could either recreate it (but fragile if the real mapper initialization is changed later) or obtain it from a fresh RootController. This commit opts for the latter. diff --git a/kallithea/config/app_cfg.py b/kallithea/config/app_cfg.py --- a/kallithea/config/app_cfg.py +++ b/kallithea/config/app_cfg.py @@ -28,7 +28,6 @@ from tg.support.converters import asbool from kallithea.lib.middleware.https_fixup import HttpsFixup from kallithea.lib.middleware.simplegit import SimpleGit from kallithea.lib.middleware.simplehg import SimpleHg -from kallithea.config.routing import make_map from kallithea.lib.auth import set_available_permissions from kallithea.lib.db_manage import DbManage from kallithea.lib.utils import load_rcextensions, make_ui, set_app_settings, set_vcs_config, \ @@ -119,10 +118,6 @@ def setup_configuration(app): kallithea.CELERY_EAGER = str2bool(config['app_conf'].get('celery.always.eager')) kallithea.CONFIG = config - # Provide routes mapper to the RoutedController - root_controller = app.find_controller('root') - root_controller.mapper = config['routes.map'] = make_map(config) - load_rcextensions(root_path=config['here']) # FIXME move test setup code out of here diff --git a/kallithea/controllers/root.py b/kallithea/controllers/root.py --- a/kallithea/controllers/root.py +++ b/kallithea/controllers/root.py @@ -12,20 +12,21 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . from tgext.routes import RoutedController +from kallithea.config.routing import make_map from kallithea.lib.base import BaseController from kallithea.controllers.error import ErrorController - +from tg import config -# With TurboGears, the RootController is the controller from which all routing -# starts from. It is 'magically' found based on the fact that a controller -# 'foo' is expected to have a class name FooController, located in a file -# foo.py, inside config['paths']['controllers']. The name 'root' for the root -# controller is the default name. The dictionary config['paths'] determines the -# directories where templates, static files and controllers are found. It is -# set up in tg.AppConfig based on AppConfig['package'] ('kallithea') and the -# respective defaults 'templates', 'public' and 'controllers'. -# Inherit from RoutedController to allow Kallithea to use regex-based routing. +# This is the main Kallithea entry point; TurboGears will forward all requests +# to an instance of 'controller.root.RootController' in the configured +# 'application' module (set by app_cfg.py). Requests are forwarded to +# controllers based on the routing mapper that lives in this root instance. +# The mapper is configured using routes defined in routing.py. This use of the +# 'mapper' attribute is a feature of tgext.routes, which is activated by +# inheriting from its RoutedController class. class RootController(RoutedController, BaseController): + mapper = make_map(config) + # the following assignment hooks in error handling error = ErrorController() diff --git a/kallithea/tests/conftest.py b/kallithea/tests/conftest.py --- a/kallithea/tests/conftest.py +++ b/kallithea/tests/conftest.py @@ -8,6 +8,7 @@ from routes.util import URLGenerator from tg import config import pytest +from kallithea.controllers.root import RootController from kallithea.model.user import UserModel from kallithea.model.meta import Session from kallithea.model.db import Setting, User, UserIpMap @@ -26,7 +27,7 @@ def pytest_configure(): kallithea.tests.base.testapp = loadapp('config:kallithea/tests/test.ini', relative_to=path) logging.disable(logging.NOTSET) - kallithea.tests.base.url = URLGenerator(config['routes.map'], kallithea.tests.base.environ) + kallithea.tests.base.url = URLGenerator(RootController().mapper, kallithea.tests.base.environ) @pytest.fixture