Skip to content

Commit

Permalink
Avoid None among plugin directories (#3162)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Jul 1, 2021
1 parent d6985be commit d71eb80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/molecule/provisioner/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import logging
import os
import shutil
from typing import List, Optional

from molecule import util
from molecule.api import drivers
Expand Down Expand Up @@ -782,7 +783,7 @@ def manage_inventory(self):
else:
self._link_or_update_vars()

def abs_path(self, path):
def abs_path(self, path: str) -> Optional[str]:
return util.abs_path(os.path.join(self._config.scenario.directory, path))

def _add_or_update_vars(self):
Expand Down Expand Up @@ -907,15 +908,15 @@ def _default_to_regular(self, d):

return d

def _get_plugin_directory(self):
def _get_plugin_directory(self) -> str:
return os.path.join(self.directory, "plugins")

def _get_modules_directories(self):
def _get_modules_directories(self) -> List[str]:
"""Return list of ansilbe module includes directories.
Adds modules directory from molecule and its plugins.
"""
paths = list()
paths: List[Optional[str]] = list()
if os.environ.get("ANSIBLE_LIBRARY"):
paths = list(map(util.abs_path, os.environ["ANSIBLE_LIBRARY"].split(":")))

Expand Down Expand Up @@ -945,7 +946,7 @@ def _get_modules_directories(self):
]
)

return paths
return [path for path in paths if path is not None]

def _get_filter_plugin_directory(self):
return util.abs_path(os.path.join(self._get_plugin_directory(), "filter"))
Expand Down
3 changes: 2 additions & 1 deletion src/molecule/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,11 @@ def filter_verbose_permutation(options):
return {k: options[k] for k in options if not re.match("^[v]+$", k)}


def abs_path(path):
def abs_path(path: str) -> Optional[str]:
"""Return absolute path."""
if path:
return os.path.abspath(path)
return None


def merge_dicts(a: MutableMapping, b: MutableMapping) -> MutableMapping:
Expand Down

0 comments on commit d71eb80

Please sign in to comment.