# Buggy code
def find_plugins(path, ptype, collection=None):
    display.vvvv("Searching %s for plugins" % path)

    plugin_list = set()

    if not os.path.exists(path):
        display.vvvv("%s does not exist" % path)
        return plugin_list

    if not os.path.isdir(path):
        display.vvvv("%s is not a directory" % path)
        return plugin_list

    bkey = ptype.upper()
    for plugin in os.listdir(path):
        display.vvvv("Found %s" % plugin)
        full_path = "/".join([path, plugin])

        if plugin.startswith("."):
            continue
        elif os.path.isdir(full_path):
            continue
        elif any(plugin.endswith(x) for x in C.BLACKLIST_EXTS):
            continue
        elif plugin.startswith("__"):
            continue
        elif plugin in C.IGNORE_FILES:
            continue
        elif plugin.startswith("_"):
            if os.path.islink(full_path):  # avoids aliases
                continue

        plugin = os.path.splitext(plugin)[0]  # removes the extension
        plugin = plugin.lstrip("_")  # remove underscore from deprecated plugins

        if plugin not in BLACKLIST.get(bkey, ()):
            if collection:
                plugin = "%s.%s" % (collection, plugin)

            plugin_list.add(plugin)
            display.vvvv("Added %s" % plugin)

    return plugin_list


# Traceback (ModuleNotFoundError)
ERROR: Command "importer.py" returned exit status 1.
Standard Error
Traceback (most recent call last):
File "/root/ansible/ansible_collections/community/kubernetes/tests/output/.tmp/sanity/import/minimal-py36/bin/importer.py", line 447, in <module>
main()
File "/root/ansible/ansible_collections/community/kubernetes/tests/output/.tmp/sanity/import/minimal-py36/bin/importer.py", line 51, in main
from ansible.utils.collection_loader import AnsibleCollectionLoader
File "/root/ansible/lib/ansible/utils/collection_loader.py", line 15, in <module>
from ansible import constants as C
File "/root/ansible/lib/ansible/constants.py", line 12, in <module>
from jinja2 import Template
ModuleNotFoundError: No module named 'jinja2'

# Fixed code
def find_plugins(path, ptype):
    display.vvvv("Searching %s for plugins" % path)

    plugin_list = set()

    if not os.path.exists(path):
        display.vvvv("%s does not exist" % path)
        return plugin_list

    if not os.path.isdir(path):
        display.vvvv("%s is not a directory" % path)
        return plugin_list

    bkey = ptype.upper()
    for plugin in os.listdir(path):
        display.vvvv("Found %s" % plugin)
        full_path = "/".join([path, plugin])

        if plugin.startswith("."):
            continue
        elif os.path.isdir(full_path):
            continue
        elif any(plugin.endswith(x) for x in C.BLACKLIST_EXTS):
            continue
        elif plugin.startswith("__"):
            continue
        elif plugin in C.IGNORE_FILES:
            continue
        elif plugin.startswith("_"):
            if os.path.islink(full_path):  # avoids aliases
                continue

        plugin = os.path.splitext(plugin)[0]  # removes the extension
        plugin = plugin.lstrip("_")  # remove underscore from deprecated plugins

        if plugin not in BLACKLIST.get(bkey, ()):
            plugin_list.add(plugin)
            display.vvvv("Added %s" % plugin)

    return plugin_list