From 89bcce88792980c41029db2094630a5bbb0c2529 Mon Sep 17 00:00:00 2001 From: Eugene Prikazchikov Date: Fri, 16 Dec 2016 08:49:07 +0300 Subject: [PATCH 1/9] Replace raw_input => six.moves.input This allows to run project under Python3 --- setup.py | 3 ++- src/gitsweep/cli.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index e5483d8..ef9b8fa 100644 --- a/setup.py +++ b/setup.py @@ -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: diff --git a/src/gitsweep/cli.py b/src/gitsweep/cli.py index 6b995b5..6d46bb1 100644 --- a/src/gitsweep/cli.py +++ b/src/gitsweep/cli.py @@ -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 @@ -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: From 0561601b74e452c16b6f9de149825c4b2996f1c8 Mon Sep 17 00:00:00 2001 From: Eugene Prikazchikov Date: Wed, 21 Dec 2016 19:17:01 +0300 Subject: [PATCH 2/9] "distibute" is deprecated, use setuptools instead --- bootstrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap.py b/bootstrap.py index 63aebb9..4a578ea 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -32,7 +32,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() From 28863d0f1bd9586d0772fabd96060d89e0e01662 Mon Sep 17 00:00:00 2001 From: Eugene Prikazchikov Date: Wed, 21 Dec 2016 19:17:45 +0300 Subject: [PATCH 3/9] Use six.moves.urllib instead of urllib2 --- bootstrap.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/bootstrap.py b/bootstrap.py index 4a578ea..35947e2 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -20,9 +20,13 @@ $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') @@ -54,12 +58,18 @@ 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: From 51052d4adf6936d5d10e12d31e65eb94f58a5ac1 Mon Sep 17 00:00:00 2001 From: Eugene Prikazchikov Date: Wed, 21 Dec 2016 19:18:06 +0300 Subject: [PATCH 4/9] Use six.moves.reload_module --- bootstrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap.py b/bootstrap.py index 35947e2..38f4bac 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -73,7 +73,7 @@ ez['use_setuptools'](to_dir=tmpeggs, download_delay=0) if to_reload: - reload(pkg_resources) + reload_module(pkg_resources) else: import pkg_resources From 3780e637e9a261e79cfa62130ec38e35372d6049 Mon Sep 17 00:00:00 2001 From: Eugene Prikazchikov Date: Wed, 21 Dec 2016 19:18:50 +0300 Subject: [PATCH 5/9] Get rid of deprecated contextlib.nested --- src/gitsweep/tests/testcases.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/gitsweep/tests/testcases.py b/src/gitsweep/tests/testcases.py index fd9299c..8f8ce6a 100644 --- a/src/gitsweep/tests/testcases.py +++ b/src/gitsweep/tests/testcases.py @@ -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 @@ -245,11 +245,9 @@ def gscommand(self, 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: From 46990ad2ac403af4b047adacaf5e0ad70cfd35a3 Mon Sep 17 00:00:00 2001 From: Eugene Prikazchikov Date: Wed, 21 Dec 2016 22:18:13 +0300 Subject: [PATCH 6/9] Fix tests --- src/gitsweep/tests/test_cli.py | 4 ++-- src/gitsweep/tests/testcases.py | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/gitsweep/tests/test_cli.py b/src/gitsweep/tests/test_cli.py index 9ddd6ce..cf0f2f3 100644 --- a/src/gitsweep/tests/test_cli.py +++ b/src/gitsweep/tests/test_cli.py @@ -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') @@ -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') diff --git a/src/gitsweep/tests/testcases.py b/src/gitsweep/tests/testcases.py index 8f8ce6a..840e43a 100644 --- a/src/gitsweep/tests/testcases.py +++ b/src/gitsweep/tests/testcases.py @@ -245,9 +245,7 @@ def gscommand(self, command): self.cli.args = args[1:] - with ( - patch.object(sys, 'stdout'), - patch.object(sys, 'stderr')): + with patch.object(sys, 'stdout'), patch.object(sys, 'stderr'): stdout = sys.stdout stderr = sys.stderr try: From 4b7fd43dc0abcb460e52bcc08f7745a98756c3bd Mon Sep 17 00:00:00 2001 From: Eugene Prikazchikov Date: Wed, 21 Dec 2016 22:27:37 +0300 Subject: [PATCH 7/9] Assign status code to local variable In Python3 exception is only accessible inside except clause --- src/gitsweep/tests/testcases.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gitsweep/tests/testcases.py b/src/gitsweep/tests/testcases.py index 840e43a..7931293 100644 --- a/src/gitsweep/tests/testcases.py +++ b/src/gitsweep/tests/testcases.py @@ -241,6 +241,7 @@ def gscommand(self, command): """ Runs the command with the given args. """ + exit_code = None args = split(command) self.cli.args = args[1:] @@ -251,9 +252,9 @@ def gscommand(self, command): 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) From 59ee9580d4dc24610bb5fdef8d9f45fa698736ed Mon Sep 17 00:00:00 2001 From: Eugene Prikazchikov Date: Wed, 21 Dec 2016 22:47:27 +0300 Subject: [PATCH 8/9] Remove mentions of Python2.6 and add Python3.5 --- README.rst | 4 ++-- setup.py | 2 +- tox.ini | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 3fd0286..3ac562a 100644 --- a/README.rst +++ b/README.rst @@ -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. :: @@ -190,7 +190,7 @@ Requirements ------------ * Git >= 1.7 -* Python >= 2.6 +* Python >= 2.7 License ------- diff --git a/setup.py b/setup.py index ef9b8fa..b8e6940 100644 --- a/setup.py +++ b/setup.py @@ -27,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' diff --git a/tox.ini b/tox.ini index e46ef65..f62524a 100644 --- a/tox.ini +++ b/tox.ini @@ -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 From 0880f35163abc9530c5ba3ea15653920101382a7 Mon Sep 17 00:00:00 2001 From: Eugene Prikazchikov Date: Wed, 21 Dec 2016 22:51:03 +0300 Subject: [PATCH 9/9] Remove unneeded blank line --- bootstrap.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bootstrap.py b/bootstrap.py index 38f4bac..1e1fb19 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -26,7 +26,6 @@ from six.moves import reload_module, urllib - tmpeggs = tempfile.mkdtemp() is_jython = sys.platform.startswith('java')