webgme / bindings

WebGME API bindings for Python
MIT License
1 stars 4 forks source link

Allow zmq server to also check for functions defined in the Plugin, not just PluginBase. #23

Closed umesh-timalsina closed 3 years ago

umesh-timalsina commented 3 years ago

I wanted to implement a get_artifact_metadata function for my python plugin. For that I implemented the following method in the Plugin files:

Javascript:

        async getArtifactMetadata(metadataHash) {
            return await this.blobClient.get(metadataHash);
        }

Python:

    def _get_artifact_metadata(self, metadata_hash):
        return self._send({
            'name': 'getArtifactMetadata',
            'args': [metadata_hash]
        })

This fails with the following error:

'Unexpected request name getArtifactMetadata of type [plugin]',
    type: 'Error',

It looks like the switchCase here doesn't take into consideration the functions that might have been defined in the plugin instance that inherits from plugin base.

I think this behavior should be supported. Because there might be functions like the one above, which don't need to be added to PluginBase but might provide nice utility to python plugin itself.

kecso commented 3 years ago

The zeromq interface is a curated one and that is why only functions that was thought to be necessary for execution plugins implemented in python were allowed. Also, low level functions (like _send) should not be called directly from your own plugin implementation. On the other hand I agree that for the experienced audience, this option would allow to overcome some of the shortcomings of the language bridge zeromq means for the plugin. Given some proper logging - that it is dangerous to use this approach if you are not aware of the capabilities of zeromq + js plugins + webgme in general - I can see it working. I will try to add it to the package and create a new npm package.