Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search collections installed via package manager as well #130

Merged
merged 2 commits into from
Feb 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 25 additions & 6 deletions UltiSnips/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,29 @@ def get_files_builtin() -> List[str]:

return sorted(file_names)

def get_files_user() -> List[str]:
"""Return the sorted list of all module files provided by collections installed in the
user home folder ~/.ansible/collections/

def get_files_collections(user: bool = False) -> List[str]:
"""Return the sorted list of all module files provided by collections installed in either
the system folder /usr/share/ansible/collections/ or user folder ~/.ansible/collections/

Parameters
----------
user: bool (default: False)
A boolean indicating whether to get collections installed in the user folder

Returns
-------
List[str]
A list of strings representing the Python module files installed in ~/.ansible/collections/
A list of strings representing the Python module files provided by collections
"""

if user:
collection_path = '~/.ansible/collections/ansible_collections/'
else:
collection_path = '/usr/share/ansible/collections/ansible_collections/'

file_names: List[str] = []
for root, dirs, files in os.walk(os.path.expanduser('~/.ansible/collections/ansible_collections/')):
for root, dirs, files in os.walk(os.path.expanduser(collection_path)):
files_without_symlinks = []
for f in files:
if not os.path.islink(os.path.join(root, f)):
Expand Down Expand Up @@ -353,8 +364,16 @@ def get_collection_name(filepath:str) -> str:
docstring_builtin['collection_name'] = "ansible.builtin"
modules_docstrings.append(docstring_builtin)

system_modules_paths = get_files_collections()
for f in system_modules_paths:
docstring_system = get_module_docstring(f)
if docstring_system and docstring_system not in modules_docstrings:
collection_name = get_collection_name(f)
docstring_system['collection_name'] = collection_name
modules_docstrings.append(docstring_system)

if args.user:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default behavior for --user remains the same since get_files_collections(user=True) is behind this if statement.

user_modules_paths = get_files_user()
user_modules_paths = get_files_collections(user=True)
for f in user_modules_paths:
docstring_user = get_module_docstring(f)
if docstring_user and docstring_user not in modules_docstrings:
Expand Down