How embedding Python Source as Modules?

Hello.
I read the instruction https://www.paraview.org/Wiki/ParaView/Plugin_HowTo and build a simple HelloWorldRedaer but it doesn’t work. It load a dynamic library but can’t apply a HelloWorldReader reader.



What I doing wrong? Please, review my example.
HelloWorldReader.tar.gz (882 Bytes)

Thanks in advance.

do not import it, just use it.

HelloWorldReader()

it does not work too

I missed the fact that you are using a python module (as described in the Howto)

It is more simpler now, take a look into the paraview sources:
./Examples/Plugins/PythonAlgorithm/PythonAlgorithmExamples.py

Thanks, Mathieu.
Maybe I don’t understand but it is examples of clear python filters. And it’s working. But I can’t embedding python source as module (native dynamic library). Is it possible? What should I doing for that?

This wasn’t updated in the new module system because ParaView didn’t have any up-to-date plugins doing Python (.py) module loading. Do you have a plugin I could use to implement the functionality?

Ben, thanks for the reply. I have about 15 python plugins and I need embedding them. If you can update the example that I uploaded in the first message then I can rewrite my scripts for embedding.

OK, I’ll try and take a look at it. Thanks for the example. Mind if I add the HelloWorldReader to ParaView as an example when it’s ported?

This fixes ParaView’s module loading so that it can work: https://gitlab.kitware.com/paraview/paraview/merge_requests/3308. For your plugin, changing it to be an actual package (I did HelloWorldReader/{__init__.py,hello_world_reader.py}), it now loads properly. However, I don’t know how to actually use the plugin to get the proxy to show up in the File > Open dialog. @mwestphal @utkarsh.ayachit Any ideas?

Thank you, Ben.

Mind if I add the HelloWorldReader to ParaView as an example when it’s ported?

Yes of course you can add this example.

However, I don’t know how to actually use the plugin to get the proxy to show up in the File > Open dialog.

If I understand correctly, now it also does not work?

Offtopic: Can I autoload python based filters without using GUI (.pyc format is preferred) as a temporary solution?

Hmm, I don’t think so. @utkarsh.ayachit Is there a way to do that?

This is more likely me not knowing how to use the plugin :slight_smile: .

Offtopic: Can I autoload python based filters without using GUI (.pyc format is preferred) as a temporary solution?

I fixed vtkPVPluginLoader and now it’s possible to autoload python (.py format) filters without GUI. I can share it if need.

That’d be great!

So after talking here, it seems that here’s the current status:

  • The PYTHON_MODULES argument to paraview_add_plugin is working as-intended as of the above MR. This makes code available to import in the shell after loading the associated plugin
  • Proxy Python filters should be loaded directly through the load plugin dialog. This makes them available for use in the paraview.simple module.
  • What your example is doing is making a proxy in a module made available in a plugin. This is the intersection of the above two use cases and is not currently supported.

There are some obstacles to overcome before this can happen:

  • Separate client/server cases would need to make the proxy available on the server as well by loading the plugin and then importing the associated proxy.
  • Proxies are registered globally right now by inspecting the globals of the module after direct importing. The decorators would need to learn how to register upon being called instead.

I’ve filed an issue for this here: https://gitlab.kitware.com/paraview/paraview/issues/19063

I’ve filed an issue for this here: https://gitlab.kitware.com/paraview/paraview/issues/19065
and created a merge request with the implementation of this issue https://gitlab.kitware.com/paraview/paraview/merge_requests/3310