From 78597091b04a6b5e00903aace98cf18888ac64d7 Mon Sep 17 00:00:00 2001 From: Kate Case Date: Mon, 28 Oct 2024 09:54:58 -0400 Subject: [PATCH] Update abs_path to always return str --- src/molecule/command/base.py | 2 +- src/molecule/provisioner/ansible.py | 17 +++++++---------- src/molecule/util.py | 4 ++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/molecule/command/base.py b/src/molecule/command/base.py index dbad14d6b..029468337 100644 --- a/src/molecule/command/base.py +++ b/src/molecule/command/base.py @@ -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, diff --git a/src/molecule/provisioner/ansible.py b/src/molecule/provisioner/ansible.py index ddb259203..3d68da93f 100644 --- a/src/molecule/provisioner/ansible.py +++ b/src/molecule/provisioner/ansible.py @@ -27,6 +27,7 @@ import os import shutil +from pathlib import Path from typing import Any from ansible_compat.ports import cached_property @@ -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(), @@ -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 diff --git a/src/molecule/util.py b/src/molecule/util.py index 356c2d930..0470c61a5 100644 --- a/src/molecule/util.py +++ b/src/molecule/util.py @@ -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: @@ -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: