Skip to content

Commit

Permalink
Address ruff PTH109
Browse files Browse the repository at this point in the history
  • Loading branch information
shatakshiiii committed Jun 13, 2024
1 parent a968138 commit a8eb8a7
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 17 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_navigator/actions/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ansible_navigator/actions/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/ansible_navigator/actions/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions src/ansible_navigator/actions/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions src/ansible_navigator/actions/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

import json
import os
import shlex
import shutil

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/ansible_navigator/actions/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_navigator/actions/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,8 +28,6 @@


if TYPE_CHECKING:
from pathlib import Path

from ansible_navigator.utils.key_value_store import KeyValueStore


Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/utils/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a8eb8a7

Please sign in to comment.