Code Monkey home page Code Monkey logo

gossip's People

Contributors

ayalash avatar drrlvn avatar sivanbecker avatar vmalloc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gossip's Issues

Is it possible to use hooks on methods in a class?

Is it possible to use hooks on methods in a class? E.g.:

import gossip


class Foo:
    def trigger(self):
        gossip.trigger('this_hook')

    @gossip.register('this_hook')
    def triggered_by_hook(self):
        print('triggered_by_hook')


foo = Foo()
foo.trigger()

Support contextbacks

The usage should be something like:

operation_context = gossip.define_contextback('name', args=(...), tags=..., ....)

And then for registration

@operation_context.register
@contextmanager
def my_contextmanager(arg1, arg2):
     ...
     yield
     ....

Gossip ignore define_hook kwargs if the hook was registered before

Reproduction code:

import gossip

@gossip.register('hook_a')
def foo(**kwargs):
    pass

gossip.define('hook_a', tags=('my', 'tags'), arg_names=('x', 'y'))
gossip.define('hook_b', tags=('my', 'tags'), arg_names=('z', 'y'))

@gossip.register('hook_b')
def bar(**kwargs):
    pass

for hook in gossip.get_all_hooks():
  print(f'Hook: {hook.full_name}, tags: {hook.tags}, arguments: {hook.get_argument_names()}')

The output:

Hook: hook_a, tags: ('my', 'tags'), arguments: ()
Hook: hook_b, tags: ('my', 'tags'), arguments: ('z', 'y')

hook_b is as expected, but hook_a should add x & y as arguments

gossip.unregister_token does not work as expected

The following code fails on AssertionError:

import gossip

@gossip.register('a.b', token='token')
def foo():
    pass

gossip.unregister_token('token')
assert not gossip.get_all_registrations()  # <= Raise AssertionError

Using gossip for objectmethods

how can I use gossip for objectmethods

>>> import gossip
>>> class MyClass(object):
...     def trigger(self):
...         gossip.trigger('my_hook')
...     @gossip.register('my_hook')
...     def my_func(self):
...         print 42
... 
>>> my_object = MyClass()
>>> my_object.trigger()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in trigger
  File "/home/eli/qa/.venv/local/lib/python2.7/site-packages/gossip/hooks.py", line 189, in trigger
    trigger_with_tags(hook_name, kwargs, None)
  File "/home/eli/qa/.venv/local/lib/python2.7/site-packages/gossip/hooks.py", line 199, in trigger_with_tags
    hook.trigger(kwargs or {}, tags)
  File "/home/eli/qa/.venv/local/lib/python2.7/site-packages/gossip/hooks.py", line 152, in trigger
    exception_policy.handle_exception(ctx, exc_info)
  File "/home/eli/qa/.venv/local/lib/python2.7/site-packages/gossip/exception_policy.py", line 29, in handle_exception
    reraise(exc_info[0], exc_info[1], exc_info[2])
  File "/home/eli/qa/.venv/local/lib/python2.7/site-packages/gossip/hooks.py", line 169, in _call_registration
    registration(**kwargs)  # pylint: disable=star-args
  File "/home/eli/qa/.venv/local/lib/python2.7/site-packages/gossip/registration.py", line 70, in __call__
    return self.func(*args, **kwargs)
TypeError: my_func() takes exactly 1 argument (0 given)

since the self parameter is not sent

Adding registration context

The code of hook registration for specific code block looks not elegant.
Currently there are two options for doing it:

hook = gossip.get_hook('my_hook')
reg = hook.register(func)
... # Code block
reg.unregister

or

goossip.register(func, 'my_hook', token='some_token')
... # Code block
gossip.unregister_token('some_token')

It would be nice to have:

with gossip.registrated(fun, 'my_hook'):
    ... # Code block

Better description for registrations on exception logs

For example, raising an exception in a registration yields something like this:

[2014-06-16 15:16] WARNING: gossip.hooks: Exception occurred while calling <gossip.registration.Registration object at 0x7f66e37e8d50>

It would be better to attempt and describe the actual registration name (function/object)

Add support for toggle hooks

In several cases it is necessary to register hooks in pairs (e.g. start/end or before/after of events). In some of these cases it is necessary to ensure that the "closing" hook isn't called unless the "hook" was called. This is particularly useful for plugin systems.

This feature will enable registering like this:

from gossip import Toggle

_toggle = Toggle()
@gossip.register(toggle_on=_toggle)
def before():
   ...

@gossip.register(toggle_off=_toggle)
def after():
   ...

Add sphinx extension for listing hooks

Every project which uses gossip, should have its own implementation for listing the gossip hooks it supports.

It would be nice to have a sphinx extension which listing all the hooks of a specific gossip group for documentation.

Register pre-defined hook with arguments

Hi Rotem,

Thanks for developing Gossip. I love it!
I'm currently using it as part of a framework I'm writing, so I'm pre-defining a lot of hooks I use in different places. I always store the hook object and use it directly for registration (to have the hook name defined in only one place), but I'm hitting a wall when using arguments with these objects. I'm using strict groups.

# Works fine
myhook = gossip.define("mygroup.testhook", arg_names=["some_arg"])

@myhook.register
def some_function(some_arg):
    pass
# Does not work: 
myhook = gossip.define("mygroup.testhook", arg_names=["some_arg"], tags=["test"])

@myhook.register(tags=["test"])
def some_function(some_arg):
    pass

I always end up with the following
TypeError: register() takes at least 2 arguments (2 given)

Do I need to wrap the register() call to get the functionality I want?

Cheers!
Tim

Hook priority/weight

Hello. Great job on this library! Very feature rich and easy to use.

I'm wondering if there's a way of specifying priority or weights when registering hooks. The provides/needs capabilities are not quite what I'm looking for. Glancing at the source code it seems there isn't a way of doing this in gossip, but maybe someone knows of a work-around?

This, and collecting all hook return values, are the only two things stopping me from completely ditching the blinker library.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.