[PEAK] Re: Trellis: ctrl.pulse

Sergey Schetinin maluke at gmail.com
Wed Apr 15 17:32:31 EDT 2009


On Thu, Apr 16, 2009 at 00:17, P.J. Eby <pje at telecommunity.com> wrote:
> At 11:48 PM 4/15/2009 +0300, Sergey Schetinin wrote:
>>
>> On Wed, Apr 15, 2009 at 23:43, P.J. Eby <pje at telecommunity.com> wrote:
>> > At 11:38 PM 4/15/2009 +0300, Sergey Schetinin wrote:
>> >>
>> >> On Wed, Apr 15, 2009 at 23:11, Sergey Schetinin <maluke at gmail.com>
>> >> wrote:
>> >> > Importing trellis from stm is ugly, and messes with lazy imports of
>> >> > trellis (as done by Importing), replacing pulse with a special cell
>> >> > doesn't seem to hard, see attached patch.
>> >>
>> >> Also, install_controller is unnecessary:
>> >
>> > install_controller() is an API function so that you can replace the
>> > controller, e.g. for testing or for applications with special needs.
>>
>> Oh, I see, but given it populates the global namespace, if some other
>> module already did "from peak.events.trellis import *" things will
>> break.
>
> Yes.  So don't do that.  ;-)
>
>
>> Can it really be part of API?
>
> Technically, I haven't documented it yet.  But that was the original intent
> of having it there.  At the moment it's more of a semi-private hack.
>  However, it's why you'll almost never see me importing stuff from
> 'trellis', as opposed to using 'trellis.whatever'.

Maybe a better choice would be not to add those functions to __all__
then (ctrl as well)? That would make it OK to `import *` to get things
like Component and decorators. And on_undo and similar things would be
addressed as stm.ctrl.on_undo. Or trellis.py could import itself and
then the overridable globals would be accessed as trellis.on_undo as
well, but things wouldn't be as fragile to import *.


trellis = sys.modules['peak.events.trellis']

__all__ = [
    'Cell', 'Constant', 'make', 'todo', 'todos', 'modifier',
    'Component', 'repeat', 'poll', 'InputConflict',
    'Dict', 'List', 'Set', 'mark_dirty', 'ConstantMixin', 'Sensor', #'ctrl',
    'AbstractConnector', 'Connector',  'Effector', 'init_attrs',
    'attr', 'attrs', 'compute', 'maintain', 'perform', 'Performer', 'Pipe',
    'trellis'
]


_stm_names = [
    'on_commit', 'on_undo', 'atomically', 'manage', 'savepoint',
    'rollback_to', 'schedule', 'cancel', 'lock', 'used', 'changed',
    'initialize', 'change_attr',
]

def install_controller(new_ctrl):
    global ctrl
    globals().update([(name, getattr(new_ctrl, name)) for name in _stm_names])
    stm.ctrl = ctrl = new_ctrl

install_controller(stm.Controller()) #stm.LocalController()


More information about the PEAK mailing list