From 0b9016fa83831ecfedf99d5347f9bb8c6cebcf3b Mon Sep 17 00:00:00 2001 From: Ratson Date: Sun, 29 Mar 2015 22:57:29 +0800 Subject: [PATCH 1/2] Add Python 3 support --- .travis.yml | 2 ++ PyGitUp/git_wrapper.py | 8 +++++--- PyGitUp/gitup.py | 16 ++++++++++------ requirements.txt | 5 +++-- setup.py | 5 +++-- tests/__init__.py | 2 +- tests/test_bundler.py | 4 +++- tests/test_not_on_a_git_repo.py | 2 +- 8 files changed, 28 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 20f3826..dfd7b71 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ language: python python: + - "3.4" + - "3.3" - "2.7" - "2.6" # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors diff --git a/PyGitUp/git_wrapper.py b/PyGitUp/git_wrapper.py index 5459c85..7bb586c 100644 --- a/PyGitUp/git_wrapper.py +++ b/PyGitUp/git_wrapper.py @@ -23,6 +23,8 @@ import platform from contextlib import contextmanager +import six + # 3rd party libs from termcolor import colored # Assume, colorama is already initialized from git import GitCommandError, CheckoutError as OrigCheckoutError, Git @@ -84,7 +86,7 @@ def run(self, name, *args, **kwargs): """ Run a git command specified by name and args/kwargs. """ tostdout = kwargs.pop('tostdout', False) - stdout = '' + stdout = six.b('') # Execute command cmd = getattr(self.git, name)(as_process=True, *args, **kwargs) @@ -95,12 +97,12 @@ def run(self, name, *args, **kwargs): # Print to stdout if tostdout: - sys.stdout.write(output) + sys.stdout.write(output.decode('utf-8')) sys.stdout.flush() stdout += output - if output == "": + if output == six.b(""): break # Wait for the process to quit diff --git a/PyGitUp/gitup.py b/PyGitUp/gitup.py index a77a331..216aaa0 100644 --- a/PyGitUp/gitup.py +++ b/PyGitUp/gitup.py @@ -43,12 +43,15 @@ import re import platform import json -import urllib2 import subprocess -from cStringIO import StringIO from contextlib import contextmanager from tempfile import NamedTemporaryFile +import six +from six.moves import cStringIO as StringIO +from six.moves.urllib.error import HTTPError, URLError +from six.moves.urllib.request import urlopen + # 3rd party libs try: #noinspection PyUnresolvedReferences @@ -181,7 +184,8 @@ def __init__(self, testing=False, sparse=False): # change_count: Number of unstaged changes self.change_count = len( - self.git.status(porcelain=True, untracked_files='no').split('\n') + self.git.status(porcelain=True, untracked_files='no').split( + six.b('\n')) ) # Load configuration @@ -253,7 +257,7 @@ def rebase_all_branches(self): continue # Do not do anything - base = self.git.merge_base(branch.name, target.name) + base = self.git.merge_base(branch.name, target.name).decode('utf-8') if base == target.commit.hexsha: print(colored('ahead of upstream', 'cyan')) @@ -386,9 +390,9 @@ def version_info(self): try: # Get version information from the PyPI JSON API - details = json.load(urllib2.urlopen(PYPI_URL)) + details = json.load(urlopen(PYPI_URL)) online_version = details['info']['version'] - except (urllib2.HTTPError, urllib2.URLError, ValueError): + except (HTTPError, URLError, ValueError): recent = True # To not disturb the user with HTTP/parsing errors else: recent = local_version >= pkg.parse_version(online_version) diff --git a/requirements.txt b/requirements.txt index 76d254a..930f43a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ -GitPython==0.3.4 -colorama==0.3.2 +GitPython==0.3.6 +colorama==0.3.3 termcolor==1.1.0 docopt==0.6.2 +six==1.9.0 diff --git a/setup.py b/setup.py index ffee198..b28a7b8 100644 --- a/setup.py +++ b/setup.py @@ -6,8 +6,9 @@ version="1.2.2", packages=find_packages(exclude=["tests"]), scripts=['PyGitUp/gitup.py'], - install_requires=['GitPython==0.3.4', 'colorama==0.3.2', - 'termcolor==1.1.0', 'docopt==0.6.2'], + install_requires=['GitPython==0.3.6', 'colorama==0.3.3', + 'termcolor==1.1.0', 'docopt==0.6.2', + 'six==1.9.0'], # Tests test_suite="nose.collector", diff --git a/tests/__init__.py b/tests/__init__.py index 7674be0..ee00abb 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -27,7 +27,7 @@ def run_test(*args, **kwargs): @contextlib.contextmanager def capture(): import sys - from cStringIO import StringIO + from six.moves import cStringIO as StringIO oldout, olderr = sys.stdout, sys.stderr out = None try: diff --git a/tests/test_bundler.py b/tests/test_bundler.py index 4c68a54..72abdcf 100644 --- a/tests/test_bundler.py +++ b/tests/test_bundler.py @@ -4,6 +4,8 @@ import subprocess from os.path import join +import six + # 3rd party libs from nose.plugins.skip import SkipTest from git import * @@ -55,7 +57,7 @@ def is_installed(prog): return False def get_output(cmd): - return subprocess.check_output(cmd, shell=shell) + return str(subprocess.check_output(cmd, shell=shell)) # Check for ruby and bundler if not (is_installed('ruby') and is_installed('gem') diff --git a/tests/test_not_on_a_git_repo.py b/tests/test_not_on_a_git_repo.py index 9877412..ba0786a 100644 --- a/tests/test_not_on_a_git_repo.py +++ b/tests/test_not_on_a_git_repo.py @@ -14,7 +14,7 @@ def setup(): - os.makedirs(repo_path, 0700) + os.makedirs(repo_path, 0o700) @raises(GitError) From ae1d94f420249d2eed5dd17fc864b32e08293781 Mon Sep 17 00:00:00 2001 From: Ratson Date: Mon, 30 Mar 2015 19:59:25 +0800 Subject: [PATCH 2/2] Update Python 3 compatibility note in README --- README.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 2124aa9..dc1c963 100644 --- a/README.rst +++ b/README.rst @@ -62,8 +62,7 @@ Otherwise pip will refuse to install ``git-up`` due to ``Access denied`` errors. Python 3 compatibility: ~~~~~~~~~~~~~~~~~~~~~~~ -``PyGitUp`` is not compatible with Python 3 because some essential 3rd party -libs don't support it. Sorry. +Python 3.3 and 3.4 are supported. Options and Configuration -------------------------