From 62def85b6b10fdf21b0e887f407ca05f83a65c8a Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Thu, 9 Jun 2016 18:16:15 +0100 Subject: [PATCH] Support for python 3 Support using python 3 interpreter. Fix imports and metaclass definition to be python 2/3 compatible. Update min requirements to use GitPython that is python 3 compatible and works with openstack global-requirements. Use '//' for integer division and used brackets around tuple iterations. Change-Id: I51617a433987d1549e0686c1feda01f971b13fa0 --- git_upstream/log.py | 9 ++++++--- git_upstream/main.py | 2 +- git_upstream/tests/base.py | 4 ++-- git_upstream/tests/strategies/test_strategies.py | 2 +- git_upstream/tests/test_import.py | 4 ++-- requirements.txt | 9 ++++++--- tox.ini | 2 +- 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/git_upstream/log.py b/git_upstream/log.py index a5e15ff..9ad38e5 100644 --- a/git_upstream/log.py +++ b/git_upstream/log.py @@ -28,9 +28,11 @@ from functools import wraps import logging import textwrap +import six + # Add new NOTICE logging level -NOTICE = (logging.INFO + logging.WARN) / 2 +NOTICE = (logging.INFO + logging.WARN) // 2 logging.NOTICE = NOTICE logging.addLevelName(NOTICE, "NOTICE") @@ -51,7 +53,7 @@ def get_logger(name=None): Wrapper for standard logging.getLogger that ensures all loggers in this application will have their name prefixed with 'git-upstream'. """ - name = ".".join([x for x in "git-upstream", name if x]) + name = ".".join([x for x in ("git-upstream", name) if x]) logger = logging.getLogger(name) return logger @@ -138,8 +140,9 @@ class DedentLoggerMeta(type): return dedentlog +@six.add_metaclass(DedentLoggerMeta) class DedentLogger(logging.Logger): - __metaclass__ = DedentLoggerMeta + pass # override default logger class for everything that imports this module diff --git a/git_upstream/main.py b/git_upstream/main.py index 799ccb3..7706a5b 100644 --- a/git_upstream/main.py +++ b/git_upstream/main.py @@ -79,7 +79,7 @@ def setup_console_logging(options): # determine maximum logging requested for file and console provided they # are not disabled, and including stderr which is fixed at ERROR main_log_level = min([value - for value in options.log_level, console_log_level + for value in (options.log_level, console_log_level) if value != logging.NOTSET ] + [logging.ERROR]) logger = log.get_logger() diff --git a/git_upstream/tests/base.py b/git_upstream/tests/base.py index efcc323..98b1533 100644 --- a/git_upstream/tests/base.py +++ b/git_upstream/tests/base.py @@ -159,7 +159,7 @@ class GitRepo(fixtures.Fixture): break tmpfile.close() os.remove(tmpfile.name) - tmpfile.write(contents) + tmpfile.write(contents.encode('utf-8')) tmpfile.close() return tmpfile.name @@ -362,4 +362,4 @@ class BaseTestCase(testtools.TestCase): raise self.addDetail('pre-script-output', - text_content(output)) + text_content(output.decode('utf-8'))) diff --git a/git_upstream/tests/strategies/test_strategies.py b/git_upstream/tests/strategies/test_strategies.py index 5695afd..a2ca004 100644 --- a/git_upstream/tests/strategies/test_strategies.py +++ b/git_upstream/tests/strategies/test_strategies.py @@ -25,7 +25,7 @@ from git_upstream.tests.base import BaseTestCase from git_upstream.tests.base import get_scenarios import_command = __import__("git_upstream.commands.import", globals(), - locals(), ['LocateChangesWalk'], -1) + locals(), ['LocateChangesWalk']) LocateChangesWalk = import_command.LocateChangesWalk diff --git a/git_upstream/tests/test_import.py b/git_upstream/tests/test_import.py index 8b806ec..b0f033a 100644 --- a/git_upstream/tests/test_import.py +++ b/git_upstream/tests/test_import.py @@ -15,10 +15,10 @@ """Tests for the 'import' module""" -from base import BaseTestCase +from git_upstream.tests.base import BaseTestCase import_command = __import__("git_upstream.commands.import", globals(), - locals(), ['ImportUpstream'], -1) + locals(), ['ImportUpstream']) ImportUpstream = import_command.ImportUpstream diff --git a/requirements.txt b/requirements.txt index 9401cff..5e2bc81 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,7 @@ -pbr>=0.5.21,<1.0 - argcomplete -GitPython>=0.3.2.RC1,!=0.3.2 +# GitPython 1.0.1 required by openstack global-requirements +# python>=3 should work with >=0.3.4 +# python<3 should work with >=0.3.2.RC1,!=0.3.2 +GitPython>=1.0.1 # BSD License (3 clause) +pbr>=0.5.21,<1.0 +six>=1.9.0 # MIT diff --git a/tox.ini b/tox.ini index cc05879..7112d42 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] minversion = 1.6 skipsdist = True -envlist = pep8, py27 +envlist = pep8,py34,py27 [testenv] usedevelop = True