summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostis Anagnostopoulos <ankostis@gmail.com>2016-10-02 22:39:27 +0200
committerGitHub <noreply@github.com>2016-10-02 22:39:27 +0200
commitfd8537b23ce85be6f9dacb7806e791b7f902a206 (patch)
treeec46b9f3844cc71c9e47546bf991640e0226c33d
parentdf5c1cb715664fd7a98160844572cc473cb6b87c (diff)
parent51f4a1407ef12405e16f643f5f9d2002b4b52ab9 (diff)
downloadgitpython-fd8537b23ce85be6f9dacb7806e791b7f902a206.tar.gz
Merge pull request #523 from yarikoptic/enh-wraps
RF: use @functools.wraps within decorators instead of manual __name__ reassignment
-rw-r--r--git/config.py4
-rw-r--r--git/index/util.py11
-rw-r--r--git/test/lib/helper.py9
-rw-r--r--git/util.py4
4 files changed, 19 insertions, 9 deletions
diff --git a/git/config.py b/git/config.py
index ad6192ff..b342410c 100644
--- a/git/config.py
+++ b/git/config.py
@@ -17,6 +17,8 @@ import logging
import abc
import os
+from functools import wraps
+
from git.odict import OrderedDict
from git.util import LockFile
from git.compat import (
@@ -67,11 +69,11 @@ class MetaParserBuilder(abc.ABCMeta):
def needs_values(func):
"""Returns method assuring we read values (on demand) before we try to access them"""
+ @wraps(func)
def assure_data_present(self, *args, **kwargs):
self.read()
return func(self, *args, **kwargs)
# END wrapper method
- assure_data_present.__name__ = func.__name__
return assure_data_present
diff --git a/git/index/util.py b/git/index/util.py
index 0340500c..ce798851 100644
--- a/git/index/util.py
+++ b/git/index/util.py
@@ -2,6 +2,9 @@
import struct
import tempfile
import os
+
+from functools import wraps
+
from git.compat import is_win
__all__ = ('TemporaryFileSwap', 'post_clear_cache', 'default_index', 'git_working_dir')
@@ -48,13 +51,13 @@ def post_clear_cache(func):
natively which in fact is possible, but probably not feasible performance wise.
"""
+ @wraps(func)
def post_clear_cache_if_not_raised(self, *args, **kwargs):
rval = func(self, *args, **kwargs)
self._delete_entries_cache()
return rval
-
# END wrapper method
- post_clear_cache_if_not_raised.__name__ = func.__name__
+
return post_clear_cache_if_not_raised
@@ -63,6 +66,7 @@ def default_index(func):
repository index. This is as we rely on git commands that operate
on that index only. """
+ @wraps(func)
def check_default_index(self, *args, **kwargs):
if self._file_path != self._index_path():
raise AssertionError(
@@ -70,7 +74,6 @@ def default_index(func):
return func(self, *args, **kwargs)
# END wrpaper method
- check_default_index.__name__ = func.__name__
return check_default_index
@@ -78,6 +81,7 @@ def git_working_dir(func):
"""Decorator which changes the current working dir to the one of the git
repository in order to assure relative paths are handled correctly"""
+ @wraps(func)
def set_git_working_dir(self, *args, **kwargs):
cur_wd = os.getcwd()
os.chdir(self.repo.working_tree_dir)
@@ -88,7 +92,6 @@ def git_working_dir(func):
# END handle working dir
# END wrapper
- set_git_working_dir.__name__ = func.__name__
return set_git_working_dir
#} END decorators
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index a85ac2fd..e55a23df 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -12,6 +12,8 @@ import tempfile
import io
import logging
+from functools import wraps
+
from git import Repo, Remote, GitCommandError, Git
from git.util import rmtree
from git.compat import string_types, is_win
@@ -86,6 +88,7 @@ def with_rw_directory(func):
"""Create a temporary directory which can be written to, remove it if the
test succeeds, but leave it otherwise to aid additional debugging"""
+ @wraps(func)
def wrapper(self):
path = tempfile.mktemp(prefix=func.__name__)
os.mkdir(path)
@@ -122,6 +125,7 @@ def with_rw_repo(working_tree_ref, bare=False):
assert isinstance(working_tree_ref, string_types), "Decorator requires ref name for working tree checkout"
def argument_passer(func):
+ @wraps(func)
def repo_creator(self):
prefix = 'non_'
if bare:
@@ -155,7 +159,6 @@ def with_rw_repo(working_tree_ref, bare=False):
# END rm test repo if possible
# END cleanup
# END rw repo creator
- repo_creator.__name__ = func.__name__
return repo_creator
# END argument passer
return argument_passer
@@ -211,6 +214,7 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
def argument_passer(func):
+ @wraps(func)
def remote_repo_creator(self):
remote_repo_dir = _mktemp("remote_repo_%s" % func.__name__)
repo_dir = _mktemp("remote_clone_non_bare_repo")
@@ -319,10 +323,9 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
gd.proc.wait()
# END cleanup
# END bare repo creator
- remote_repo_creator.__name__ = func.__name__
return remote_repo_creator
# END remote repo creator
- # END argument parsser
+ # END argument parser
return argument_passer
diff --git a/git/util.py b/git/util.py
index 814cd7f4..9640a74f 100644
--- a/git/util.py
+++ b/git/util.py
@@ -14,6 +14,8 @@ import shutil
import stat
import time
+from functools import wraps
+
from git.compat import is_win
from gitdb.util import ( # NOQA
make_sha,
@@ -50,13 +52,13 @@ def unbare_repo(func):
"""Methods with this decorator raise InvalidGitRepositoryError if they
encounter a bare repository"""
+ @wraps(func)
def wrapper(self, *args, **kwargs):
if self.repo.bare:
raise InvalidGitRepositoryError("Method '%s' cannot operate on bare repositories" % func.__name__)
# END bare method
return func(self, *args, **kwargs)
# END wrapper
- wrapper.__name__ = func.__name__
return wrapper