Skip to content

Commit af827c1

Browse files
committed
Use pathlib instead of os for Path operations
1 parent 7f7ee7d commit af827c1

File tree

7 files changed

+9
-13
lines changed

7 files changed

+9
-13
lines changed

infrahub_sdk/checks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import importlib
44
import inspect
5-
import os
5+
import pathlib
66
import warnings
77
from abc import abstractmethod
88
from typing import TYPE_CHECKING, Any
@@ -55,7 +55,7 @@ def __init__(
5555
self.branch = branch
5656
self.params = params or {}
5757

58-
self.root_directory = root_directory or os.getcwd()
58+
self.root_directory = root_directory or str(pathlib.Path.cwd())
5959

6060
self._client = client
6161

infrahub_sdk/operation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
import os
3+
import pathlib
44
from typing import TYPE_CHECKING
55

66
from .repository import GitRepoManager
@@ -22,7 +22,7 @@ def __init__(
2222
) -> None:
2323
self.branch = branch
2424
self.convert_query_response = convert_query_response
25-
self.root_directory = root_directory or os.getcwd()
25+
self.root_directory = root_directory or str(pathlib.Path.cwd())
2626
self.infrahub_node = infrahub_node
2727
self._nodes: list[InfrahubNode] = []
2828
self._related_nodes: list[InfrahubNode] = []

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,6 @@ ignore = [
255255
"PLR6301", # Method could be a function, class method, or static method
256256
"PLW0603", # Using the global statement to update `SETTINGS` is discouraged
257257
"PLW1641", # Object does not implement `__hash__` method
258-
"PTH100", # `os.path.abspath()` should be replaced by `Path.resolve()`
259-
"PTH109", # `os.getcwd()` should be replaced by `Path.cwd()`
260258
"RUF005", # Consider `[*path, str(key)]` instead of concatenation
261259
"RUF029", # Function is declared `async`, but doesn't `await` or use `async` features.
262260
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes

tests/helpers/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
def change_directory(new_directory: str) -> Generator[None, None, None]:
1616
"""Helper function used to change directories in a with block."""
1717
# Save the current working directory
18-
original_directory = os.getcwd()
18+
original_directory = Path.cwd()
1919

2020
# Change to the new directory
2121
try:
@@ -30,7 +30,7 @@ def change_directory(new_directory: str) -> Generator[None, None, None]:
3030
@contextmanager
3131
def temp_repo_and_cd(source_dir: Path) -> Generator[Path, None, None]:
3232
temp_dir = tempfile.mkdtemp()
33-
original_directory = os.getcwd()
33+
original_directory = Path.cwd()
3434

3535
try:
3636
shutil.copytree(source_dir, temp_dir, dirs_exist_ok=True)

tests/integration/test_infrahubctl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
if TYPE_CHECKING:
2323
from infrahub_sdk import InfrahubClient
2424

25-
FIXTURE_BASE_DIR = Path(Path(os.path.abspath(__file__)).parent / ".." / "fixtures")
25+
FIXTURE_BASE_DIR = Path(Path(Path(__file__).resolve()).parent / ".." / "fixtures")
2626

2727

2828
runner = CliRunner()

tests/unit/ctl/test_render_app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import os
32
from dataclasses import dataclass
43
from pathlib import Path
54

@@ -14,7 +13,7 @@
1413
runner = CliRunner()
1514

1615

17-
FIXTURE_BASE_DIR = Path(Path(os.path.abspath(__file__)).parent / ".." / ".." / "fixtures" / "repos")
16+
FIXTURE_BASE_DIR = Path(Path(Path(__file__).resolve()).parent / ".." / ".." / "fixtures" / "repos")
1817

1918

2019
@dataclass

tests/unit/ctl/test_transform_app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Integration tests for infrahubctl commands."""
22

33
import json
4-
import os
54
import shutil
65
import tempfile
76
from collections.abc import Generator
@@ -20,7 +19,7 @@
2019

2120

2221
FIXTURE_BASE_DIR = Path(
23-
Path(os.path.abspath(__file__)).parent / ".." / ".." / "fixtures" / "integration" / "test_infrahubctl"
22+
Path(Path(__file__).resolve()).parent / ".." / ".." / "fixtures" / "integration" / "test_infrahubctl"
2423
)
2524

2625

0 commit comments

Comments
 (0)