diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2022-05-18 08:17:32 +0800 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2022-05-18 08:17:32 +0800 |
commit | 38e9a18b976b2b7e3b3cd0fcd5b037573823d7c2 (patch) | |
tree | 8ac0bc1540650cf3befff11735e1421de372fa92 /git/index/util.py | |
parent | b30720ee4d9762a03eae4fa7cfa4b0190d81784d (diff) | |
parent | 43c00af7e542911cce638cfab49c6a6dc9349e55 (diff) | |
download | gitpython-38e9a18b976b2b7e3b3cd0fcd5b037573823d7c2.tar.gz |
Merge branch 'black-fmt'
Diffstat (limited to 'git/index/util.py')
-rw-r--r-- | git/index/util.py | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/git/index/util.py b/git/index/util.py index 4f8af553..bfc7fadd 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,11 @@ 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 +82,16 @@ 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 +102,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 +110,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 |