summaryrefslogtreecommitdiff
path: root/git/index/util.py
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2022-05-18 07:43:53 +0800
committerSebastian Thiel <sebastian.thiel@icloud.com>2022-05-18 07:43:53 +0800
commit21ec529987d10e0010badd37f8da3274167d436f (patch)
treea3394cfe902ce7edd07c89420c21c13274a2d295 /git/index/util.py
parentb30720ee4d9762a03eae4fa7cfa4b0190d81784d (diff)
downloadgitpython-21ec529987d10e0010badd37f8da3274167d436f.tar.gz
Run everything through 'black'
That way people who use it won't be deterred, while it unifies style everywhere.
Diffstat (limited to 'git/index/util.py')
-rw-r--r--git/index/util.py35
1 files changed, 23 insertions, 12 deletions
diff --git a/git/index/util.py b/git/index/util.py
index 4f8af553..7339b147 100644
--- a/git/index/util.py
+++ b/git/index/util.py
@@ -11,7 +11,7 @@ import os.path as osp
# typing ----------------------------------------------------------------------
-from typing import (Any, Callable, TYPE_CHECKING)
+from typing import Any, Callable, TYPE_CHECKING
from git.types import PathLike, _T
@@ -21,24 +21,26 @@ if TYPE_CHECKING:
# ---------------------------------------------------------------------------------
-__all__ = ('TemporaryFileSwap', 'post_clear_cache', 'default_index', 'git_working_dir')
+__all__ = ("TemporaryFileSwap", "post_clear_cache", "default_index", "git_working_dir")
-#{ Aliases
+# { Aliases
pack = struct.pack
unpack = struct.unpack
-#} END aliases
+# } END aliases
+
class TemporaryFileSwap(object):
"""Utility class moving a file to a temporary location within the same directory
and moving it back on to where on object deletion."""
+
__slots__ = ("file_path", "tmp_file_path")
def __init__(self, file_path: PathLike) -> None:
self.file_path = file_path
- self.tmp_file_path = str(self.file_path) + tempfile.mktemp('', '', '')
+ self.tmp_file_path = str(self.file_path) + tempfile.mktemp("", "", "")
# it may be that the source does not exist
try:
os.rename(self.file_path, self.tmp_file_path)
@@ -53,7 +55,8 @@ class TemporaryFileSwap(object):
# END temp file exists
-#{ Decorators
+# { Decorators
+
def post_clear_cache(func: Callable[..., _T]) -> Callable[..., _T]:
"""Decorator for functions that alter the index using the git command. This would
@@ -66,10 +69,13 @@ def post_clear_cache(func: Callable[..., _T]) -> Callable[..., _T]:
"""
@wraps(func)
- def post_clear_cache_if_not_raised(self: 'IndexFile', *args: Any, **kwargs: Any) -> _T:
+ def post_clear_cache_if_not_raised(
+ self: "IndexFile", *args: Any, **kwargs: Any
+ ) -> _T:
rval = func(self, *args, **kwargs)
self._delete_entries_cache()
return rval
+
# END wrapper method
return post_clear_cache_if_not_raised
@@ -78,14 +84,17 @@ def post_clear_cache(func: Callable[..., _T]) -> Callable[..., _T]:
def default_index(func: Callable[..., _T]) -> Callable[..., _T]:
"""Decorator assuring the wrapped method may only run if we are the default
repository index. This is as we rely on git commands that operate
- on that index only. """
+ on that index only."""
@wraps(func)
- def check_default_index(self: 'IndexFile', *args: Any, **kwargs: Any) -> _T:
+ def check_default_index(self: "IndexFile", *args: Any, **kwargs: Any) -> _T:
if self._file_path != self._index_path():
raise AssertionError(
- "Cannot call %r on indices that do not represent the default git index" % func.__name__)
+ "Cannot call %r on indices that do not represent the default git index"
+ % func.__name__
+ )
return func(self, *args, **kwargs)
+
# END wrapper method
return check_default_index
@@ -96,7 +105,7 @@ def git_working_dir(func: Callable[..., _T]) -> Callable[..., _T]:
repository in order to assure relative paths are handled correctly"""
@wraps(func)
- def set_git_working_dir(self: 'IndexFile', *args: Any, **kwargs: Any) -> _T:
+ def set_git_working_dir(self: "IndexFile", *args: Any, **kwargs: Any) -> _T:
cur_wd = os.getcwd()
os.chdir(str(self.repo.working_tree_dir))
try:
@@ -104,8 +113,10 @@ def git_working_dir(func: Callable[..., _T]) -> Callable[..., _T]:
finally:
os.chdir(cur_wd)
# END handle working dir
+
# END wrapper
return set_git_working_dir
-#} END decorators
+
+# } END decorators