From f3d5df2ce3addd9e9e1863f4f33665a16b415b71 Mon Sep 17 00:00:00 2001 From: Andreas Maier Date: Fri, 21 Oct 2016 11:11:22 +0200 Subject: Fixes to support Python 2.6 again. Details: - Added Python 2.6 again to .travis.yml (it was removed in commit 4486bcb). - Replaced the use of dictionary comprehensions in `git/cmd.py` around line 800 with the code before that change (in commit 25a2ebf). Reason: dict comprehensions were introduced only in Python 2.7. - Changed the import source for `SkipTest` and `skipIf` from `unittest.case` to first trying `unittest` and upon ImportError from `unittest2`. This was done in `git/util.py` and in several testcases. Reason: `SkipTest` and `skipIf` were introduced to unittest only in Python 2.7, and `unittest2` is a backport of `unittest` additions to Python 2.6. - In git/test/lib/helper.py, fixed the definition of `assertRaisesRegex` to work on py26. - For Python 2.6, added the `unittest2` dependency to `requirements.txt` and changed `.travis.yml` to install `unittest2`. Because git/util.py uses SkipTest from unittest/unittest2, the dependency could not be added to `test-requirements.txt`. - Fixed an assertion in `git/test/test_index.py` to also allow a Python 2.6 specific exception message. - In `is_cygwin_git()` in `git/util.py`, replaced `check_output()` with `Popen()`. It was added in Python 2.7. - Enabled Python 2.6 for Windows: - Added Python 2.6 for MINGW in .appveyor.yml. - When defining `PROC_CREATIONFLAGS` in `git/cmd.py`, made use of certain win32 and subprocess flags that were introduced in Python 2.7, dependent on whether we run on Python 2.7 or higher. - In `AutoInterrupt.__del__()` in `git/cmd.py`, allowed for `os` not having `kill()`. `os.kill()` was added for Windows in Python 2.7 (For Linux, it existed in Python 2.6 already). --- git/util.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'git/util.py') diff --git a/git/util.py b/git/util.py index 1e0d3eb4..6e3ddfab 100644 --- a/git/util.py +++ b/git/util.py @@ -11,11 +11,15 @@ import getpass import logging import os import platform +import subprocess import re import shutil import stat import time -from unittest.case import SkipTest +try: + from unittest import SkipTest +except ImportError: + from unittest2 import SkipTest from gitdb.util import (# NOQA @IgnorePep8 make_sha, @@ -303,7 +307,7 @@ def is_cygwin_git(git_executable): if not is_win: return False - from subprocess import check_output + #from subprocess import check_output is_cygwin = _is_cygwin_cache.get(git_executable) if is_cygwin is None: @@ -316,8 +320,11 @@ def is_cygwin_git(git_executable): ## Just a name given, not a real path. uname_cmd = osp.join(git_dir, 'uname') - uname = check_output(uname_cmd, universal_newlines=True) - is_cygwin = 'CYGWIN' in uname + process = subprocess.Popen([uname_cmd], stdout=subprocess.PIPE, + universal_newlines=True) + uname_out, _ = process.communicate() + #retcode = process.poll() + is_cygwin = 'CYGWIN' in uname_out except Exception as ex: log.debug('Failed checking if running in CYGWIN due to: %r', ex) _is_cygwin_cache[git_executable] = is_cygwin -- cgit v1.2.1