diff --git a/nitpick/config.py b/nitpick/config.py index 5fce8d83..902313c7 100644 --- a/nitpick/config.py +++ b/nitpick/config.py @@ -17,7 +17,7 @@ from nitpick.files.pyproject_toml import PyProjectTomlFile from nitpick.files.setup_cfg import SetupCfgFile from nitpick.formats import Toml -from nitpick.generic import climb_directory_tree, rmdir_if_empty, search_dict, version_to_tuple +from nitpick.generic import climb_directory_tree, search_dict, version_to_tuple from nitpick.mixin import NitpickMixin from nitpick.style import Style from nitpick.typedefs import JsonDict, PathOrStr, StrOrList, YieldFlake8Error @@ -105,7 +105,6 @@ def clear_cache_dir(self) -> None: cache_root = self.root_dir / CACHE_DIR_NAME # type: Path self.cache_dir = cache_root / PROJECT_NAME rmtree(str(self.cache_dir), ignore_errors=True) - rmdir_if_empty(cache_root) def merge_styles(self) -> YieldFlake8Error: """Merge one or multiple style files.""" diff --git a/nitpick/generic.py b/nitpick/generic.py index 3d6739ce..f0169b43 100644 --- a/nitpick/generic.py +++ b/nitpick/generic.py @@ -130,22 +130,6 @@ def find_object_by_key(list_: List[dict], search_key: str, search_value: Any) -> return {} -def rmdir_if_empty(path_or_str: PathOrStr): - """Remove the directory if empty.""" - path = Path(path_or_str) - if not path.exists(): - return - - try: - has_items = next(path.iterdir(), False) - if has_items is False: - # If the directory has no more files/directories inside, try to remove the parent. - path.rmdir() - except (FileNotFoundError, OSError): - # If any removal attempt fails, just ignore it. Some other flake8 thread might have deleted the directory. - pass - - def search_dict(jmespath_expression: Union[ParsedResult, str], data: MutableMapping[str, Any], default: Any) -> Any: """Search a dictionary using a JMESPath expression, and returning a default value.