[PATCH 4 of 4] hacks: add support for monkeypatching Kallithea internals

Thomas De Schampheleire patrickdepinguin at gmail.com
Sat Apr 25 14:33:32 EDT 2015


# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1429565291 -7200
#      Mon Apr 20 23:28:11 2015 +0200
# Node ID accdfd58edfb0687cfb2e59e619e2f90ed8f0d35
# Parent  3d17f0d2a96eac41e6bf4312df1f6af476cce4ad
hacks: add support for monkeypatching Kallithea internals

[tdescham:
  - update commit message
  - remove redundant import of os.path
  - describe possible need for absolute_import ]

diff --git a/kallithea/config/environment.py b/kallithea/config/environment.py
--- a/kallithea/config/environment.py
+++ b/kallithea/config/environment.py
@@ -16,6 +16,7 @@
 """
 
 import os
+import imp
 import logging
 import kallithea
 import platform
@@ -43,12 +44,28 @@
 log = logging.getLogger(__name__)
 
 
+def load_hacks():
+    """
+    Load hacks - python files dropped in kallithea/hacks that will monkeypatch
+    Kallithea internals
+    In order to import kallithea modules correctly from a hack, you may need
+    the following line at its very top:
+        from __future__ import absolute_import
+    """
+    hacksdir = os.path.dirname(__file__) + '/../hacks'
+    if os.path.isdir(hacksdir):
+        for f in os.listdir(hacksdir):
+            if not f.startswith('_') and f.endswith('.py'):
+                _m = imp.load_source('hacks.%s' % f, hacksdir + '/' + f)
+
 def load_environment(global_conf, app_conf, initial=False,
                      test_env=None, test_index=None):
     """
     Configure the Pylons environment via the ``pylons.config``
     object
     """
+    load_hacks()
+
     config = PylonsConfig()
 
     # Pylons paths


More information about the kallithea-general mailing list