Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address ruff PTH120 #1792

Merged
merged 8 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ ignore = [
'PT022', # [*] No teardown in fixture `cmd_in_tty`, use `return` instead of `yield`
'PTH109', # `os.getcwd()` should be replaced by `Path.cwd()`
'PTH118', # `os.path.join()` should be replaced by `Path` with `/` operator
'PTH120', # `os.path.dirname()` should be replaced by `Path.parent`
'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
4 changes: 2 additions & 2 deletions src/ansible_navigator/actions/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@
}

if isinstance(self._args.playbook, str):
playbook_dir = os.path.dirname(self._args.playbook)
playbook_dir = f"{Path(self._args.playbook).parent}"

Check warning on line 418 in src/ansible_navigator/actions/collections.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_navigator/actions/collections.py#L418

Added line #L418 was not covered by tests
else:
playbook_dir = os.getcwd()

Expand Down Expand Up @@ -566,7 +566,7 @@
"path"
].startswith(self._adjacent_collection_dir):
collection["__type"] = "bind_mount"
elif collection["path"].startswith(os.path.dirname(self._adjacent_collection_dir)):
elif collection["path"].startswith(f"{Path(self._adjacent_collection_dir).parent}"):
collection["__type"] = "bind_mount"
error = (
f"{collection['known_as']} was mounted and catalogued in the"
Expand Down
3 changes: 2 additions & 1 deletion src/ansible_navigator/actions/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import shlex
import shutil

from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any

Expand Down Expand Up @@ -177,7 +178,7 @@

if self._args.mode == "interactive":
if isinstance(self._args.playbook, str):
playbook_dir = os.path.dirname(self._args.playbook)
playbook_dir = f"{Path(self._args.playbook).parent}"

Check warning on line 181 in src/ansible_navigator/actions/doc.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_navigator/actions/doc.py#L181

Added line #L181 was not covered by tests
else:
playbook_dir = os.getcwd()
kwargs.update({"host_cwd": playbook_dir})
Expand Down
4 changes: 2 additions & 2 deletions src/ansible_navigator/actions/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ def write_artifact(self, filename: str | None = None) -> None:
playbook = next(k["playbook"] for k in self._plays.value)
filename = filename or self._args.playbook_artifact_save_as
filename = filename.format(
playbook_dir=os.path.dirname(playbook),
playbook_dir=Path(playbook).parent,
playbook_name=Path(playbook).stem,
playbook_status=status,
time_stamp=now_iso(self._args.time_zone),
Expand All @@ -896,7 +896,7 @@ def write_artifact(self, filename: str | None = None) -> None:
self._logger.debug("Resolved artifact file name set to %s", filename)

try:
Path(os.path.dirname(filename)).mkdir(parents=True, exist_ok=True)
Path(Path(filename).parent).mkdir(parents=True, exist_ok=True)
artifact = {
"version": "2.0.0",
"plays": self._plays.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def log_file(entry: SettingsEntry, config: ApplicationConfiguration) -> PostProc
exit_messages: list[ExitMessage] = []
entry.value.current = str(expand_path(entry.value.current))
try:
Path(os.path.dirname(entry.value.current)).mkdir(parents=True, exist_ok=True)
Path(Path(entry.value.current).parent).mkdir(parents=True, exist_ok=True)
Path(entry.value.current).touch()
except (OSError, FileNotFoundError) as exc:
exit_msgs = [
Expand Down
10 changes: 5 additions & 5 deletions src/ansible_navigator/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@
messages.append(LogMessage(level=logging.DEBUG, message=message))

path_errors = []
doc_cache_dir = os.path.dirname(collection_doc_cache_path)
doc_cache_dir = Path(collection_doc_cache_path).parent
try:
Path(doc_cache_dir).mkdir(parents=True, exist_ok=True)
doc_cache_dir.mkdir(parents=True, exist_ok=True)
except OSError as exc:
path_errors.append(f"Problem making directory: {doc_cache_dir}")
path_errors.append(f"Problem making directory: {doc_cache_dir!s}")

Check warning on line 114 in src/ansible_navigator/initialization.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_navigator/initialization.py#L114

Added line #L114 was not covered by tests
path_errors.append(f"Error was: {exc!s}")

if not os.access(os.path.dirname(collection_doc_cache_path), os.W_OK):
if not os.access(Path(collection_doc_cache_path).parent, os.W_OK):
path_errors.append("Directory not writable")

if not os.access(os.path.dirname(collection_doc_cache_path), os.R_OK):
if not os.access(Path(collection_doc_cache_path).parent, os.R_OK):
path_errors.append("Directory not readable")

if path_errors:
Expand Down
Loading