[PATCH PoC] hacks: the concept of python files that will be loaded and can monkeypatch Kallithea internals
Thomas De Schampheleire
patrickdepinguin at gmail.com
Fri Apr 24 02:43:43 EDT 2015
On Thu, Apr 23, 2015 at 10:28 PM, Mads Kiilerich <mads at kiilerich.com> wrote:
> On 04/23/2015 10:00 PM, Thomas De Schampheleire wrote:
>>
>> 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
>
>
> Hmm ... not really ... but it can be avoided with
> from __future__ import absolute_import
Yes, indeed, adding this line at the top of the hack works fine.
>
> It would perhaps be better to just use an existing fullblown extension
> mechanism - perhaps the one from Mercurial.
>
> So ... this proof of concept "proved" that something conceptually simple
> could add a lot of value. Now comes the details ...
The method you provided here has the advantage that it is very simple
and has very little impact on the rest of the code. I'm not very
familiar with the internals of Mercurial extension handling, so I
cannot judge if it is better than this patch.
Best regards,
Thomas
More information about the kallithea-general
mailing list