Newbie question: how to organize Python files when developing module with some complex logic?

Hi,

I am currently developing an Ansible role, that allows me to sync some configuration by the means of the REST API of a 3rd party product to configure this product.

This involves some complex analysis and quite a couple of REST calls.

So I started implementing an Ansible module doing that sync.

I organized the main entry point of the module in the /library subdirectory of the role and the real implementation in the /module_utils directory within the role.

During the work I also did some refactoring of the code, extracting model classes in a model.py, and some other functionality to respective python files to keep things together.
I yet only am testing manually with a python file that just executes the functions in the files in the module_utils directory.

When I now tried it the first time from my Ansible playbook, it was unable to find the imports of the helper files in module_utils.
More precise: the primary class was imported to the module code with an import from ansible.module_util.my_python_file - but my_python_file imported the “sibbling” files directly.
The playbook execution now is complaining about unknown modules.
So my impression is, that I also would have to import a sibbling from “ansible.module_util.sibbling” instead of from “sibbling” only …
But this would disallow for local testing w/o using the ansible playbook.

What am I doing wrong ?
Should I treat the python code by itself, and create a pip package from it and just require this from the Module ?

How would you organize your files to be efficient during development ?

Thanks a lot!
Martin

Ok, I was able to solve part of the problem by using relative imports all over my module_utils code.

Single thing that still is annoying:
the module code itself still needs to import from ansible.module_utils… - what is not known by my IDE during development time.

Any thoughts to this ?

Thanks !