How embedding Python Source as Modules?

(Evgeny Kolosov) #1

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.

(Mathieu Westphal (Kitware)) #2

do not import it, just use it.

HelloWorldReader()

(Evgeny Kolosov) #3

it does not work too

(Mathieu Westphal (Kitware)) #4

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

(Evgeny Kolosov) #5

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?

(Ben Boeckel) #6

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?

(Evgeny Kolosov) #7

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.

(Ben Boeckel) #8

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?

(Ben Boeckel) #9

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?

(Evgeny Kolosov) #10

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?

(Evgeny Kolosov) #12

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

(Ben Boeckel) #13

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

(Ben Boeckel) #14

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

(Evgeny Kolosov) #15

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.

(Ben Boeckel) #16

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

(Evgeny Kolosov) #17

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