diff --git a/infrahub_sdk/checks.py b/infrahub_sdk/checks.py index e1dfc404..a68ce0d4 100644 --- a/infrahub_sdk/checks.py +++ b/infrahub_sdk/checks.py @@ -2,7 +2,7 @@ import importlib import inspect -import os +import pathlib import warnings from abc import abstractmethod from typing import TYPE_CHECKING, Any @@ -55,7 +55,7 @@ def __init__( self.branch = branch self.params = params or {} - self.root_directory = root_directory or os.getcwd() + self.root_directory = root_directory or str(pathlib.Path.cwd()) self._client = client diff --git a/infrahub_sdk/operation.py b/infrahub_sdk/operation.py index 3ae3d9c9..ed0bf19a 100644 --- a/infrahub_sdk/operation.py +++ b/infrahub_sdk/operation.py @@ -1,6 +1,6 @@ from __future__ import annotations -import os +import pathlib from typing import TYPE_CHECKING from .repository import GitRepoManager @@ -22,7 +22,7 @@ def __init__( ) -> None: self.branch = branch self.convert_query_response = convert_query_response - self.root_directory = root_directory or os.getcwd() + self.root_directory = root_directory or str(pathlib.Path.cwd()) self.infrahub_node = infrahub_node self._nodes: list[InfrahubNode] = [] self._related_nodes: list[InfrahubNode] = [] diff --git a/pyproject.toml b/pyproject.toml index cbbabf57..99466282 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -255,8 +255,6 @@ ignore = [ "PLR6301", # Method could be a function, class method, or static method "PLW0603", # Using the global statement to update `SETTINGS` is discouraged "PLW1641", # Object does not implement `__hash__` method - "PTH100", # `os.path.abspath()` should be replaced by `Path.resolve()` - "PTH109", # `os.getcwd()` should be replaced by `Path.cwd()` "RUF005", # Consider `[*path, str(key)]` instead of concatenation "RUF029", # Function is declared `async`, but doesn't `await` or use `async` features. "S311", # Standard pseudo-random generators are not suitable for cryptographic purposes diff --git a/tests/helpers/utils.py b/tests/helpers/utils.py index 9de4ee71..515d9609 100644 --- a/tests/helpers/utils.py +++ b/tests/helpers/utils.py @@ -15,7 +15,7 @@ def change_directory(new_directory: str) -> Generator[None, None, None]: """Helper function used to change directories in a with block.""" # Save the current working directory - original_directory = os.getcwd() + original_directory = Path.cwd() # Change to the new directory try: @@ -30,7 +30,7 @@ def change_directory(new_directory: str) -> Generator[None, None, None]: @contextmanager def temp_repo_and_cd(source_dir: Path) -> Generator[Path, None, None]: temp_dir = tempfile.mkdtemp() - original_directory = os.getcwd() + original_directory = Path.cwd() try: shutil.copytree(source_dir, temp_dir, dirs_exist_ok=True) diff --git a/tests/integration/test_infrahubctl.py b/tests/integration/test_infrahubctl.py index 20106050..a4fa197b 100644 --- a/tests/integration/test_infrahubctl.py +++ b/tests/integration/test_infrahubctl.py @@ -22,7 +22,7 @@ if TYPE_CHECKING: from infrahub_sdk import InfrahubClient -FIXTURE_BASE_DIR = Path(Path(os.path.abspath(__file__)).parent / ".." / "fixtures") +FIXTURE_BASE_DIR = Path(Path(Path(__file__).resolve()).parent / ".." / "fixtures") runner = CliRunner() diff --git a/tests/unit/ctl/test_render_app.py b/tests/unit/ctl/test_render_app.py index 88e71f86..4ccde6f9 100644 --- a/tests/unit/ctl/test_render_app.py +++ b/tests/unit/ctl/test_render_app.py @@ -1,5 +1,4 @@ import json -import os from dataclasses import dataclass from pathlib import Path @@ -14,7 +13,7 @@ runner = CliRunner() -FIXTURE_BASE_DIR = Path(Path(os.path.abspath(__file__)).parent / ".." / ".." / "fixtures" / "repos") +FIXTURE_BASE_DIR = Path(Path(Path(__file__).resolve()).parent / ".." / ".." / "fixtures" / "repos") @dataclass diff --git a/tests/unit/ctl/test_transform_app.py b/tests/unit/ctl/test_transform_app.py index 9ae4585d..5b7cb4f1 100644 --- a/tests/unit/ctl/test_transform_app.py +++ b/tests/unit/ctl/test_transform_app.py @@ -1,7 +1,6 @@ """Integration tests for infrahubctl commands.""" import json -import os import shutil import tempfile from collections.abc import Generator @@ -20,7 +19,7 @@ FIXTURE_BASE_DIR = Path( - Path(os.path.abspath(__file__)).parent / ".." / ".." / "fixtures" / "integration" / "test_infrahubctl" + Path(Path(__file__).resolve()).parent / ".." / ".." / "fixtures" / "integration" / "test_infrahubctl" )