Skip to content

Commit

Permalink
Update abs_path to always return str
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos committed Oct 28, 2024
1 parent 30e97b5 commit 7859709
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/molecule/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def get_configs(
scenario_paths = filter_ignored_scenarios(scenario_paths)
configs = [
config.Config(
molecule_file=util.abs_path(c), # type: ignore[arg-type]
molecule_file=util.abs_path(c),
args=args,
command_args=command_args,
ansible_args=ansible_args,
Expand Down
17 changes: 7 additions & 10 deletions src/molecule/provisioner/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import os
import shutil

from pathlib import Path
from typing import Any

from ansible_compat.ports import cached_property
Expand Down Expand Up @@ -520,8 +521,8 @@ def default_env(self): # type: ignore[no-untyped-def] # noqa: ANN201, D102
os.environ,
{
"ANSIBLE_CONFIG": self._config.provisioner.config_file,
"ANSIBLE_ROLES_PATH": ":".join(roles_path_list), # type: ignore[arg-type]
self._config.ansible_collections_path: ":".join(collections_path_list), # type: ignore[arg-type]
"ANSIBLE_ROLES_PATH": ":".join(roles_path_list),
self._config.ansible_collections_path: ":".join(collections_path_list),
"ANSIBLE_LIBRARY": ":".join(self._get_modules_directories()),
"ANSIBLE_FILTER_PLUGINS": ":".join(
self._get_filter_plugins_directories(),
Expand Down Expand Up @@ -804,17 +805,13 @@ def _add_or_update_vars(self): # type: ignore[no-untyped-def] # noqa: ANN202
vars_target = self.group_vars

if vars_target:
target_vars_directory = os.path.join( # noqa: PTH118
self.inventory_directory,
target,
)

if not os.path.isdir(util.abs_path(target_vars_directory)): # type: ignore[arg-type] # noqa: PTH112
os.mkdir(util.abs_path(target_vars_directory)) # type: ignore[arg-type] # noqa: PTH102
target_vars_directory = Path(util.abs_path(Path(self.inventory_directory) / target))
if not target_vars_directory.is_dir():
target_vars_directory.mkdir()

for target in vars_target: # noqa: PLW2901
target_var_content = vars_target[target]
path = os.path.join(util.abs_path(target_vars_directory), target) # type: ignore[arg-type] # noqa: PTH118
path = target_vars_directory / target
util.write_file(path, util.safe_dump(target_var_content))

def _write_inventory(self): # type: ignore[no-untyped-def] # noqa: ANN202
Expand Down
4 changes: 2 additions & 2 deletions src/molecule/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def filter_verbose_permutation(options: dict[str, Any]) -> dict[str, Any]:
return {k: options[k] for k in options if not re.match("^[v]+$", k)}


def abs_path(path: str | Path | None) -> str | None:
def abs_path(path: str | Path | None) -> str:
"""Return absolute path.
Args:
Expand All @@ -408,7 +408,7 @@ def abs_path(path: str | Path | None) -> str | None:
path = Path(path)

return str(path.resolve())
return None
return ""


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

0 comments on commit 7859709

Please sign in to comment.