Skip to content

Commit

Permalink
Compatibility fix for Python 3.3
Browse files Browse the repository at this point in the history
ymattw committed Nov 18, 2024
1 parent 2616f39 commit f703394
Showing 4 changed files with 19 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -2,6 +2,10 @@
Change log
==========

Version 1.4.2 (2024-11-18)

- Compatibility Fix: Ensure ydiff works properly with Python 3.3 and later.

Version 1.4.1 (2024-11-13)

- Fix setup() dependency: MANIFEST.in is still required for Python < 3.8 to
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -48,15 +48,21 @@ build:
./setup.py build sdist

# Expected to run outside docker with twine installed via pip
dist-test: docker-test clean build
dist-test: docker-test-min-python3 docker-test clean build
~/.local/bin/twine upload --repository=testpypi dist/ydiff-*.tar.gz
rm -f ~/.pypirc

# Expected to run outside docker with twine installed via pip
dist: docker-test clean build
dist: docker-test-min-python3 docker-test clean build
~/.local/bin/twine upload dist/ydiff-*.tar.gz
rm -f ~/.pypirc

MIN_PY_VERSION ?= 3.3
docker-test-min-python3:
docker run -v $(shell pwd):$(shell pwd) -w $(shell pwd) -t --rm \
python:$(MIN_PY_VERSION)-alpine /bin/sh -ec \
'apk add -U bash git less make; pip install --trusted-host pypi.python.org -r requirements-dev.txt; make test'

docker-test:
docker run -v $(shell pwd):$(shell pwd) -w $(shell pwd) -t --rm \
python:3-alpine /bin/sh -ec \
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Pygments
coverage
docutils==0.20.1
docutils<=0.20.1
pycodestyle
13 changes: 6 additions & 7 deletions ydiff.py
Original file line number Diff line number Diff line change
@@ -14,10 +14,9 @@
import subprocess
import sys
import unicodedata
from typing import List, Tuple

PKG_INFO = {
'version' : '1.4.1',
'version' : '1.4.2',
'license' : 'BSD-3',
'author' : 'Matt Wang',
'url' : 'https://github.com/ymattw/ydiff',
@@ -193,7 +192,7 @@ def _strtrim(text, width, wrap_char, pad, color_codes):
return left


def _split_to_words(s: str) -> List[str]:
def _split_to_words(s: str) -> list:
r"""Split to list of "words" for fine-grained comparison by breaking
all uppercased/lowercased, camel and snake cased names at the "word"
boundary. Note '\s' has to be here to match '\n'.
@@ -202,7 +201,7 @@ def _split_to_words(s: str) -> List[str]:
return r.findall(s)


def _word_diff(a: str, b: str) -> Tuple[str, str]:
def _word_diff(a: str, b: str) -> tuple:
r"""Takes the from/to texts yield by Hunk.mdiff() which are part of the
'changed' block, remove the special markers (\0-, \0+, \0^, \1), compare
word by word and return two new texts with the markers reassemabled.
@@ -436,7 +435,7 @@ def __init__(self, side_by_side=False, width=0, tab_width=8, wrap=False,
self._tab_width = tab_width
self._wrap = wrap
self._theme = theme
self._codes = set(sum(_THEMES[theme].values(), start=[]))
self._codes = set(sum(_THEMES[theme].values(), []))

def markup(self, diff):
"""Returns a generator"""
@@ -703,7 +702,7 @@ def _revision_control_log(vcs_name, args):
return subprocess.Popen(cmd + args, stdout=subprocess.PIPE).stdout


def _check_command_status(cmd: List[str]) -> bool:
def _check_command_status(cmd: list) -> bool:
"""Return True if command returns 0."""
try:
return subprocess.call(
@@ -804,7 +803,7 @@ def _process_args(self, largs, rargs, values):
parser.add_option(
'-o', '--pager-options', metavar='OPT',
help="""options to supply to pager application""")
themes = ', '.join(['default', *sorted(_THEMES.keys() - {'default'})])
themes = ', '.join(['default'] + sorted(_THEMES.keys() - {'default'}))
parser.add_option(
'', '--theme', metavar='THEME', default='default',
help="""option to pick a color theme (one of %s)""" % themes)

0 comments on commit f703394

Please sign in to comment.