Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Autoproxying helpers to automatically register the outputs of functions #87

Open
mawildoer opened this issue Jan 31, 2024 · 4 comments

Comments

@mawildoer
Copy link

Hello!

I've been using the autoproxying features of Pyro to interact with a heavily OO API kicad-python, that returns/yields lots of other rich/custom objects.

I wanted to maintain the existing interface for the sake of remote/local compatibility, so I came up with these helper decorators to automatically register returned objects:

def register_return(method):
    """Decorator to register the return value
    of a method in the Pyro daemon."""
    @wraps(method)
    def wrapper(self, *args, **kwargs):
        daemon = self._pyroDaemon
        result = method(self, *args, **kwargs)
        daemon.register(result)
        return result

    return wrapper


def register_yielded(method):
    """Decorator to register the return value
    of a method in the Pyro daemon."""
    @wraps(method)
    def wrapper(self, *args, **kwargs):
        daemon = self._pyroDaemon
        generator = method(self, *args, **kwargs)
        for result in generator:
            daemon.register(result)
            yield result
    return wrapper

I feel like there's perhaps a simpler way I'm missing, but if there isn't perhaps this would be a useful util we can include in Pyro for others?

@mawildoer mawildoer changed the title Autoproxying helpers to automatically register the outputs of functions [Feature] Autoproxying helpers to automatically register the outputs of functions Jan 31, 2024
@irmen
Copy link
Owner

irmen commented Feb 1, 2024

Personally I prefer writing explicit adapter classes to have full control over what is happening, but I can appreciate some simple generic wrappers to get "the bulk done" if you will.
I guess you've looked at the "thirdpartylib" example?

@mawildoer
Copy link
Author

I did! In my case I'm attempting to adapt an existing class that itself already wraps another interface and I don't want to wrap it again since there's quite a lot of methods and returns involved!

Here's a link to one of the files in question: https://github.com/atait/kicad-python/pull/4/files#diff-ecd96c7f47e6b5011bec5c67da46ffe55af26c39ffa89e63b2aa55792008e0a1

@TheSven73
Copy link

@mawildoer did you get kicad-python to work using Pyro5 autoproxies? If so, did you run into #92 ?

@mawildoer
Copy link
Author

@TheSven73 I certainly didn't take a rigorous route through this one and it was a while ago, but I don't recall running into that issue. Sorry I can't be of more help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants