Skip to content

Commit 93798e8

Browse files
author
Stephen
authored
Search collections installed via package manager as well (pearofducks#130)
1 parent f8c503c commit 93798e8

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

UltiSnips/generate.py

+25-6
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,29 @@ def get_files_builtin() -> List[str]:
4343

4444
return sorted(file_names)
4545

46-
def get_files_user() -> List[str]:
47-
"""Return the sorted list of all module files provided by collections installed in the
48-
user home folder ~/.ansible/collections/
46+
47+
def get_files_collections(user: bool = False) -> List[str]:
48+
"""Return the sorted list of all module files provided by collections installed in either
49+
the system folder /usr/share/ansible/collections/ or user folder ~/.ansible/collections/
50+
51+
Parameters
52+
----------
53+
user: bool (default: False)
54+
A boolean indicating whether to get collections installed in the user folder
4955
5056
Returns
5157
-------
5258
List[str]
53-
A list of strings representing the Python module files installed in ~/.ansible/collections/
59+
A list of strings representing the Python module files provided by collections
5460
"""
5561

62+
if user:
63+
collection_path = '~/.ansible/collections/ansible_collections/'
64+
else:
65+
collection_path = '/usr/share/ansible/collections/ansible_collections/'
66+
5667
file_names: List[str] = []
57-
for root, dirs, files in os.walk(os.path.expanduser('~/.ansible/collections/ansible_collections/')):
68+
for root, dirs, files in os.walk(os.path.expanduser(collection_path)):
5869
files_without_symlinks = []
5970
for f in files:
6071
if not os.path.islink(os.path.join(root, f)):
@@ -353,8 +364,16 @@ def get_collection_name(filepath:str) -> str:
353364
docstring_builtin['collection_name'] = "ansible.builtin"
354365
modules_docstrings.append(docstring_builtin)
355366

367+
system_modules_paths = get_files_collections()
368+
for f in system_modules_paths:
369+
docstring_system = get_module_docstring(f)
370+
if docstring_system and docstring_system not in modules_docstrings:
371+
collection_name = get_collection_name(f)
372+
docstring_system['collection_name'] = collection_name
373+
modules_docstrings.append(docstring_system)
374+
356375
if args.user:
357-
user_modules_paths = get_files_user()
376+
user_modules_paths = get_files_collections(user=True)
358377
for f in user_modules_paths:
359378
docstring_user = get_module_docstring(f)
360379
if docstring_user and docstring_user not in modules_docstrings:

0 commit comments

Comments
 (0)