As mentioned, you need to set `PYTHONPATH` in your IDE to the directory containing `ansible_collections`. Like: `PYTHONPATH=~/.ansible/collections`.
I don't use a fancy IDE, so I don't have any direct guidance on where you would need to set this. Maybe the IDE doesn't respect this environment variable, or has other ways to configure it. Effectively, the `ansible_collections/` directory is similar to a Python namespace package, and the `collections/` directory is similar to `site-packages` used by python. So you just need to point `PYTHONPATH` or whatever else your IDE may use to all collections paths that ansible is configured to consult. I mentioned this in my original reply. On Wed, Feb 22, 2023 at 2:59 PM Roman Dodin <[email protected]> wrote: > As for the 2nd question the only workaround I found is to use relative > imports, which I want to get rid of. > Let me give you an example. In my collection dir I have the plugins subdir > that has: > > plugins > ├── httpapi > │ └── sr.py > ├── module_utils > │ └── sr.py > └── modules > └── get.py > > In my get.py I have to import a class from module_utils, and the full > import path looks like > > from > ansible_collections.<namespace>.<collection>.plugins.module_utils.srlinux > import MyClass > > How do I make my python instance to resolve this path? I understand that > at runtime ansible does add collections dir to the PYTHONPATH (or something > of sorts), but without running ansible, how do i make my dev environment to > resolve this path? > > Thank you all for your help and valuable inputs. > > PS. I can solve this with a relative path like > > from ..module_utils.sr import MyClass > > but I would like to not use relative imports if possible. > > > On Wed, Feb 22, 2023 at 9:48 PM Brian Coca <[email protected]> wrote: > >> ls -l ~/.ansible/collections/ansible_collections/ >> total 20 >> lrwxrwxrwx 1 bcoca bcoca 54 Oct 7 2021 bcoca -> >> /home/bcoca/work/collections/ansible_collections/bcoca >> >> On Wed, Feb 22, 2023 at 3:45 PM Brian Coca <[email protected]> wrote: >> > >> > symlinks do work, but you still need an ansible_collections/ dir >> > before your collection >> > >> > >> > >> > >> > -- >> > ---------- >> > Brian Coca >> >> >> >> -- >> ---------- >> Brian Coca >> >> -- Matt Martz @sivel sivel.net -- You received this message because you are subscribed to the Google Groups "Ansible Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/CAD8N0v_F5%2Bg%2BVH4Po-bf%3DTdti1%2Bkk_H5Qw2Pa5Cc6gX%3DR%3D4Qfg%40mail.gmail.com.
