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
This commit is contained in:
Darragh Bailey 2016-06-09 18:16:15 +01:00
parent 00377869a9
commit 62def85b6b
7 changed files with 19 additions and 13 deletions

View File

@ -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

View File

@ -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()

View File

@ -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')))

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,7 +1,7 @@
[tox]
minversion = 1.6
skipsdist = True
envlist = pep8, py27
envlist = pep8,py34,py27
[testenv]
usedevelop = True