summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYaroslav Halchenko <debian@onerussian.com>2017-11-27 20:35:19 -0500
committerYaroslav Halchenko <debian@onerussian.com>2017-11-27 20:35:19 -0500
commit6ee08fce6ec508fdc6e577e3e507b342d048fa16 (patch)
tree47b8bac37afca3878d4535d3c13db38e55242628
parent0a96030d82fa379d24b952a58eed395143950c7b (diff)
downloadgitpython-6ee08fce6ec508fdc6e577e3e507b342d048fa16.tar.gz
RF: primarily flake8 lints + minor RF to reduce duplication in PATHEXT
I did keep some "bare" except with catch all Exception: , while tried to disable flake8 complaints where clearly all exceptions are to be catched
-rw-r--r--git/compat.py2
-rw-r--r--git/diff.py14
-rw-r--r--git/exc.py2
-rw-r--r--git/refs/log.py2
-rw-r--r--git/remote.py8
-rw-r--r--git/repo/base.py2
-rw-r--r--git/test/lib/helper.py6
-rw-r--r--git/test/test_submodule.py2
-rw-r--r--git/test/test_util.py54
-rw-r--r--git/util.py17
10 files changed, 53 insertions, 56 deletions
diff --git a/git/compat.py b/git/compat.py
index b8045857..b63768f3 100644
--- a/git/compat.py
+++ b/git/compat.py
@@ -309,5 +309,5 @@ def register_surrogateescape():
try:
b"100644 \x9f\0aaa".decode(defenc, "surrogateescape")
-except:
+except Exception:
register_surrogateescape()
diff --git a/git/diff.py b/git/diff.py
index 16c782f3..28c10e49 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -313,20 +313,20 @@ class Diff(object):
h %= self.b_blob.path
msg = ''
- l = None # temp line
- ll = 0 # line length
+ line = None # temp line
+ line_length = 0 # line length
for b, n in zip((self.a_blob, self.b_blob), ('lhs', 'rhs')):
if b:
- l = "\n%s: %o | %s" % (n, b.mode, b.hexsha)
+ line = "\n%s: %o | %s" % (n, b.mode, b.hexsha)
else:
- l = "\n%s: None" % n
+ line = "\n%s: None" % n
# END if blob is not None
- ll = max(len(l), ll)
- msg += l
+ line_length = max(len(line), line_length)
+ msg += line
# END for each blob
# add headline
- h += '\n' + '=' * ll
+ h += '\n' + '=' * line_length
if self.deleted_file:
msg += '\nfile deleted in rhs'
diff --git a/git/exc.py b/git/exc.py
index a737110c..5c5aa2b4 100644
--- a/git/exc.py
+++ b/git/exc.py
@@ -48,7 +48,7 @@ class CommandError(UnicodeMixin, GitError):
else:
try:
status = u'exit code(%s)' % int(status)
- except:
+ except ValueError:
s = safe_decode(str(status))
status = u"'%s'" % s if isinstance(status, string_types) else s
diff --git a/git/refs/log.py b/git/refs/log.py
index 623a63db..1c085ef1 100644
--- a/git/refs/log.py
+++ b/git/refs/log.py
@@ -246,7 +246,7 @@ class RefLog(list, Serializable):
try:
self._serialize(fp)
lfd.commit()
- except:
+ except Exception:
# on failure it rolls back automatically, but we make it clear
lfd.rollback()
raise
diff --git a/git/remote.py b/git/remote.py
index 35460f5a..813566a2 100644
--- a/git/remote.py
+++ b/git/remote.py
@@ -542,9 +542,11 @@ class Remote(LazyMixin, Iterable):
if ' Push URL:' in line:
yield line.split(': ')[-1]
except GitCommandError as ex:
- if any([msg in str(ex) for msg in ['correct access rights','cannot run ssh']]):
- # If ssh is not setup to access this repository, see issue 694
- result = Git().execute(['git','config','--get','remote.%s.url' % self.name])
+ if any([msg in str(ex) for msg in ['correct access rights', 'cannot run ssh']]):
+ # If ssh is not setup to access this repository, see issue 694
+ result = Git().execute(
+ ['git', 'config', '--get', 'remote.%s.url' % self.name]
+ )
yield result
else:
raise ex
diff --git a/git/repo/base.py b/git/repo/base.py
index 990def64..2fbae012 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -203,7 +203,7 @@ class Repo(object):
def __del__(self):
try:
self.close()
- except:
+ except Exception:
pass
def close(self):
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index 729c76a4..ff337f29 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -139,7 +139,7 @@ def with_rw_repo(working_tree_ref, bare=False):
try:
try:
return func(self, rw_repo)
- except:
+ except: # noqa E722
log.info("Keeping repo after failure: %s", repo_dir)
repo_dir = None
raise
@@ -227,7 +227,7 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
Same as with_rw_repo, but also provides a writable remote repository from which the
rw_repo has been forked as well as a handle for a git-daemon that may be started to
run the remote_repo.
- The remote repository was cloned as bare repository from the rorepo, whereas
+ The remote repository was cloned as bare repository from the ro repo, whereas
the rw repo has a working tree and was cloned from the remote repository.
remote_repo has two remotes: origin and daemon_origin. One uses a local url,
@@ -296,7 +296,7 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
with cwd(rw_repo.working_dir):
try:
return func(self, rw_repo, rw_daemon_repo)
- except:
+ except: # noqa E722
log.info("Keeping repos after failure: \n rw_repo_dir: %s \n rw_daemon_repo_dir: %s",
rw_repo_dir, rw_daemon_repo_dir)
rw_repo_dir = rw_daemon_repo_dir = None
diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py
index f970dd2c..5c8a2798 100644
--- a/git/test/test_submodule.py
+++ b/git/test/test_submodule.py
@@ -920,4 +920,4 @@ class TestSubmodule(TestBase):
submodule_path = 'D:\\submodule_path'
relative_path = Submodule._to_relative_path(super_repo, submodule_path)
msg = '_to_relative_path should be "submodule_path" but was "%s"' % relative_path
- assert relative_path == 'submodule_path', msg \ No newline at end of file
+ assert relative_path == 'submodule_path', msg
diff --git a/git/test/test_util.py b/git/test/test_util.py
index 525c8609..d30c8376 100644
--- a/git/test/test_util.py
+++ b/git/test/test_util.py
@@ -217,49 +217,49 @@ class TestUtils(TestBase):
@ddt.data(('name', ''), ('name', 'prefix_'))
def test_iterable_list(self, case):
name, prefix = case
- l = IterableList(name, prefix)
+ ilist = IterableList(name, prefix)
name1 = "one"
name2 = "two"
m1 = TestIterableMember(prefix + name1)
m2 = TestIterableMember(prefix + name2)
- l.extend((m1, m2))
+ ilist.extend((m1, m2))
- self.assertEqual(len(l), 2)
+ self.assertEqual(len(ilist), 2)
# contains works with name and identity
- self.assertIn(name1, l)
- self.assertIn(name2, l)
- self.assertIn(m2, l)
- self.assertIn(m2, l)
- self.assertNotIn('invalid', l)
+ self.assertIn(name1, ilist)
+ self.assertIn(name2, ilist)
+ self.assertIn(m2, ilist)
+ self.assertIn(m2, ilist)
+ self.assertNotIn('invalid', ilist)
# with string index
- self.assertIs(l[name1], m1)
- self.assertIs(l[name2], m2)
+ self.assertIs(ilist[name1], m1)
+ self.assertIs(ilist[name2], m2)
# with int index
- self.assertIs(l[0], m1)
- self.assertIs(l[1], m2)
+ self.assertIs(ilist[0], m1)
+ self.assertIs(ilist[1], m2)
# with getattr
- self.assertIs(l.one, m1)
- self.assertIs(l.two, m2)
+ self.assertIs(ilist.one, m1)
+ self.assertIs(ilist.two, m2)
# test exceptions
- self.failUnlessRaises(AttributeError, getattr, l, 'something')
- self.failUnlessRaises(IndexError, l.__getitem__, 'something')
+ self.failUnlessRaises(AttributeError, getattr, ilist, 'something')
+ self.failUnlessRaises(IndexError, ilist.__getitem__, 'something')
# delete by name and index
- self.failUnlessRaises(IndexError, l.__delitem__, 'something')
- del(l[name2])
- self.assertEqual(len(l), 1)
- self.assertNotIn(name2, l)
- self.assertIn(name1, l)
- del(l[0])
- self.assertNotIn(name1, l)
- self.assertEqual(len(l), 0)
-
- self.failUnlessRaises(IndexError, l.__delitem__, 0)
- self.failUnlessRaises(IndexError, l.__delitem__, 'something')
+ self.failUnlessRaises(IndexError, ilist.__delitem__, 'something')
+ del(ilist[name2])
+ self.assertEqual(len(ilist), 1)
+ self.assertNotIn(name2, ilist)
+ self.assertIn(name1, ilist)
+ del(ilist[0])
+ self.assertNotIn(name1, ilist)
+ self.assertEqual(len(ilist), 0)
+
+ self.failUnlessRaises(IndexError, ilist.__delitem__, 0)
+ self.failUnlessRaises(IndexError, ilist.__delitem__, 'something')
diff --git a/git/util.py b/git/util.py
index 5baeee91..18c28fd1 100644
--- a/git/util.py
+++ b/git/util.py
@@ -188,20 +188,15 @@ def assure_directory_exists(path, is_file=False):
def _get_exe_extensions():
- try:
- winprog_exts = tuple(p.upper() for p in os.environ['PATHEXT'].split(os.pathsep))
- except:
- winprog_exts = ('.BAT', 'COM', '.EXE')
-
- return winprog_exts
+ PATHEXT = os.environ.get('PATHEXT', None)
+ return tuple(p.upper() for p in PATHEXT.split(os.pathsep)) \
+ if PATHEXT \
+ else (('.BAT', 'COM', '.EXE') if is_win else ())
def py_where(program, path=None):
# From: http://stackoverflow.com/a/377028/548792
- try:
- winprog_exts = tuple(p.upper() for p in os.environ['PATHEXT'].split(os.pathsep))
- except:
- winprog_exts = is_win and ('.BAT', 'COM', '.EXE') or ()
+ winprog_exts = _get_exe_extensions()
def is_exec(fpath):
return osp.isfile(fpath) and os.access(fpath, os.X_OK) and (
@@ -347,7 +342,7 @@ def expand_path(p, expand_vars=True):
if expand_vars:
p = osp.expandvars(p)
return osp.normpath(osp.abspath(p))
- except:
+ except Exception:
return None
#} END utilities