Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.6.8
3.11
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
language: python
dist: jammy
python:
- "3.6.6"
- "3.11"
# command to install dependencies
install:
- pip install -r requirements-dev.txt
- make dev
# command to run tests
script:
- flake8 sdiff tests
- nosetests
- make test
- make coverage
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

PYTHON=venv/bin/python3
PIP=venv/bin/pip
NOSE=venv/bin/nosetests
COVERAGE=venv/bin/coverage
TEST_RUNNER=venv/bin/pytest
TEST_RUNNER_FLAGS=-s --durations=3 --durations-min=0.005
FLAKE=venv/bin/flake8
FLAGS=
PYPICLOUD_HOST=pypicloud.getkeepsafe.local
Expand All @@ -29,14 +31,16 @@ flake:
$(FLAKE) sdiff tests

test: flake
$(NOSE) -s $(FLAGS)
$(COVERAGE) run -m pytest $(TEST_RUNNER_FLAGS)

vtest:
$(NOSE) -s -v $(FLAGS)
$(COVERAGE) run -m pytest -v $(TEST_RUNNER_FLAGS)

testloop:
while sleep 1; do $(TEST_RUNNER) -s --lf $(TEST_RUNNER_FLAGS); done

cov cover coverage:
$(NOSE) -s --with-cover --cover-html --cover-html-dir ./coverage $(FLAGS)
echo "open file://`pwd`/coverage/index.html"
$(COVERAGE) report -m

clean:
rm -rf `find . -name __pycache__`
Expand Down
4 changes: 1 addition & 3 deletions sdiff/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from typing import Type

from .parser import parse, MdParser, ZendeskHelpMdParser # noqa
from .renderer import TextRenderer
from .compare import diff_struct, diff_links # noqa


def diff(md1, md2, renderer=TextRenderer(), parser_cls: Type[MdParser] = MdParser):
def diff(md1, md2, renderer=TextRenderer(), parser_cls: type[MdParser] = MdParser):
tree1 = parse(md1, parser_cls)
tree2 = parse(md2, parser_cls)

Expand Down
2 changes: 1 addition & 1 deletion sdiff/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class DiffError(object):
class DiffError:

def __str__(self):
return self.message
Expand Down
14 changes: 7 additions & 7 deletions sdiff/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class ZendeskArtSymbols(Enum):
callout = 'C'


class Node(object):
class Node:
symbol = Symbols.null.value
name = ''

def __init__(self, nodes=None):
self.nodes: typing.List[Node] = nodes or []
self.nodes: list[Node] = nodes or []
self.meta = {}

def __str__(self):
Expand All @@ -57,7 +57,7 @@ def add_nodes(self, nodes):
self.nodes.extend(nodes)

def print_all(self):
return '%s%s' % (self.symbol, ''.join(map(lambda i: i.print_all(), self.nodes)))
return '{}{}'.format(self.symbol, ''.join(map(lambda i: i.print_all(), self.nodes)))


class Root(Node):
Expand Down Expand Up @@ -112,7 +112,7 @@ def original(self, renderer):
return renderer.render_node(self, result)

def print_all(self):
return '%s%s' % (self.level, ''.join(map(lambda i: i.print_all(), self.nodes)))
return '{}{}'.format(self.level, ''.join(map(lambda i: i.print_all(), self.nodes)))


class List(Node):
Expand All @@ -138,7 +138,7 @@ def original(self, renderer):
result = ''
for idx, node in enumerate(self.nodes):
if self.ordered:
result += '%s. %s' % (idx, node.original(renderer))
result += '{}. {}'.format(idx, node.original(renderer))
else:
result += '* ' + node.original(renderer)
result = result + '\n\n'
Expand Down Expand Up @@ -222,7 +222,7 @@ def __repr__(self):
return repr({'type': self.name, 'meta': self.meta})

def original(self, renderer):
return renderer.render_node(self, u' \u00B6\n')
return renderer.render_node(self, ' \u00B6\n')


class ZendeskHelpNode(Node, ABC):
Expand Down Expand Up @@ -257,7 +257,7 @@ class ZendeskHelpCallout(ZendeskHelpNode):
symbol = ZendeskArtSymbols.callout.value
name = 'callout'

def __init__(self, style: str = None, nodes: typing.List[Node] = None):
def __init__(self, style: str = None, nodes: list[Node] = None):
super().__init__(nodes)
self.style = style

Expand Down
10 changes: 5 additions & 5 deletions sdiff/parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Match, Type
from re import Match

import mistune
import re
Expand Down Expand Up @@ -76,10 +76,10 @@ def get_lexer(cls):
def __init__(self):
super().__init__()
self.grammar_class.block_html = re.compile(
r'^\s* *(?:%s|%s|%s) *(?:\n{1,}|\s*$)' % (
r'^\s* *(?:{}|{}|{}) *(?:\n{{1,}}|\s*$)'.format(
r'<!--[\s\S]*?-->',
r'<(%s)((?:%s)*?)>([\s\S]+?)<\/\1>' % (mistune._block_tag, mistune._valid_attr),
r'<%s(?:%s)*?>' % (mistune._block_tag, mistune._valid_attr),
r'<({})((?:{})*?)>([\s\S]+?)<\/\1>'.format(mistune._block_tag, mistune._valid_attr),
r'<{}(?:{})*?>'.format(mistune._block_tag, mistune._valid_attr),
)
)

Expand Down Expand Up @@ -212,7 +212,7 @@ def _remove_ltr_rtl_marks(text):
return re.sub(r'(\u200e|\u200f)', '', text)


def parse(text, parser_cls: Type[MdParser] = MdParser):
def parse(text, parser_cls: type[MdParser] = MdParser):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommended to use type over Type?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is how pyupgrade --py36-plus works by default: tries to use typing.type which fails

Additionally typing.Type usage seems to be deprecated according to: https://docs.python.org/3.11/library/typing.html#typing

so at this point using type[My_Class] should be way to go

# HACK dirty hack to be consistent with Markdown list_block
text = _remove_spaces_from_empty_lines(text)
text = _remove_ltr_rtl_marks(text)
Expand Down
4 changes: 2 additions & 2 deletions sdiff/renderer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sdiff.model import Root, Node


class HtmlRenderer(object):
class HtmlRenderer:

def render(self, tree: Root):
result = tree.original(self)
Expand All @@ -15,7 +15,7 @@ def render_node(self, node, text):
return text


class TextRenderer(object):
class TextRenderer:

def render(self, tree: Root):
result = tree.original(self)
Expand Down
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ ignore = F403, F405

[pep8]
max-line-length = 120

[coverage:run]
branch = True

[coverage:report]
fail_under = 96
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from setuptools import setup, find_packages


version = '0.4.1'
version = '1.0.0'


def read(f):
Expand All @@ -14,8 +14,9 @@ def read(f):
]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any need to upgrade this library? mistune

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are using v1 of this library: https://github.com/lepture/mistune/tree/v1 0.8.4 is last version of v1 then there is v2 and v3 which may break compatibility - I've have not checked but:

  • v1 docs says it's python 3.5+ compatible
  • we have tests covering usage of mistune starting from ParserTestCase and it seems coverage is pretty good.


tests_require = [
'nose',
'flake8',
'pytest >= 8',
'coverage==7.6.1',
'flake8==7.1.1',
'autopep8',
]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_sdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def _load_fixture(*path):

def _read_test_files(dirpath):
path = Path(os.path.join('tests/fixtures', dirpath))
filenames = set(f.name.split('.')[0] for f in path.glob('*.md'))
filenames = {f.name.split('.')[0] for f in path.glob('*.md')}
Comment thread
snejku marked this conversation as resolved.
return [('%s.en.md' % fn, '%s.de.md' % fn) for fn in filenames]


Expand Down