8000 Merge pull request #541 from andy-maier/py26_fixes · ankostis/GitPython@2f207e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f207e0

Browse files
authored
Merge pull request gitpython-developers#541 from andy-maier/py26_fixes
Fixes to support Python 2.6 again.
2 parents a8437c0 + f3d5df2 commit 2f207e0

File tree

15 files changed

+81
-27
lines changed
  • 15 files changed

    +81
    -27
    lines changed

    .appveyor.yml

    Lines changed: 3 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -7,6 +7,9 @@ environment:
    77
    matrix:
    88
    ## MINGW
    99
    #
    10+
    - PYTHON: "C:\\Python26"
    11+
    PYTHON_VERSION: "2.6"
    12+
    GIT_PATH: "%GIT_DAEMON_PATH%"
    1013
    - PYTHON: "C:\\Python27"
    1114
    PYTHON_VERSION: "2.7"
    1215
    GIT_PATH: "%GIT_DAEMON_PATH%"

    .travis.yml

    Lines changed: 5 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,10 +1,14 @@
    11
    language: python
    22
    python:
    3+
    - "2.6"
    34
    - "2.7"
    45
    - "3.3"
    56
    - "3.4"
    67
    - "3.5"
    78
    # - "pypy" - won't work as smmap doesn't work (see gitdb/.travis.yml for details)
    9+
    #matrix:
    10+
    # allow_failures:
    11+
    # - python: "2.6"
    812
    git:
    913
    # a higher depth is needed for most of the tests - must be high enough to not actually be shallow
    1014
    # as we clone our own repository in the process
    @@ -15,6 +19,7 @@ install:
    1519
    - git fetch --tags
    1620
    - pip install -r test-requirements.txt
    1721
    - pip install codecov sphinx
    22+
    - if [ "$TRAVIS_PYTHON_VERSION" == '2.6' ]; then pip install unittest2; fi
    1823

    1924
    # generate some reflog as git-python tests need it (in master)
    2025
    - ./init-tests-after-clone.sh

    git/cmd.py

    Lines changed: 9 additions & 5 deletions
    Original file line numberDiff line numberDiff line change
    @@ -140,9 +140,9 @@ def dict_to_slots_and__excluded_are_none(self, d, excluded=()):
    140140
    CREATE_NO_WINDOW = 0x08000000
    141141

    142142
    ## CREATE_NEW_PROCESS_GROUP is needed to allow killing it afterwards,
    143-
    # seehttps://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal
    143+
    # see https://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal
    144144
    PROC_CREATIONFLAGS = (CREATE_NO_WINDOW | subprocess.CREATE_NEW_PROCESS_GROUP
    145-
    if is_win
    145+
    if is_win and sys.version_info >= (2, 7)
    146146
    else 0)
    147147

    148148

    @@ -246,7 +246,7 @@ def __del__(self):
    246246
    return
    247247

    248248
    # can be that nothing really exists anymore ...
    249-
    if os is None or os.kill is None:
    249+
    if os is None or getattr(os, 'kill', None) is None:
    250250
    return
    251251

    252252
    # try to kill it
    @@ -832,8 +832,12 @@ def _call_process(self, method, *args, **kwargs):
    832832
    :return: Same as ``execute``"""
    833833
    # Handle optional arguments prior to calling transform_kwargs
    834834
    # otherwise these'll end up in args, which is bad.
    835-
    _kwargs = {k: v for k, v in kwargs.items() if k in execute_kwargs}
    836-
    kwargs = {k: v for k, v in kwargs.items() if k not in execute_kwargs}
    835+
    _kwargs = dict()
    836+
    for kwarg in execute_kwargs:
    837+
    try:
    838+
    _kwargs[kwarg] = kwargs.pop(kwarg)
    839+
    except KeyError:
    840+
    pass
    837841

    838842
    insert_after_this_arg = kwargs.pop('insert_kwargs_after', None)
    839843

    git/objects/submodule/base.py

    Lines changed: 4 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -3,7 +3,10 @@
    33
    import logging
    44
    import os
    55
    import stat
    6-
    from unittest.case import SkipTest
    6+
    try:
    7+
    from unittest import SkipTest
    8+
    except ImportError:
    9+
    from unittest2 import SkipTest
    710
    import uuid
    811

    912
    import git

    git/test/lib/helper.py

    Lines changed: 12 additions & 5 deletions
    Original file line numberDiff line numberDiff line change
    @@ -7,20 +7,24 @@
    77

    88
    import contextlib
    99
    from functools import wraps
    10+
    import sys
    1011
    import io
    1112
    import logging
    1213
    import os
    1314
    import tempfile
    1415
    import textwrap
    1516
    import time
    16-
    from unittest import TestCase
    17-
    import unittest
    1817

    19-
    from git.compat import string_types, is_win, PY3
    18+
    from git.compat import string_types, is_win
    2019
    from git.util import rmtree, cwd
    2120

    2221
    import os.path as osp
    22+
    if sys.version_info[0:2] == (2, 6):
    23+
    import unittest2 as unittest
    24+
    else:
    25+
    import unittest
    2326

    27+
    TestCase = unittest.TestCase
    2428

    2529
    ospd = osp.dirname
    2630

    @@ -335,8 +339,11 @@ class TestBase(TestCase):
    335339
    of the project history ( to assure tests don't fail for others ).
    336340
    """
    337341

    338-
    if not PY3:
    339-
    assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
    342+
    # On py26, unittest2 has assertRaisesRegex
    343+
    # On py3, unittest has assertRaisesRegex
    344+
    # On py27, we use unittest, which names it differently:
    345+
    if sys.version_info[0:2] == (2, 7):
    346+
    assertRaisesRegex = TestCase.assertRaisesRegexp
    340347

    341348
    def _small_repo_url(self):
    342349
    """:return" a path to a small, clonable repository"""

    git/test/test_base.py

    Lines changed: 4 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -7,7 +7,10 @@
    77
    import os
    88
    import sys
    99
    import tempfile
    10-
    from unittest import skipIf
    10+
    try:
    11+
    from unittest import SkipTest, skipIf
    12+
    except ImportError:
    13+
    from unittest2 import SkipTest, skipIf
    1114

    1215
    from git import (
    1316
    Blob,
    @@ -131,7 +134,6 @@ def test_add_unicode(self, rw_repo):
    131134
    try:
    132135
    file_path.encode(sys.getfilesystemencoding())
    133136
    except UnicodeEncodeError:
    134-
    from unittest import SkipTest
    135137
    raise SkipTest("Environment doesn't support unicode filenames")
    136138

    137139
    with open(file_path, "wb") as fp:

    git/test/test_fun.py

    Lines changed: 4 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -1,6 +1,9 @@
    11
    from io import BytesIO
    22
    from stat import S_IFDIR, S_IFREG, S_IFLNK
    3-
    from unittest.case import skipIf
    3+
    try:
    4+
    from unittest import skipIf
    5+
    except ImportError:
    6+
    from unittest2 import skipIf
    47

    58
    from git.compat import PY3
    69
    from git.index import IndexFile

    git/test/test_index.py

    Lines changed: 7 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -13,7 +13,10 @@
    1313
    )
    1414
    import sys
    1515
    import tempfile
    16-
    from unittest.case import skipIf
    16+
    try:
    17+
    from unittest import skipIf
    18+
    except ImportError:
    19+
    from unittest2 import skipIf
    1720

    1821
    from git import (
    1922
    IndexFile,
    @@ -149,8 +152,9 @@ def add_bad_blob():
    149152
    except Exception as ex:
    150153
    msg_py3 = "required argument is not an integer"
    151154
    msg_py2 = "cannot convert argument to integer"
    152-
    ## msg_py26 ="unsupported operand type(s) for &: 'str' and 'long'"
    153-
    assert msg_py2 in str(ex) or msg_py3 in str(ex), str(ex)
    155+
    msg_py26 = "unsupported operand type(s) for &: 'str' and 'long'"
    156+
    assert msg_py2 in str(ex) or msg_py3 in str(ex) or \
    157+
    msg_py26 in str(ex), str(ex)
    154158

    155159
    ## 2nd time should not fail due to stray lock file
    156160
    try:

    git/test/test_remote.py

    Lines changed: 4 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -6,7 +6,10 @@
    66

    77
    import random
    88
    import tempfile
    9-
    from unittest.case import skipIf
    9+
    try:
    10+
    from unittest import skipIf
    11+
    except ImportError:
    12+
    from unittest2 import skipIf
    1013

    1114
    from git import (
    1215
    RemoteProgress,

    git/test/test_repo.py

    Lines changed: 4 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -11,7 +11,10 @@
    1111
    import pickle
    1212
    import sys
    1313
    import tempfile
    14-
    from unittest.case import skipIf
    14+
    try:
    15+
    from unittest import skipIf, SkipTest
    16+
    except ImportError:
    17+
    from unittest2 import skipIf, SkipTest
    1518

    1619
    from git import (
    1720
    InvalidGitRepositoryError,
    @@ -53,7 +56,6 @@
    5356
    from git.util import HIDE_WINDOWS_KNOWN_ERRORS, cygpath
    5457
    from git.test.lib import with_rw_directory
    5558
    from git.util import join_path_native, rmtree, rmfile, bin_to_hex
    56-
    from unittest import SkipTest
    5759

    5860
    import functools as fnt
    5961
    import os.path as osp

    git/test/test_submodule.py

    Lines changed: 4 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -3,7 +3,10 @@
    33
    # the BSD License: http://www.opensource.org/licenses/bsd-license.php
    44
    import os
    55
    import sys
    6-
    from unittest.case import skipIf
    6+
    try:
    7+
    from unittest import skipIf
    8+
    except ImportError:
    9+
    from unittest2 import skipIf
    710

    811
    import git
    912
    from git.cmd import Git

    git/test/test_tree.py

    Lines changed: 4 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -6,7 +6,10 @@
    66

    77
    from io import BytesIO
    88
    import sys
    9-
    from unittest.case import skipIf
    9+
    try:
    10+
    from unittest import skipIf
    11+
    except ImportError:
    12+
    from unittest2 import skipIf
    1013

    1114
    from git import (
    1215
    Tree,

    git/test/test_util.py

    Lines changed: 5 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -6,7 +6,11 @@
    66

    77
    import tempfile
    88
    import time
    9-
    from unittest.case import skipIf
    9+
    try:
    10+
    from unittest import skipIf
    11+
    except ImportError:
    12+
    from unittest2 import skipIf
    13+
    1014

    1115
    import ddt
    1216

    git/util.py

    Lines changed: 11 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -9,11 +9,15 @@
    99
    import logging
    1010
    import os
    1111
    import platform
    12+
    import subprocess
    1213
    import re
    1314
    import shutil
    1415
    import stat
    1516
    import time
    16-
    from unittest.case import SkipTest
    17+
    try:
    18+
    from unittest import SkipTest
    19+
    except ImportError:
    20+
    from unittest2 import SkipTest
    1721

    1822
    from gitdb.util import (# NOQA @IgnorePep8
    1923
    make_sha,
    @@ -301,7 +305,7 @@ def is_cygwin_git(git_executable):
    301305
    if not is_win:
    302306
    return False
    303307

    304-
    from subprocess import check_output
    308+
    #from subprocess import check_output
    305309

    306310
    is_cygwin = _is_cygwin_cache.get(git_executable)
    307311
    if is_cygwin is None:
    @@ -314,8 +318,11 @@ def is_cygwin_git(git_executable):
    314318

    315319
    ## Just a name given, not a real path.
    316320
    uname_cmd = osp.join(git_dir, 'uname')
    317-
    uname = check_output(uname_cmd, universal_newlines=True)
    318-
    is_cygwin = 'CYGWIN' in uname
    321+
    process = subprocess.Popen([uname_cmd], stdout=subprocess.PIPE,
    322+
    universal_newlines=True)
    323+
    uname_out, _ = process.communicate()
    324+
    #retcode = process.poll()
    325+
    is_cygwin = 'CYGWIN' in uname_out
    319326
    except Exception as ex:
    320327
    log.debug('Failed checking if running in CYGWIN due to: %r', ex)
    321328
    _is_cygwin_cache[git_executable] = is_cygwin

    requirements.txt

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,2 +1,3 @@
    11
    gitdb>=0.6.4
    22
    ddt>=1.1.1
    3+
    unittest2; python_version < '2.7'

    0 commit comments

    Comments
     (0)
    0