From 987c463ecadea228466976a2fe88596554623f8f Mon Sep 17 00:00:00 2001 From: Patrick Ogenstad Date: Wed, 30 Oct 2024 22:37:12 +0100 Subject: [PATCH] Fix PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` --- backend/infrahub/git/base.py | 8 ++++---- backend/infrahub/git/directory.py | 4 +++- pyproject.toml | 1 - 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/backend/infrahub/git/base.py b/backend/infrahub/git/base.py index 048e4cbd78..435e06c53e 100644 --- a/backend/infrahub/git/base.py +++ b/backend/infrahub/git/base.py @@ -316,10 +316,10 @@ async def create_locally( log.warning(f"Found an existing file at {self.directory_root}, deleted it", repository=self.name) # Initialize directory structure - os.makedirs(self.directory_root) - os.makedirs(self.directory_branches) - os.makedirs(self.directory_commits) - os.makedirs(self.directory_temp) + Path(self.directory_root).mkdir(parents=True) + Path(self.directory_branches).mkdir(parents=True) + Path(self.directory_commits).mkdir(parents=True) + Path(self.directory_temp).mkdir(parents=True) try: repo = Repo.clone_from(self.location, self.directory_default) diff --git a/backend/infrahub/git/directory.py b/backend/infrahub/git/directory.py index 090ea57270..b6b6e5b0e8 100644 --- a/backend/infrahub/git/directory.py +++ b/backend/infrahub/git/directory.py @@ -1,4 +1,5 @@ import os +from pathlib import Path from infrahub import config from infrahub.log import get_logger @@ -25,7 +26,8 @@ def initialize_repositories_directory() -> bool: """ repos_dir = get_repositories_directory() if not os.path.isdir(repos_dir): - os.makedirs(repos_dir) + Path(repos_dir).mkdir(parents=True) + log.debug(f"Initialized the repositories_directory at {repos_dir}") return True diff --git a/pyproject.toml b/pyproject.toml index 26d9affedf..d546d9986e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -520,7 +520,6 @@ ignore = [ "PLW1508", # Invalid type for environment variable default; expected `str` or `None` "PTH100", # `os.path.abspath()` should be replaced by `Path.resolve()` "PTH102", # `os.mkdir()` should be replaced by `Path.mkdir()` - "PTH103", # `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` "PTH107", # `os.remove()` should be replaced by `Path.unlink()` "PTH108", # `os.unlink()` should be replaced by `Path.unlink()` "PTH109", # `os.getcwd()` should be replaced by `Path.cwd()`