diff --git a/pyproject.toml b/pyproject.toml index 677b61cc5..ab7c879a6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -299,7 +299,6 @@ ignore = [ 'PT005', # Fixture `_settings_samples` returns a value, remove leading underscore 'PT019', # Fixture `_mocked_func` without value is injected as parameter, use `@pytest.mark.usefixtures` instead 'PT022', # [*] No teardown in fixture `cmd_in_tty`, use `return` instead of `yield` - 'PTH109', # `os.getcwd()` should be replaced by `Path.cwd()` 'PTH110', # `os.path.exists()` should be replaced by `Path.exists()` 'PTH111', # `os.path.expanduser()` should be replaced by `Path.expanduser()` 'PTH118', # `os.path.join()` should be replaced by `Path` with `/` operator diff --git a/src/ansible_navigator/actions/collections.py b/src/ansible_navigator/actions/collections.py index fdca7f276..33e925f62 100644 --- a/src/ansible_navigator/actions/collections.py +++ b/src/ansible_navigator/actions/collections.py @@ -417,7 +417,7 @@ def _run_runner(self) -> None: if isinstance(self._args.playbook, str): playbook_dir = os.path.dirname(self._args.playbook) else: - playbook_dir = os.getcwd() + playbook_dir = os.getcwd() # noqa:PTH109 if isinstance(self._args.execution_environment_volume_mounts, list): kwargs["container_volume_mounts"] = self._args.execution_environment_volume_mounts diff --git a/src/ansible_navigator/actions/config.py b/src/ansible_navigator/actions/config.py index 65ca59440..4bba1b4a9 100644 --- a/src/ansible_navigator/actions/config.py +++ b/src/ansible_navigator/actions/config.py @@ -3,11 +3,11 @@ from __future__ import annotations import curses -import os import re import shlex import shutil +from pathlib import Path from typing import TYPE_CHECKING from typing import Any @@ -236,7 +236,7 @@ def _run_runner(self) -> tuple[str, str, int] | None: kwargs = { "container_engine": self._args.container_engine, - "host_cwd": os.getcwd(), + "host_cwd": Path.cwd(), "execution_environment_image": self._args.execution_environment_image, "execution_environment": self._args.execution_environment, "navigator_mode": self._args.mode, diff --git a/src/ansible_navigator/actions/doc.py b/src/ansible_navigator/actions/doc.py index 76fea322d..a02970b99 100644 --- a/src/ansible_navigator/actions/doc.py +++ b/src/ansible_navigator/actions/doc.py @@ -179,7 +179,7 @@ def _run_runner(self) -> dict[Any, Any] | tuple[str, str, int] | None: if isinstance(self._args.playbook, str): playbook_dir = os.path.dirname(self._args.playbook) else: - playbook_dir = os.getcwd() + playbook_dir = os.getcwd() # noqa:PTH109 kwargs.update({"host_cwd": playbook_dir}) self._runner = AnsibleDoc(**kwargs) @@ -202,7 +202,7 @@ def _run_runner(self) -> dict[Any, Any] | tuple[str, str, int] | None: plugin_doc_response = self._extract_plugin_doc(plugin_doc, plugin_doc_err) return plugin_doc_response else: - kwargs.update({"host_cwd": os.getcwd()}) + kwargs.update({"host_cwd": os.getcwd()}) # noqa:PTH109 if self._args.execution_environment: ansible_doc_path = "ansible-doc" else: diff --git a/src/ansible_navigator/actions/exec.py b/src/ansible_navigator/actions/exec.py index c97d90475..65a446ad6 100644 --- a/src/ansible_navigator/actions/exec.py +++ b/src/ansible_navigator/actions/exec.py @@ -3,9 +3,10 @@ from __future__ import annotations import logging -import os import shlex +from pathlib import Path + from ansible_navigator.action_base import ActionBase from ansible_navigator.action_defs import RunStdoutReturn from ansible_navigator.configuration_subsystem.definitions import ApplicationConfiguration @@ -121,7 +122,7 @@ def _run_runner(self) -> tuple[str, str, int] | None: kwargs = { "container_engine": self._args.container_engine, - "host_cwd": os.getcwd(), + "host_cwd": Path.cwd(), "execution_environment_image": self._args.execution_environment_image, "execution_environment": self._args.execution_environment, "navigator_mode": self._args.mode, diff --git a/src/ansible_navigator/actions/inventory.py b/src/ansible_navigator/actions/inventory.py index f2d54bc27..5a4fbfd2c 100644 --- a/src/ansible_navigator/actions/inventory.py +++ b/src/ansible_navigator/actions/inventory.py @@ -3,7 +3,6 @@ from __future__ import annotations import json -import os import shlex import shutil @@ -458,7 +457,7 @@ def _collect_inventory_details_interactive( source = "derived from playbook" else: # or the current working directory - playbook_dir = os.getcwd() + playbook_dir = Path.cwd() source = "CWD" self._logger.info("--playbook-directory for inventory from (%s): %s", source, playbook_dir) @@ -540,7 +539,7 @@ def _collect_inventory_details( kwargs = { "container_engine": self._args.container_engine, - "host_cwd": os.getcwd(), + "host_cwd": Path.cwd(), "execution_environment_image": self._args.execution_environment_image, "execution_environment": self._args.execution_environment, "navigator_mode": self._args.mode, diff --git a/src/ansible_navigator/actions/lint.py b/src/ansible_navigator/actions/lint.py index 0268076b3..b20780844 100644 --- a/src/ansible_navigator/actions/lint.py +++ b/src/ansible_navigator/actions/lint.py @@ -24,6 +24,7 @@ from datetime import datetime from datetime import timezone from enum import IntEnum +from pathlib import Path from typing import TYPE_CHECKING from typing import Any @@ -237,7 +238,7 @@ def _run_runner(self) -> tuple[str, str, int]: "private_data_dir": self._args.ansible_runner_artifact_dir, "rotate_artifacts": self._args.ansible_runner_rotate_artifacts_count, "timeout": self._args.ansible_runner_timeout, - "host_cwd": os.getcwd(), + "host_cwd": Path.cwd(), } if isinstance(self._args.execution_environment_volume_mounts, list): diff --git a/src/ansible_navigator/actions/run.py b/src/ansible_navigator/actions/run.py index 4735a8727..d9c5326c8 100644 --- a/src/ansible_navigator/actions/run.py +++ b/src/ansible_navigator/actions/run.py @@ -580,7 +580,7 @@ def _run_runner(self) -> None: kwargs = { "container_engine": self._args.container_engine, - "host_cwd": os.getcwd(), + "host_cwd": Path.cwd(), "execution_environment_image": self._args.execution_environment_image, "execution_environment": self._args.execution_environment, "inventory": self._args.inventory, diff --git a/src/ansible_navigator/configuration_subsystem/navigator_configuration.py b/src/ansible_navigator/configuration_subsystem/navigator_configuration.py index b4891d102..846f81e2f 100644 --- a/src/ansible_navigator/configuration_subsystem/navigator_configuration.py +++ b/src/ansible_navigator/configuration_subsystem/navigator_configuration.py @@ -7,6 +7,7 @@ from dataclasses import dataclass from dataclasses import field +from pathlib import Path from typing import TYPE_CHECKING from ansible_navigator.utils.definitions import ExitMessage @@ -27,8 +28,6 @@ if TYPE_CHECKING: - from pathlib import Path - from ansible_navigator.utils.key_value_store import KeyValueStore @@ -776,7 +775,7 @@ class Internals: short_description="Specify the path that contains ansible-builder manifest files", subcommands=["builder"], value=SettingsEntryValue( - default=os.getcwd(), + default=Path.cwd(), schema_default=".", ), version_added="v2.0", diff --git a/tests/unit/utils/test_functions.py b/tests/unit/utils/test_functions.py index be7ee098f..56c632f7c 100644 --- a/tests/unit/utils/test_functions.py +++ b/tests/unit/utils/test_functions.py @@ -50,7 +50,7 @@ def test_find_many_settings_cwd(monkeypatch: pytest.MonkeyPatch) -> None: :param monkeypatch: The monkeypatch fixture """ - paths = [os.path.join(os.getcwd(), "ansible-navigator" + ext) for ext in EXTENSIONS] + paths = [os.path.join(Path.cwd(), "ansible-navigator" + ext) for ext in EXTENSIONS] def check_path_exists(arg: Any) -> bool: return str(arg) in paths