collection_prep icon indicating copy to clipboard operation
collection_prep copied to clipboard

collection_prep_add_docs: Search for plugins/doc_fragments in the working directory

Open mariolenz opened this issue 3 years ago • 1 comments

It looks like collection_prep_add_docs -p . looks for plugins/doc_fragments in the collection search path, not in the current directory (see community.vmware#1062 ff).

I think that not searching for plugins/doc_fragments in the directory defined with -p breaks the principle of least astonishment.

mariolenz avatar Oct 04 '21 16:10 mariolenz

Ran into this issue the other day. I do expect collection prep to look for fragments in the same base path as modules from the collection, too.

The easy workaround for this is run a collection installation before running collection_prep:

ansible-galaxy collection build --force
export COLL=$(ls ansible-collection*) && pipenv run ansible-galaxy collection install $COLL --force

I want to add the actual error message. The error message indicates that the issue is not easy to fix as the doc generation is integrated from the ansible python module site-packages/ansible/utils/plugin_docs.py. I did not check if plugin_docs is able to take a custom path as input.

Traceback (most recent call last):
  File "/root/.local/share/virtualenvs/Ansible.Collection-4Fc_I88C/bin/collection_prep_add_docs", line 8, in <module>
    sys.exit(main())
  File "/root/.local/share/virtualenvs/Ansible.Collection-4Fc_I88C/lib/python3.8/site-packages/collection_prep/cmd/add_docs.py", line 549, in main
    content = process(collection=collection, path=path)
  File "/root/.local/share/virtualenvs/Ansible.Collection-4Fc_I88C/lib/python3.8/site-packages/collection_prep/cmd/add_docs.py", line 333, in process
    ) = plugin_docs.get_docstring(fullpath, fragment_loader)
  File "/root/.local/share/virtualenvs/Ansible.Collection-4Fc_I88C/lib/python3.8/site-packages/ansible/utils/plugin_docs.py", line 217, in get_docstring
    add_fragments(data['doc'], filename, fragment_loader=fragment_loader, is_module=is_module)
  File "/root/.local/share/virtualenvs/Ansible.Collection-4Fc_I88C/lib/python3.8/site-packages/ansible/utils/plugin_docs.py", line 201, in add_fragments
    raise AnsibleError('unknown doc_fragment(s) in file {0}: {1}'.format(filename, to_native(', '.join(unknown_fragments))))
ansible.errors.AnsibleError: unknown doc_fragment(s) in file /opt/git_azure/Ansible.Collection/plugins/modules/my_module_item.py: ansible.collection.module_fragment

phospi avatar Feb 10 '22 12:02 phospi