[PATCH PoC] hacks: the concept of python files that will be loaded and can monkeypatch Kallithea internals

Thomas De Schampheleire patrickdepinguin at gmail.com
Thu Apr 23 16:00:22 EDT 2015


On Mon, Apr 20, 2015 at 11:28 PM, Mads Kiilerich <mads at kiilerich.com> wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski at unity3d.com>
> # Date 1429565291 -7200
> #      Mon Apr 20 23:28:11 2015 +0200
> # Node ID fcfd593347c8240544996f5516113595c0ff390a
> # Parent  7e5a0c784880bf8da968710948f3aa617403bf5a
> hacks: the concept of python files that will be loaded and can monkeypatch Kallithea internals
>
> 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,8 @@
>  """
>
>  import os
> +import os.path
> +import imp
>  import logging
>  import kallithea
>  import platform
> @@ -43,12 +45,25 @@ from kallithea.model.scm import ScmModel
>  log = logging.getLogger(__name__)
>
>
> +def load_hacks():
> +    """
> +    Load hacks - python files dropped in kallithea/hacks that will monkeypatch
> +    Kallithea internals
> +    """
> +    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
> diff --git a/kallithea/hacks/nogit.py b/kallithea/hacks/nogit.py
> new file mode 100644
> --- /dev/null
> +++ b/kallithea/hacks/nogit.py
> @@ -0,0 +1,5 @@
> +"""
> +disable adding Git repos
> +"""
> +import kallithea
> +kallithea.BACKENDS.pop('git')

I can't run such an example correctly:

..../kallithea/config/../hacks/foo.py:9: RuntimeWarning: Parent module
'hacks.foo' not found while handling absolute import
  import kallithea

If I don't import anything but just print something, no such warning is printed.

I haven't had time yet to dig deeper, but perhaps you know off the top
of your head what's the problem?
This is with Python 2.7.5.

Thanks,
Thomas


More information about the kallithea-general mailing list