Turbogears2 migration: import of helpers/app_globals into kallithea.lib

Thomas De Schampheleire patrickdepinguin at gmail.com
Wed Aug 31 12:15:09 UTC 2016


Hi Alessandro,

In kallithea/lib/__init__.py you added following statements:

from . import helpers
from . import app_globals

following an expectation of Turbogears2.
This poses problems with statements like 'from kallithea.lib import vcs'.

I have now dug deeper to the real requirement of this change, and
found that it is due to method _setup_helpers_and_globals in
tg/configuration/app_config.py:

    def _setup_helpers_and_globals(self, conf):
        """Add helpers and globals objects to the ``conf``.

        Override this method to customize the way that ``app_globals``
and ``helpers``
        are setup. TurboGears expects them to be available in ``conf``
dictionary
        as ``tg.app_globals`` and ``helpers``.
        """
        gclass = conf.pop('app_globals', None)
        if gclass is None:
            try:
                g = conf['package'].lib.app_globals.Globals()
            except AttributeError:
                log.warn('app_globals not provided and
lib.app_globals.Globals is not available.')
                g = Bunch()
        else:
            g = gclass()

        g.dotted_filename_finder = DottedFileNameFinder()
        conf['tg.app_globals'] = g

        if conf.get('tg.pylons_compatible', True):
            conf['pylons.app_globals'] = g

        h = conf.get('helpers', None)
        if h is None:
            try:
                h = conf['package'].lib.helpers
            except AttributeError:
                log.warn('helpers not provided and lib.helpers is not
available.')
                h = Bunch()
        conf['helpers'] = h


Encouraged by the docstring, I tried overriding this method as follows
from Kallithea:

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
@@ -33,6 +33,14 @@ class KallitheaAppConfig(AppConfig):
     def after_init_config(self, conf):
         conf['tg.strict_tmpl_context'] = True

+    def _setup_helpers_and_globals(self, conf):
+        from kallithea.lib import app_globals, helpers
+        from tg.util import DottedFileNameFinder
+        g = app_globals.Globals()
+        conf['tg.app_globals'] = g
+        conf['pylons.app_globals'] = g
+        conf['helpers'] = helpers
+        g.dotted_filename_finder = DottedFileNameFinder()

 base_config = KallitheaAppConfig()
 base_config.renderers = []
diff --git a/kallithea/lib/__init__.py b/kallithea/lib/__init__.py
--- a/kallithea/lib/__init__.py
+++ b/kallithea/lib/__init__.py
@@ -24,9 +24,6 @@ Original author and date, and relevant c
 :copyright: (c) 2013 RhodeCode GmbH, and others.
 :license: GPLv3, see LICENSE.md for more details.
 """
-from . import helpers
-from . import app_globals
-
 import os

 def get_current_revision(quiet=False):


This seems to work functionally, also in the test suite, but for a
reason unclear to me the above patch triggers debug logs of tg to
appear on the console when running 'paster serve development.ini',
while it is not the case without this patch.
What worries me most, is that inside these extra logs, there is an
error log as follows:

2016-08-31 12:55:09.422 ERROR [tg.appwrappers.transaction_manager]
Unable to Enable Transaction Manager
Traceback (most recent call last):
  File "/home/tdescham/repo/contrib/kallithea/venv/kallithea-tg-clean/lib/python2.7/site-packages/tg/appwrappers/transaction_manager.py",
line 51, in __init__
    import transaction
ImportError: No module named transaction
2016-08-31 12:55:09.423 DEBUG [tg.appwrappers.transaction_manager]
TransactionManager enabled: False -> {'attempts': 1, 'enabled': True,
'commit_veto': None}


It is unclear to me whether this is a new problem due to my patch, or
that it always existed but never showed due to the logs not visible.

Any feedback is welcome...

Thanks a lot,
Thomas


More information about the kallithea-general mailing list