From ce52c5fb04c1790146b1a8d0d57004e2a3cfdd8b Mon Sep 17 00:00:00 2001 From: Akinori Hattori Date: Wed, 24 May 2017 22:04:58 +0900 Subject: [PATCH 1/3] Fix test on Windows --- tests/test_diff_highlight.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_diff_highlight.py b/tests/test_diff_highlight.py index 57ce452..ee61221 100644 --- a/tests/test_diff_highlight.py +++ b/tests/test_diff_highlight.py @@ -20,8 +20,12 @@ class TestDiffHighlight(unittest.TestCase): @unittest.skipIf(color is None, "mercurial is not supported py3") def test_colorui(self): - import curses - curses.setupterm("xterm", 1) + try: + import curses + + curses.setupterm("xterm", 1) + except ImportError: + pass color._styles['diff.inserted_highlight'] = 'green inverse' color._styles['diff.deleted_highlight'] = 'red inverse' From 8a65f680724fe87d61adf833101443a763f8a92b Mon Sep 17 00:00:00 2001 From: Akinori Hattori Date: Sun, 17 Sep 2017 20:48:43 +0900 Subject: [PATCH 2/3] Fix for mercurial-4.2 --- .travis.yml | 1 + src/diff_highlight.py | 37 +++++++++++++++++++++++----------- tests/test_diff_highlight.py | 39 ++++++++++++++++++++++++++++-------- tox.ini | 8 +++++++- 4 files changed, 64 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6938b6a..648f85b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ env: - TOXENV=hg35 - TOXENV=hg36 - TOXENV=hg41 + - TOXENV=hg42 - TOXENV=coverage install: pip install docutils tox script: tox diff --git a/src/diff_highlight.py b/src/diff_highlight.py index 4bb2e0d..e8b9dfd 100644 --- a/src/diff_highlight.py +++ b/src/diff_highlight.py @@ -14,8 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from hgext import color -from mercurial import extensions +from mercurial import extensions, ui, util from mercurial.i18n import _ from highlights.pprint import INSERTED, DELETED, pprint_hunk @@ -25,7 +24,7 @@ DELETE_EMPH = 'diff.deleted_highlight' -class colorui(color.colorui): +class colorui(ui.ui): hunk = None tab = None @@ -89,23 +88,37 @@ def uisetup(ui): return try: - extensions.find('color') - except KeyError: - ui.warn(_("warning: 'diff-highlight' requires 'color' extension " - "to be enabled, but not\n")) - return + from hgext import color as colorext + + try: + extensions.find('color') + except KeyError: + ui.warn(_("warning: 'diff-highlight' requires 'color' extension " + "to be enabled, but not\n")) + return + except ImportError: + colorext = None + try: + from mercurial import color + except ImportError: + pass if not isinstance(ui, colorui): colorui.__bases__ = (ui.__class__,) ui.__class__ = colorui + ver = tuple(int(s) if s.isdigit() else s for s in util.version().split('.')) + def colorconfig(orig, *args, **kwargs): ret = orig(*args, **kwargs) - try: - from mercurial.color import _styles as styles - except ImportError: + if ver < (4, 1): + styles = colorext._styles + elif ver < (4, 2): styles = color._styles + else: + styles = color._defaultstyles + if INSERT_EMPH not in styles: styles[INSERT_EMPH] = styles[INSERT_NORM] + ' inverse' @@ -114,4 +127,4 @@ def colorconfig(orig, *args, **kwargs): return ret - extensions.wrapfunction(color, 'configstyles', colorconfig) + extensions.wrapfunction(colorext if ver < (4, 2) else color, 'configstyles', colorconfig) diff --git a/tests/test_diff_highlight.py b/tests/test_diff_highlight.py index ee61221..f7df1d3 100644 --- a/tests/test_diff_highlight.py +++ b/tests/test_diff_highlight.py @@ -7,10 +7,16 @@ import unittest if sys.version_info < (3, 0): + try: + from hgext import color + + colorext = color + except ImportError: + colorext = None try: from mercurial import color except ImportError: - from hgext import color + pass from diff_highlight import colorui from mercurial.util import version as mercurial_version else: @@ -26,10 +32,18 @@ def test_colorui(self): curses.setupterm("xterm", 1) except ImportError: pass - color._styles['diff.inserted_highlight'] = 'green inverse' - color._styles['diff.deleted_highlight'] = 'red inverse' ui = colorui() + if mercurial_version() >= "4.2.0": + ui.setconfig('ui', 'color', 'always') + color.setup(ui) + styles = ui._styles + else: + colorui.__bases__ = (colorext.colorui,) + styles = color._styles + styles['diff.inserted_highlight'] = 'green inverse' + styles['diff.deleted_highlight'] = 'red inverse' + if mercurial_version() >= "3.7.0": ui.pushbuffer(labeled=True) else: @@ -48,13 +62,22 @@ def test_colorui(self): ui.write(" ", '') ui.write("\n", '') - stop = "\x1b(B\x1b[m" + if mercurial_version() >= "4.2.0": + stop = "\x1b[0m" + + def start(*colors): + return "\x1b[0;" + ";".join(str(c) for c in colors) + "m" + + def restart(*colors): + return stop + start(*colors) + else: + stop = "\x1b(B\x1b[m" - def start(*colors): - return stop + "".join("\x1b[%dm" % c for c in colors) + def start(*colors): + return stop + "".join("\x1b[%dm" % c for c in colors) - def restart(*colors): - return stop + start(*colors) + def restart(*colors): + return stop + start(*colors) if mercurial_version() >= "3.7.0": lines = ui.popbuffer().splitlines() diff --git a/tox.ini b/tox.ini index c28ba24..d38641c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=py26,py27,py32,py33,py34,py35,hg35,hg36,hg41 +envlist=py26,py27,py32,py33,py34,py35,hg35,hg36,hg41,hg42 [testenv] deps= @@ -71,6 +71,12 @@ deps= {[testenv:py3_common]deps} mercurial<4.2 +[testenv:hg42] +basepython= python2.7 +deps= + {[testenv:py3_common]deps} + mercurial<4.3 + [testenv:coverage] basepython= python2.7 deps= From 912245104964f340a7fbec15c6769c7ec8aa52a1 Mon Sep 17 00:00:00 2001 From: Akinori Hattori Date: Sun, 17 Sep 2017 21:16:01 +0900 Subject: [PATCH 3/3] Do not test for py26 on Travis CI Mercurial 4.3 drops support for Python 2.6. --- .travis.yml | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 648f85b..684c922 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,20 @@ language: python +sudo: false python: 3.5 -env: - matrix: - - TOXENV=py26 - - TOXENV=py27 - - TOXENV=py33 - - TOXENV=py34 - - TOXENV=py35 - - TOXENV=hg35 - - TOXENV=hg36 - - TOXENV=hg41 - - TOXENV=hg42 - - TOXENV=coverage +matrix: + include: + - python: 2.7 + env: TOXENV=py27 + - python: 3.3 + env: TOXENV=py33 + - python: 3.4 + env: TOXENV=py34 + - python: 3.5 + env: TOXENV=py35 + - env: TOXENV=hg35 + - env: TOXENV=hg36 + - env: TOXENV=hg41 + - env: TOXENV=hg42 + - env: TOXENV=coverage install: pip install docutils tox script: tox