Skip to content

Commit

Permalink
Address ruff PTH: part2 (#1780)
Browse files Browse the repository at this point in the history
* Address ruff PTH207

* Address ruff PTH119

* Address ruff PTH116
  • Loading branch information
shatakshiiii authored May 30, 2024
1 parent ba5b6d3 commit 492eb1e
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 18 deletions.
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,9 @@ ignore = [
'PTH110', # `os.path.exists()` should be replaced by `Path.exists()`
'PTH111', # `os.path.expanduser()` should be replaced by `Path.expanduser()`
'PTH113', # `os.path.isfile()` should be replaced by `Path.is_file()`
'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`
'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
'RUF012', # Mutable class attributes should be annotated with `typing.ClassVar`
Expand Down
6 changes: 1 addition & 5 deletions src/ansible_navigator/actions/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

import glob
import json
import os
import shlex
Expand Down Expand Up @@ -165,10 +164,7 @@ def _set_inventories_mtime(self) -> None:
for inventory in self._inventories:
if Path(inventory).is_dir():
modification_times.append(
max(
Path(e).stat().st_mtime
for e in glob.glob(os.path.join(inventory, "**"), recursive=True)
),
max(Path(e).stat().st_mtime for e in Path(inventory).rglob("*")),
)
elif os.path.isfile(inventory):
modification_times.append(Path(inventory).stat().st_mtime)
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 @@ -887,7 +887,7 @@ def write_artifact(self, filename: str | None = None) -> None:
filename = filename or self._args.playbook_artifact_save_as
filename = filename.format(
playbook_dir=os.path.dirname(playbook),
playbook_name=os.path.splitext(os.path.basename(playbook))[0],
playbook_name=os.path.splitext(Path(playbook).name)[0],
playbook_status=status,
time_stamp=now_iso(self._args.time_zone),
)
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_navigator/tm_tokenize/grammars.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def compiler_for_file(self, filename: str, first_line: str) -> Compiler:
for k in tuple(self._scope_to_files):
self._raw_for_scope(k)

_, _, ext = os.path.basename(filename).rpartition(".")
_, _, ext = Path(filename).name.rpartition(".")
for extensions, scope in self._file_types:
if ext in extensions:
return self.compiler_for_scope(scope)
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/diagnostics/test_from_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
from __future__ import annotations

import json
import os
import subprocess

from pathlib import Path
from typing import TYPE_CHECKING


if TYPE_CHECKING:
from pathlib import Path

import pytest

from ansible_navigator.configuration_subsystem.definitions import SettingsFileType
Expand Down Expand Up @@ -58,5 +56,5 @@ def test(
assert not section.get("errors")

# Test the file permissions as well since diagnostics takes time to run
status = os.stat(file_name)
status = Path(file_name).stat()
assert oct(status.st_mode)[-3:] == str(oct(0o600))[-3:]
2 changes: 1 addition & 1 deletion tests/integration/test_execution_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
class Test(Cli2Runner):
"""Test the use of ``execution-environment`` through to runner."""

TEST_DIR_NAME = os.path.basename(__file__).replace("test_", "").replace(".py", "")
TEST_DIR_NAME = Path(__file__).name.replace("test_", "").replace(".py", "")
TEST_FIXTURE_DIR = Path(FIXTURES_DIR) / "integration" / TEST_DIR_NAME

STDOUT = {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_execution_environment_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
class Test(Cli2Runner):
"""Test the use of ``execution-environment-image`` through to runner."""

TEST_DIR_NAME = os.path.basename(__file__).replace("test_", "").replace(".py", "")
TEST_DIR_NAME = Path(__file__).name.replace("test_", "").replace(".py", "")
TEST_FIXTURE_DIR = Path(FIXTURES_DIR) / "integration" / TEST_DIR_NAME

INTERACTIVE = {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_pass_environment_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
class Test(Cli2Runner):
"""Test the use of ``pass-environment-variable`` through to runner."""

TEST_DIR_NAME = os.path.basename(__file__).replace("test_", "").replace(".py", "")
TEST_DIR_NAME = Path(__file__).name.replace("test_", "").replace(".py", "")
TEST_FIXTURE_DIR = Path(FIXTURES_DIR) / "integration" / TEST_DIR_NAME

STDOUT = {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_set_environment_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
class Test(Cli2Runner):
"""Test the use of ``set-environment-variable`` through to runner."""

TEST_DIR_NAME = os.path.basename(__file__).replace("test_", "").replace(".py", "")
TEST_DIR_NAME = Path(__file__).name.replace("test_", "").replace(".py", "")
TEST_FIXTURE_DIR = Path(FIXTURES_DIR) / "integration" / TEST_DIR_NAME

STDOUT = {
Expand Down

0 comments on commit 492eb1e

Please sign in to comment.