Yes, this is clear, but then it will point to the "installed" collection.
Unless developing directly in the ~/.ansible/collections or using symlinks
like Brian mentioned above, this won't use the files from my dev directory.

I was looking for a way to make my local files in a dir that doesn't belong
to ~/.ansible/collections or any other dir structure that I can use in a
collections_path appear in dir that will resolve.

Will move my dev dir to a predefined structure otherwise.

On Wed, Feb 22, 2023 at 10:04 PM Matt Martz <m...@sivel.net> wrote:

> 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 <dodin.ro...@gmail.com> 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 <bc...@redhat.com> 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 <bc...@redhat.com> 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 ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/CAFBEvLuOaS-1De52a1PgHOaCL9d9qErvtE1%3DzPhVvYLRrka_sg%40mail.gmail.com.

Reply via email to