From f495e94028bfddc264727ffc464cd694ddd05ab8 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Mon, 26 Sep 2016 20:41:41 +0200 Subject: src, #519: collect all is_() calls --- git/compat.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'git/compat.py') diff --git a/git/compat.py b/git/compat.py index b3572474..ff382ce8 100644 --- a/git/compat.py +++ b/git/compat.py @@ -7,6 +7,7 @@ """utilities to help provide compatibility with python 3""" # flake8: noqa +import os import sys from gitdb.utils.compat import ( @@ -79,3 +80,16 @@ def with_metaclass(meta, *bases): # end metaclass return metaclass(meta.__name__ + 'Helper', None, {}) # end handle py2 + + +def is_win(): + return os.name == 'nt' + + +def is_posix(): + return os.name == 'posix' + + +def is_darwin(): + return os.name == 'darwin' + -- cgit v1.2.1 From df2fb548040c8313f4bb98870788604bc973fa18 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Tue, 27 Sep 2016 17:23:53 +0200 Subject: PY2, #519: FIX GitCommandError.tostr() encoding issue + PY3 means "PY3 or later" (TODO: fix also for *gitdb* project). --- git/compat.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'git/compat.py') diff --git a/git/compat.py b/git/compat.py index ff382ce8..8c5036c6 100644 --- a/git/compat.py +++ b/git/compat.py @@ -11,7 +11,6 @@ import os import sys from gitdb.utils.compat import ( - PY3, xrange, MAXSIZE, izip, @@ -24,7 +23,9 @@ from gitdb.utils.encoding import ( force_text ) +PY3 = sys.version_info[0] >= 3 defenc = sys.getdefaultencoding() + if PY3: import io FileType = io.IOBase @@ -74,13 +75,8 @@ def with_metaclass(meta, *bases): # we set the __metaclass__ attribute explicitly if not PY3 and '___metaclass__' not in d: d['__metaclass__'] = meta - # end return meta(name, bases, d) - # end - # end metaclass return metaclass(meta.__name__ + 'Helper', None, {}) - # end handle py2 - def is_win(): return os.name == 'nt' @@ -93,3 +89,16 @@ def is_posix(): def is_darwin(): return os.name == 'darwin' + +## From https://docs.python.org/3.3/howto/pyporting.html +class UnicodeMixin(object): + + """Mixin class to handle defining the proper __str__/__unicode__ + methods in Python 2 or 3.""" + + if sys.version_info[0] >= 3: # Python 3 + def __str__(self): + return self.__unicode__() + else: # Python 2 + def __str__(self): + return self.__unicode__().encode('utf8') -- cgit v1.2.1 From e61439b3018b0b9a8eb43e59d0d7cf32041e2fed Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Tue, 27 Sep 2016 16:05:58 +0200 Subject: src: constify is_() calls + TCs: unittest-asserts for git-tests. --- git/compat.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'git/compat.py') diff --git a/git/compat.py b/git/compat.py index 8c5036c6..dced3a5f 100644 --- a/git/compat.py +++ b/git/compat.py @@ -24,6 +24,9 @@ from gitdb.utils.encoding import ( ) PY3 = sys.version_info[0] >= 3 +is_win = (os.name == 'nt') +is_posix = (os.name == 'posix') +is_darwin = (os.name == 'darwin') defenc = sys.getdefaultencoding() if PY3: @@ -78,17 +81,6 @@ def with_metaclass(meta, *bases): return meta(name, bases, d) return metaclass(meta.__name__ + 'Helper', None, {}) -def is_win(): - return os.name == 'nt' - - -def is_posix(): - return os.name == 'posix' - - -def is_darwin(): - return os.name == 'darwin' - ## From https://docs.python.org/3.3/howto/pyporting.html class UnicodeMixin(object): -- cgit v1.2.1 From 4cede2368aa980e30340f0ed0a1906d65fe1046c Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Tue, 27 Sep 2016 17:09:41 +0200 Subject: Win, #519: Ensure fixtures & bashscript checked-out eol=lf + FIX all Diff TCs. --- git/compat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'git/compat.py') diff --git a/git/compat.py b/git/compat.py index dced3a5f..cbfb5785 100644 --- a/git/compat.py +++ b/git/compat.py @@ -88,9 +88,9 @@ class UnicodeMixin(object): """Mixin class to handle defining the proper __str__/__unicode__ methods in Python 2 or 3.""" - if sys.version_info[0] >= 3: # Python 3 + if PY3: def __str__(self): return self.__unicode__() else: # Python 2 def __str__(self): - return self.__unicode__().encode('utf8') + return self.__unicode__().encode(defenc) -- cgit v1.2.1 From cf2335af23fb693549d6c4e72b65f97afddc5f64 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Wed, 28 Sep 2016 01:47:49 +0200 Subject: Win, hook, #519: Consume Hook Popen-proc out of GIL + HookException thrown on Popen, and were missed on Windows. + No SHELL on Popen?? + Minor fixes: + Try harder to delete trees - no remorses. + Simplify exception reprs. + Unittest-ize test_index assertions. --- git/compat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git/compat.py') diff --git a/git/compat.py b/git/compat.py index cbfb5785..d6be6ede 100644 --- a/git/compat.py +++ b/git/compat.py @@ -62,7 +62,8 @@ def safe_decode(s): return s elif isinstance(s, bytes): return s.decode(defenc, 'replace') - raise TypeError('Expected bytes or text, but got %r' % (s,)) + elif s is not None: + raise TypeError('Expected bytes or text, but got %r' % (s,)) def with_metaclass(meta, *bases): -- cgit v1.2.1 From 395955609dfd711cc4558e2b618450f3514b28c1 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Thu, 29 Sep 2016 01:07:41 +0200 Subject: FIX hook TC on PY3+Win & indeterministic lock timing. + Cannot `index.path` into ENV, it is bytes! + The hook TC never runs on linux! + Unblock removal of odbfile in perf-large streams TC. + Attempt to unblock removal of submodule file by intensive cleaning. more unblock files --- git/compat.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'git/compat.py') diff --git a/git/compat.py b/git/compat.py index d6be6ede..e760575d 100644 --- a/git/compat.py +++ b/git/compat.py @@ -66,6 +66,16 @@ def safe_decode(s): raise TypeError('Expected bytes or text, but got %r' % (s,)) +def safe_encode(s): + """Safely decodes a binary string to unicode""" + if isinstance(s, unicode): + return s.encode(defenc) + elif isinstance(s, bytes): + return s + elif s is not None: + raise TypeError('Expected bytes or text, but got %r' % (s,)) + + def with_metaclass(meta, *bases): """copied from https://github.com/Byron/bcore/blob/master/src/python/butility/future.py#L15""" class metaclass(meta): -- cgit v1.2.1 From b8b025f719b2c3203e194580bbd0785a26c08ebd Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Sat, 1 Oct 2016 16:02:20 +0200 Subject: Win, #519: FIX repo TCs. + FIX TestRepo.test_submodule_update(): + submod: del `.git` file prior overwrite; Windows denied otherwise! + FIX TestRepo.test_untracked_files(): + In the `git add ` case, it failed with unicode args on PY2. Had to encode them with `locale.getpreferredencoding()` AND use SHELL. + cmd: add `shell` into `execute()` kwds, for overriding USE_SHELL per command. + repo: replace blocky `communicate()` in `_clone()` with thread-pumps. + test_repo.py: unittestize (almost all) assertions. + Replace open --> with open for index (base and TC). + test_index.py: Enabled a dormant assertion. --- git/compat.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'git/compat.py') diff --git a/git/compat.py b/git/compat.py index e760575d..441a3761 100644 --- a/git/compat.py +++ b/git/compat.py @@ -7,6 +7,7 @@ """utilities to help provide compatibility with python 3""" # flake8: noqa +import locale import os import sys @@ -15,7 +16,6 @@ from gitdb.utils.compat import ( MAXSIZE, izip, ) - from gitdb.utils.encoding import ( string_types, text_type, @@ -23,6 +23,7 @@ from gitdb.utils.encoding import ( force_text ) + PY3 = sys.version_info[0] >= 3 is_win = (os.name == 'nt') is_posix = (os.name == 'posix') @@ -76,6 +77,16 @@ def safe_encode(s): raise TypeError('Expected bytes or text, but got %r' % (s,)) +def win_encode(s): + """Encode unicodes for process arguments on Windows.""" + if isinstance(s, unicode): + return s.encode(locale.getpreferredencoding(False)) + elif isinstance(s, bytes): + return s + elif s is not None: + raise TypeError('Expected bytes or text, but got %r' % (s,)) + + def with_metaclass(meta, *bases): """copied from https://github.com/Byron/bcore/blob/master/src/python/butility/future.py#L15""" class metaclass(meta): -- cgit v1.2.1