Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python 3 support #23

Merged
merged 2 commits into from
Mar 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 5 additions & 3 deletions PyGitUp/git_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
16 changes: 10 additions & 6 deletions PyGitUp/gitup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'))
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_not_on_a_git_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def setup():
os.makedirs(repo_path, 0700)
os.makedirs(repo_path, 0o700)


@raises(GitError)
Expand Down