Skip to content

Commit 60c8dc2

Browse files
committed
Remove checks for Python 2 and/or 3
1 parent 5549ffe commit 60c8dc2

File tree

13 files changed

+13
-70
lines changed

13 files changed

+13
-70
lines changed

git/cmd.py

-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
string_types,
2525
defenc,
2626
force_bytes,
27-
PY3,
2827
safe_decode,
2928
is_posix,
3029
is_win,
@@ -916,18 +915,12 @@ def transform_kwargs(self, split_single_char_options=True, **kwargs):
916915
@classmethod
917916
def __unpack_args(cls, arg_list):
918917
if not isinstance(arg_list, (list, tuple)):
919-
# This is just required for unicode conversion, as subprocess can't handle it
920-
# However, in any other case, passing strings (usually utf-8 encoded) is totally fine
921-
if not PY3 and isinstance(arg_list, str):
922-
return [arg_list.encode(defenc)]
923918
return [str(arg_list)]
924919

925920
outlist = []
926921
for arg in arg_list:
927922
if isinstance(arg_list, (list, tuple)):
928923
outlist.extend(cls.__unpack_args(arg))
929-
elif not PY3 and isinstance(arg_list, str):
930-
outlist.append(arg_list.encode(defenc))
931924
# END recursion
932925
else:
933926
outlist.append(str(arg))

git/compat.py

-4
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,5 @@ class metaclass(meta):
7070
def __new__(cls, name, nbases, d):
7171
if nbases is None:
7272
return type.__new__(cls, name, (), d)
73-
# There may be clients who rely on this attribute to be set to a reasonable value, which is why
74-
# we set the __metaclass__ attribute explicitly
75-
if not PY3 and '___metaclass__' not in d:
76-
d['__metaclass__'] = meta
7773
return meta(name, bases, d)
7874
return metaclass(meta.__name__ + 'Helper', None, {})

git/config.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
defenc,
2121
force_text,
2222
with_metaclass,
23-
PY3,
2423
is_win,
2524
)
2625
from git.util import LockFile
@@ -372,9 +371,7 @@ def string_decode(v):
372371
v = v[:-1]
373372
# end cut trailing escapes to prevent decode error
374373

375-
if PY3:
376-
return v.encode(defenc).decode('unicode_escape')
377-
return v.decode('string_escape')
374+
return v.encode(defenc).decode('unicode_escape')
378375
# end
379376
# end
380377

git/diff.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
import re
77

88
from git.cmd import handle_process_output
9-
from git.compat import (
10-
defenc,
11-
PY3
12-
)
9+
from git.compat import defenc
1310
from git.util import finalize_process, hex_to_bin
1411

1512
from .objects.blob import Blob
@@ -27,10 +24,7 @@
2724
def _octal_repl(matchobj):
2825
value = matchobj.group(1)
2926
value = int(value, 8)
30-
if PY3:
31-
value = bytes(bytearray((value,)))
32-
else:
33-
value = chr(value)
27+
value = bytes(bytearray((value,)))
3428
return value
3529

3630

@@ -369,8 +363,6 @@ def __str__(self):
369363
# Python2 silliness: have to assure we convert our likely to be unicode object to a string with the
370364
# right encoding. Otherwise it tries to convert it using ascii, which may fail ungracefully
371365
res = h + msg
372-
if not PY3:
373-
res = res.encode(defenc)
374366
# end
375367
return res
376368

git/index/fun.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
from git.cmd import PROC_CREATIONFLAGS, handle_process_output
1717
from git.compat import (
18-
PY3,
1918
defenc,
2019
force_text,
2120
force_bytes,
@@ -73,7 +72,7 @@ def run_commit_hook(name, index, *args):
7372
return
7473

7574
env = os.environ.copy()
76-
env['GIT_INDEX_FILE'] = safe_decode(index.path) if PY3 else safe_encode(index.path)
75+
env['GIT_INDEX_FILE'] = safe_decode(index.path)
7776
env['GIT_EDITOR'] = ':'
7877
try:
7978
cmd = subprocess.Popen([hp] + list(args),

git/objects/tree.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818
tree_to_stream
1919
)
2020

21-
from git.compat import PY3
22-
23-
if PY3:
24-
cmp = lambda a, b: (a > b) - (a < b)
21+
cmp = lambda a, b: (a > b) - (a < b)
2522

2623
__all__ = ("TreeModifier", "Tree")
2724

git/refs/log.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import time
33

44
from git.compat import (
5-
PY3,
65
string_types,
76
defenc
87
)
@@ -35,12 +34,7 @@ class RefLogEntry(tuple):
3534

3635
def __repr__(self):
3736
"""Representation of ourselves in git reflog format"""
38-
res = self.format()
39-
if PY3:
40-
return res
41-
# repr must return a string, which it will auto-encode from unicode using the default encoding.
42-
# This usually fails, so we encode ourselves
43-
return res.encode(defenc)
37+
return self.format()
4438

4539
def format(self):
4640
""":return: a string suitable to be placed in a reflog file"""

git/repo/base.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from git.compat import (
1818
text_type,
1919
defenc,
20-
PY3,
2120
safe_decode,
2221
is_win,
2322
)
@@ -691,11 +690,8 @@ def _get_untracked_files(self, *args, **kwargs):
691690
# Special characters are escaped
692691
if filename[0] == filename[-1] == '"':
693692
filename = filename[1:-1]
694-
if PY3:
695-
# WHATEVER ... it's a mess, but works for me
696-
filename = filename.encode('ascii').decode('unicode_escape').encode('latin1').decode(defenc)
697-
else:
698-
filename = filename.decode('string_escape').decode(defenc)
693+
# WHATEVER ... it's a mess, but works for me
694+
filename = filename.encode('ascii').decode('unicode_escape').encode('latin1').decode(defenc)
699695
untracked_files.append(filename)
700696
finalize_process(proc)
701697
return untracked_files

git/test/test_fun.py

-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ def test_tree_entries_from_data_with_failing_name_decode_py2(self):
287287
r = tree_entries_from_data(b'100644 \x9f\0aaa')
288288
assert r == [('aaa', 33188, u'\udc9f')], r
289289

290-
@skipIf(not PY3, 'odd types returned ... maybe figure it out one day')
291290
def test_tree_entries_from_data_with_failing_name_decode_py3(self):
292291
r = tree_entries_from_data(b'100644 \x9f\0aaa')
293292
assert r == [(b'aaa', 33188, '\udc9f')], r

git/test/test_git.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Repo,
1818
cmd
1919
)
20-
from git.compat import PY3, is_darwin
20+
from git.compat import is_darwin
2121
from git.test.lib import (
2222
TestBase,
2323
patch,
@@ -61,18 +61,12 @@ def test_call_process_calls_execute(self, git):
6161

6262
def test_call_unpack_args_unicode(self):
6363
args = Git._Git__unpack_args(u'Unicode€™')
64-
if PY3:
65-
mangled_value = 'Unicode\u20ac\u2122'
66-
else:
67-
mangled_value = 'Unicode\xe2\x82\xac\xe2\x84\xa2'
64+
mangled_value = 'Unicode\u20ac\u2122'
6865
assert_equal(args, [mangled_value])
6966

7067
def test_call_unpack_args(self):
7168
args = Git._Git__unpack_args(['git', 'log', '--', u'Unicode€™'])
72-
if PY3:
73-
mangled_value = 'Unicode\u20ac\u2122'
74-
else:
75-
mangled_value = 'Unicode\xe2\x82\xac\xe2\x84\xa2'
69+
mangled_value = 'Unicode\u20ac\u2122'
7670
assert_equal(args, ['git', 'log', '--', mangled_value])
7771

7872
@raises(GitCommandError)

git/test/test_index.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
GitCommandError,
2626
CheckoutError,
2727
)
28-
from git.compat import string_types, is_win, PY3
28+
from git.compat import string_types, is_win
2929
from git.exc import (
3030
HookExecutionError,
3131
InvalidGitRepositoryError
@@ -821,10 +821,6 @@ def test_index_bare_add(self, rw_bare_repo):
821821
asserted = True
822822
assert asserted, "Adding using a filename is not correctly asserted."
823823

824-
@skipIf(HIDE_WINDOWS_KNOWN_ERRORS and not PY3, r"""
825-
FIXME: File "C:\projects\gitpython\git\util.py", line 125, in to_native_path_linux
826-
return path.replace('\\', '/')
827-
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)""")
828824
@with_rw_directory
829825
def test_add_utf8P_path(self, rw_dir):
830826
# NOTE: fp is not a Unicode object in python 2 (which is the source of the problem)

git/test/test_repo.py

-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
GitCommandError
3838
)
3939
from git.compat import (
40-
PY3,
4140
is_win,
4241
string_types,
4342
win_encode,
@@ -526,11 +525,6 @@ def test_untracked_files(self, rwrepo):
526525
num_test_untracked += join_path_native(base, utfile) in files
527526
self.assertEqual(len(files), num_test_untracked)
528527

529-
if is_win and not PY3 and is_invoking_git:
530-
## On Windows, shell needed when passing unicode cmd-args.
531-
#
532-
repo_add = fnt.partial(repo_add, shell=True)
533-
untracked_files = [win_encode(f) for f in untracked_files]
534528
repo_add(untracked_files)
535529
self.assertEqual(len(rwrepo.untracked_files), (num_recently_untracked - len(files)))
536530
# end for each run

git/util.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333

3434
from .compat import (
3535
MAXSIZE,
36-
defenc,
37-
PY3
36+
defenc
3837
)
3938
from .exc import InvalidGitRepositoryError
4039

@@ -592,9 +591,6 @@ def _main_actor(cls, env_name, env_email, config_reader=None):
592591
('email', env_email, cls.conf_email, default_email)):
593592
try:
594593
val = os.environ[evar]
595-
if not PY3:
596-
val = val.decode(defenc)
597-
# end assure we don't get 'invalid strings'
598594
setattr(actor, attr, val)
599595
except KeyError:
600596
if config_reader is not None:

0 commit comments

Comments
 (0)