diff --git a/pyproject.toml b/pyproject.toml index ba50d81f1..9cf3b7c04 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -305,22 +305,16 @@ ignore = [ '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` 'PTH100', # `os.path.abspath()` should be replaced by `Path.resolve()` - 'PTH101', # `os.chmod()` should be replaced by `Path.chmod()` 'PTH103', # `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` - 'PTH107', # `os.remove()` should be replaced by `Path.unlink()` '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()` - 'PTH112', # `os.path.isdir()` should be replaced by `Path.is_dir()` 'PTH113', # `os.path.isfile()` should be replaced by `Path.is_file()` - 'PTH114', # `os.path.islink()` should be replaced by `Path.is_symlink()` - 'PTH115', # `os.readlink()` should be replaced by `Path.readlink()` 'PTH116', # `os.stat()` should be replaced by `Path.stat()`, `Path.owner()`, or `Path.group()` 'PTH118', # `os.path.join()` should be replaced by `Path` with `/` operator 'PTH119', # `os.path.basename()` should be replaced by `Path.name` 'PTH120', # `os.path.dirname()` should be replaced by `Path.parent` 'PTH122', # `os.path.splitext()` should be replaced by `Path.suffix` - 'PTH204', # `os.path.getmtime` should be replaced by `Path.stat().st_mtime` 'PTH207', # Replace `glob` with `Path.glob` or `Path.rglob` 'RET505', # Unnecessary `else` after `return` statement 'RUF005', # [*] Consider `[self._name, *shlex.split(self._interaction.action.match.groupdict()["params"] or "")]` instead of concatenation diff --git a/src/ansible_navigator/actions/inventory.py b/src/ansible_navigator/actions/inventory.py index 36b400829..75ab7c21f 100644 --- a/src/ansible_navigator/actions/inventory.py +++ b/src/ansible_navigator/actions/inventory.py @@ -163,15 +163,15 @@ def _set_inventories_mtime(self) -> None: """Record the inventory modification time.""" modification_times = [] for inventory in self._inventories: - if os.path.isdir(inventory): + if Path(inventory).is_dir(): modification_times.append( max( - os.path.getmtime(e) + Path(e).stat().st_mtime for e in glob.glob(os.path.join(inventory, "**"), recursive=True) ), ) elif os.path.isfile(inventory): - modification_times.append(os.path.getmtime(inventory)) + modification_times.append(Path(inventory).stat().st_mtime) if modification_times: self._inventories_mtime = max(modification_times) else: diff --git a/src/ansible_navigator/initialization.py b/src/ansible_navigator/initialization.py index 86bc1c21b..e494bd5e3 100644 --- a/src/ansible_navigator/initialization.py +++ b/src/ansible_navigator/initialization.py @@ -9,6 +9,7 @@ import os import sys +from pathlib import Path from typing import TYPE_CHECKING from typing import NoReturn @@ -135,7 +136,7 @@ def get_and_check_collection_doc_cache( message = "Collection doc cache: version was empty or incorrect, rebuilding" messages.append(LogMessage(level=logging.INFO, message=message)) collection_cache.close() - os.remove(collection_doc_cache_path) + Path(collection_doc_cache_path).unlink() collection_cache = KeyValueStore(collection_doc_cache_path) collection_cache["version"] = VERSION_CDC cache_version = collection_cache["version"] diff --git a/src/ansible_navigator/logger.py b/src/ansible_navigator/logger.py index f45c48fa7..b5a26af35 100644 --- a/src/ansible_navigator/logger.py +++ b/src/ansible_navigator/logger.py @@ -7,6 +7,7 @@ import os import zoneinfo +from pathlib import Path from typing import TYPE_CHECKING from typing import Any @@ -57,7 +58,7 @@ def setup_logger(args: ApplicationConfiguration) -> None: :param args: The CLI args """ if os.path.exists(args.log_file) and args.log_append is False: - os.remove(args.log_file) + Path(args.log_file).unlink() handler = logging.FileHandler(args.log_file) time_zone = args.entry("time_zone").value.current diff --git a/src/ansible_navigator/utils/functions.py b/src/ansible_navigator/utils/functions.py index 53a4914ae..26cc5d19f 100644 --- a/src/ansible_navigator/utils/functions.py +++ b/src/ansible_navigator/utils/functions.py @@ -503,7 +503,7 @@ def time_stamp_for_file(path: str, time_zone: str) -> tuple[float | None, str | :returns: The UNIX timestamp and an ISO 8601 string """ try: - modified = os.path.getmtime(path) + modified = Path(path).stat().st_mtime except FileNotFoundError: # It may have been mounted to a different location in the execution environment modified = None diff --git a/tests/conftest.py b/tests/conftest.py index 08215d6c2..3a2bff629 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -119,9 +119,9 @@ def locked_directory(tmpdir: str) -> Generator[str, None, None]: :param tmpdir: Fixture for temporary directory :yields: The temporary directory """ - os.chmod(tmpdir, 0o000) + Path(tmpdir).chmod(0o000) yield tmpdir - os.chmod(tmpdir, 0o777) + Path(tmpdir).chmod(0o777) @pytest.fixture(scope="session") diff --git a/tests/integration/_common.py b/tests/integration/_common.py index 40b8b45d8..a95a4ea83 100644 --- a/tests/integration/_common.py +++ b/tests/integration/_common.py @@ -217,10 +217,10 @@ def copytree( source_path = os.path.join(src, name) destination_path = os.path.join(dst, name) try: - if symlinks and os.path.islink(source_path): - source_link = os.readlink(source_path) + if symlinks and Path(source_path).is_symlink(): + source_link = Path(source_path).readlink() os.symlink(source_link, destination_path) - elif os.path.isdir(source_path): + elif Path(source_path).is_dir(): copytree( source_path, destination_path,