Check development with PyCharm and Syntax highlighting + code completion

Hi,

I’m trying to get PyCharm with a remote python interpreter to work with all the features I love to use, like syntax highlighting, code completion, debugging, etc.

My problem is now, that this line of code doesn’t work:

from .agent_based_api.v1 import *

To get around that I tried to use a custom bash script as python interpreter:

#!/bin/bash
export PYTHONPATH=/opt/omd/versions/2.0.0p15.cme/lib/python3/cmk/base/plugins/agent_based/
/opt/omd/versions/2.0.0p15.cme/bin/python3 $@

This improved the situation somehow.
Now this works:

from agent_based_api.v1 import *

(without the dot)

However, it’s very annoying to add and to remove this dot all the time, when I want to have the features available and when I want to commit the code.
So how can I setup a PyCharm environment correctly?

Thanks in advance,
Cheers,
Roland.

Hi,

i have added the CMK python lib paths to the interpreter setting in pycharm. Looks like this

In my plugins I use this format for imports

from cmk.base.plugins.agent_based.agent_based_api.v1 import (
    register,
    SNMPTree,
    TableRow,
    exists,
)

Not shure if this works with the remote interpreter as well.

cheers
Thomas

Thanks. Yes, it works with the absolute import on the remote interpreter as well.

Now, let’s see if we can take this one step further:
Is it possible to run the check in the CMK-Context directly inside PyCharm? If yes, how do I specify which host I’d like to check?

Cheers,
Roland.

Not shure on this, but I guess you can try it like in VS Code, Run cmk with all the needed parameters.
Like

cmk --plugins=your_plugin_name your_host_to_test_name_as_in_cmk

and have a break point in your plugin where you want to start debugging.

You might find some input about this here

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.