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

Python3 support #46

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ To run the tests, bootstrap Buildout and run this command:
...
$ ./bin/test

We also use Tox_. It will run the tests for Python 2.6 and 2.7.
We also use Tox_. It will run the tests for Python 2.7 and 3.5.

::

Expand All @@ -190,7 +190,7 @@ Requirements
------------

* Git >= 1.7
* Python >= 2.6
* Python >= 2.7

License
-------
Expand Down
23 changes: 16 additions & 7 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
$Id: bootstrap.py 102545 2009-08-06 14:49:47Z chrisw $
"""

import os, shutil, sys, tempfile, urllib2
import os, shutil, sys, tempfile
from optparse import OptionParser

from six.moves import reload_module, urllib


tmpeggs = tempfile.mkdtemp()

is_jython = sys.platform.startswith('java')
Expand All @@ -32,7 +35,7 @@
parser.add_option("-v", "--version", dest="version",
help="use a specific zc.buildout version")
parser.add_option("-d", "--distribute",
action="store_true", dest="distribute", default=True,
action="store_true", dest="distribute", default=False,
help="Use Disribute rather than Setuptools.")

options, args = parser.parse_args()
Expand All @@ -54,16 +57,22 @@
except ImportError:
ez = {}
if USE_DISTRIBUTE:
exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py'
).read() in ez
exec(
urllib.request.urlopen('http://python-distribute.org/distribute_setup.py'
).read(),
ez,
ez)
ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True)
else:
exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
).read() in ez
exec(
urllib.request.urlopen('https://bootstrap.pypa.io/ez_setup.py'
).read(),
ez,
ez)
ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)

if to_reload:
reload(pkg_resources)
reload_module(pkg_resources)
else:
import pkg_resources

Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
version = '0.1.1'

install_requires = [
'GitPython>=0.3.2RC1']
'GitPython>=0.3.2RC1',
'six==1.10.0']

# Add argparse if less than Python 2.7
if sys.version_info[0] <= 2 and sys.version_info[1] < 7:
Expand All @@ -26,8 +27,8 @@
'Intended Audience :: Developers',
'Natural Language :: English',
'Operating System :: POSIX',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Topic :: Software Development :: Quality Assurance',
'Topic :: Software Development :: Version Control',
'Topic :: Text Processing'
Expand Down
3 changes: 2 additions & 1 deletion src/gitsweep/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from textwrap import dedent

from git import Repo, InvalidGitRepositoryError
from six.moves import input

from gitsweep.inspector import Inspector
from gitsweep.deleter import Deleter
Expand Down Expand Up @@ -142,7 +143,7 @@ def _sweep(self):

if not args.force:
sys.stdout.write('\nDelete these branches? (y/n) ')
answer = raw_input()
answer = input()
if args.force or answer.lower().startswith('y'):
sys.stdout.write('\n')
for ref in ok_to_delete:
Expand Down
4 changes: 2 additions & 2 deletions src/gitsweep/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_will_cleanup(self):
self.make_commit()
self.command('git merge branch{0}'.format(i))

with patch('gitsweep.cli.raw_input', create=True) as ri:
with patch('gitsweep.cli.input', create=True) as ri:
ri.return_value = 'y'
(retcode, stdout, stderr) = self.gscommand('git-sweep cleanup')

Expand Down Expand Up @@ -173,7 +173,7 @@ def test_will_abort_cleanup(self):
self.make_commit()
self.command('git merge branch{0}'.format(i))

with patch('gitsweep.cli.raw_input', create=True) as ri:
with patch('gitsweep.cli.input', create=True) as ri:
ri.return_value = 'n'
(retcode, stdout, stderr) = self.gscommand('git-sweep cleanup')

Expand Down
13 changes: 5 additions & 8 deletions src/gitsweep/tests/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from uuid import uuid4 as uuid
from shutil import rmtree
from shlex import split
from contextlib import contextmanager, nested
from contextlib import contextmanager
from textwrap import dedent

from mock import patch
Expand Down Expand Up @@ -241,23 +241,20 @@ def gscommand(self, command):
"""
Runs the command with the given args.
"""
exit_code = None
args = split(command)

self.cli.args = args[1:]

patches = (
patch.object(sys, 'stdout'),
patch.object(sys, 'stderr'))

with nested(*patches):
with patch.object(sys, 'stdout'), patch.object(sys, 'stderr'):
stdout = sys.stdout
stderr = sys.stderr
try:
self.cli.run()
except SystemExit as se:
pass
exit_code = se.code

stdout = ''.join([i[0][0] for i in stdout.write.call_args_list])
stderr = ''.join([i[0][0] for i in stderr.write.call_args_list])

return (se.code, stdout, stderr)
return (exit_code, stdout, stderr)
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ deps =
mock
commands = python -m gitsweep.scripts.test

[testenv:2.6]
basepython = python2.6

[testenv:2.7]
basepython = python2.7

[testenv:3.5]
basepython = python3.5