Skip to content

Conversation

@trinitronx
Copy link

@trinitronx trinitronx commented Nov 17, 2025

This fixes the following error1 when running collection_prep_add_docs -p path/to/a_collection:

$ collection_prep_add_docs -p ./

[WARNING]: Deprecation warnings can be disabled by setting `deprecation_warnings=False` in ansible.cfg.
[DEPRECATION WARNING]: DEFAULT_MANAGED_STR option. Reason: The `ansible_managed` variable can be set just like any other variable, or a different variable can be used.
Alternatives: Set the `ansible_managed` variable, or use any custom variable in templates. This feature will be removed from ansible-core version 2.23.

[DEPRECATION WARNING]: Importing 'to_text' from 'ansible.module_utils._text' is deprecated. This feature will be removed from ansible-core version 2.24. Use ansible.module_utils.common.text.converters instead.
INFO      Setting collection name to example.collection
INFO      Setting GitHub repository url to https://github.com/example/ansible_example_collection
INFO      Collection path is /home/exampleuser/src/pub/ansible/ansible_example_collection
Traceback (most recent call last):
  File "/usr/local/bin/collection_prep_add_docs", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.12/site-packages/collection_prep/cmd/add_docs.py", line 546, in main
    tempdir = add_collection(path, galaxy)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/collection_prep/cmd/add_docs.py", line 464, in add_collection
    _AnsibleCollectionFinder(  # pylint: disable-msg=protected-access
  File "/usr/local/lib/python3.12/site-packages/ansible/utils/collection_loader/_collection_finder.py", line 195, in __init__
    paths = [os.path.expanduser(_to_text(p)) for p in paths]
                                ^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/ansible/utils/collection_loader/__init__.py", line 37, in _to_text
    raise TypeError(f'unsupported type {type(value)}')
TypeError: unsupported type <class 'pathlib.PosixPath'>

Footnotes

  1. Note: Ansible core _AnsibleCollectionFinder code still uses deprecated internal _to_text method (as of Ansible 2.20.0), which does not handle pathlib.PosixPath. Meanwhile, to_text from ansible.module_utils.common.text.converters now does. Therefore, we can convert to text here using the public to_text import if available in newer Ansible versions, else fall back to the old import.

@trinitronx
Copy link
Author

Note: The pylint pre-commit hook appears broken. Therefore, CI failures are unrelated to this change.

All other hooks are passing:

$ pre-commit run  --all-files
ruff.....................................................................Passed
prettier.................................................................Passed
black....................................................................Passed
Spell check with cspell..................................................Passed
Tabs remover.............................................................Passed
check for merge conflicts................................................Passed
check for broken symlinks............................(no files to check)Skipped
debug statements (python)................................................Passed
fix end of files.........................................................Passed
fix utf-8 byte order marker..............................................Passed
don't commit to branch...................................................Passed
trim trailing whitespace.................................................Passed
codespell................................................................Passed
yamllint.................................................................Passed
darglint.................................................................Passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant