From f6aa8d116eb33293c0a9d6d600eb7c32832758b9 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 4 Jan 2015 19:14:33 +0100 Subject: initial set of adjustments to make (most) imports work. More to come, especially when it's about strings --- git/compat.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 git/compat.py (limited to 'git/compat.py') diff --git a/git/compat.py b/git/compat.py new file mode 100644 index 00000000..52fc599c --- /dev/null +++ b/git/compat.py @@ -0,0 +1,19 @@ +#-*-coding:utf-8-*- +# config.py +# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors +# +# This module is part of GitPython and is released under +# the BSD License: http://www.opensource.org/licenses/bsd-license.php +"""utilities to help provide compatibility with python 3""" + +from gitdb.utils.compat import ( # noqa + PY3, + xrange, + MAXSIZE, + izip, +) + +from gitdb.utils.encoding import ( # noqa + string_types, + text_type +) -- cgit v1.2.1 From ae2ff0f9d704dc776a1934f72a339da206a9fff4 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 4 Jan 2015 19:50:28 +0100 Subject: Dum brute force conversion of all types. However, StringIO really is ByteIO in most cases, and py2.7 should run but doesn't. This should be made work first. --- git/compat.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'git/compat.py') diff --git a/git/compat.py b/git/compat.py index 52fc599c..611005a1 100644 --- a/git/compat.py +++ b/git/compat.py @@ -5,15 +5,22 @@ # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php """utilities to help provide compatibility with python 3""" +# flake8: noqa -from gitdb.utils.compat import ( # noqa +from gitdb.utils.compat import ( PY3, xrange, MAXSIZE, izip, ) -from gitdb.utils.encoding import ( # noqa +from gitdb.utils.encoding import ( string_types, text_type ) + +if PY3: + import io + FileType = io.IOBase +else: + FileType = file -- cgit v1.2.1 From bc8c91200a7fb2140aadd283c66b5ab82f9ad61e Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 5 Jan 2015 10:09:51 +0100 Subject: Fixed io types to make tests work on PY2 once again. Now it's about going through PY3 issues --- 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 611005a1..a95c5667 100644 --- a/git/compat.py +++ b/git/compat.py @@ -16,7 +16,8 @@ from gitdb.utils.compat import ( from gitdb.utils.encoding import ( string_types, - text_type + text_type, + force_bytes ) if PY3: -- cgit v1.2.1 From 04357d0d46fee938a618b64daed1716606e05ca5 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 5 Jan 2015 15:53:46 +0100 Subject: Intermediate commit: test_config and test_actor works Kind of tackling the tasks step by step, picking low-hanging fruit first, or the ones that everyone depends on --- git/compat.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'git/compat.py') diff --git a/git/compat.py b/git/compat.py index a95c5667..4a892ad2 100644 --- a/git/compat.py +++ b/git/compat.py @@ -7,6 +7,8 @@ """utilities to help provide compatibility with python 3""" # flake8: noqa +import sys + from gitdb.utils.compat import ( PY3, xrange, @@ -17,11 +19,39 @@ from gitdb.utils.compat import ( from gitdb.utils.encoding import ( string_types, text_type, - force_bytes + force_bytes, + force_text ) +defenc = sys.getdefaultencoding() if PY3: import io FileType = io.IOBase else: FileType = file + # usually, this is just ascii, which might not enough for our encoding needs + # Unless it's set specifically, we override it to be utf-8 + if defenc == 'ascii': + defenc = 'utf-8' + + +def with_metaclass(meta, *bases): + """copied from https://github.com/Byron/bcore/blob/master/src/python/butility/future.py#L15""" + class metaclass(meta): + __call__ = type.__call__ + __init__ = type.__init__ + + def __new__(cls, name, nbases, d): + if nbases is None: + return type.__new__(cls, name, (), d) + # There may be clients who rely on this attribute to be set to a reasonable value, which is why + # 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 + -- cgit v1.2.1 From 8a308613467a1510f8dac514624abae4e10c0779 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 5 Jan 2015 16:44:54 +0100 Subject: Fixes test_blob and improved commit writing/reading --- git/compat.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'git/compat.py') diff --git a/git/compat.py b/git/compat.py index 4a892ad2..f11d1423 100644 --- a/git/compat.py +++ b/git/compat.py @@ -27,12 +27,15 @@ defenc = sys.getdefaultencoding() if PY3: import io FileType = io.IOBase + def byte_ord(b): + return b else: FileType = file # usually, this is just ascii, which might not enough for our encoding needs # Unless it's set specifically, we override it to be utf-8 if defenc == 'ascii': defenc = 'utf-8' + byte_ord = ord def with_metaclass(meta, *bases): @@ -54,4 +57,3 @@ def with_metaclass(meta, *bases): # end metaclass return metaclass(meta.__name__ + 'Helper', None, {}) # end handle py2 - -- cgit v1.2.1 From 4a67e4e49c4e7b82e416067df69c72656213e886 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 5 Jan 2015 18:21:49 +0100 Subject: test_fun works --- git/compat.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'git/compat.py') diff --git a/git/compat.py b/git/compat.py index f11d1423..b9205418 100644 --- a/git/compat.py +++ b/git/compat.py @@ -29,6 +29,8 @@ if PY3: FileType = io.IOBase def byte_ord(b): return b + def bchr(n): + return bytes([n]) else: FileType = file # usually, this is just ascii, which might not enough for our encoding needs @@ -36,6 +38,7 @@ else: if defenc == 'ascii': defenc = 'utf-8' byte_ord = ord + bchr = chr def with_metaclass(meta, *bases): -- cgit v1.2.1 From 45c1c99a22e95d730d3096c339d97181d314d6ca Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 6 Jan 2015 10:43:25 +0100 Subject: test_index works --- git/compat.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'git/compat.py') diff --git a/git/compat.py b/git/compat.py index b9205418..5c330e5b 100644 --- a/git/compat.py +++ b/git/compat.py @@ -31,6 +31,8 @@ if PY3: return b def bchr(n): return bytes([n]) + def mviter(d): + return d.values() else: FileType = file # usually, this is just ascii, which might not enough for our encoding needs @@ -39,6 +41,8 @@ else: defenc = 'utf-8' byte_ord = ord bchr = chr + def mviter(d): + return d.itervalues() def with_metaclass(meta, *bases): -- cgit v1.2.1