Skip to content

Commit

Permalink
fix: don't try to remove the .cache root dir, it leads to errors some…
Browse files Browse the repository at this point in the history
…times
  • Loading branch information
andreoliwa committed Jun 19, 2019
1 parent ace88b2 commit 856d8e7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 18 deletions.
3 changes: 1 addition & 2 deletions nitpick/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
16 changes: 0 additions & 16 deletions nitpick/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 856d8e7

Please sign in to comment.