diff options
author | Georg Brandl <georg@python.org> | 2010-08-21 19:03:44 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-08-21 19:03:44 +0200 |
commit | 6ffec123a92ffc903af7e60a776f222d6e01cee8 (patch) | |
tree | 092d6ac8d3f025676ebc2f9c412838bc03fc7fc4 /sphinx/versioning.py | |
parent | 0ff840dc48023e8a3f2be9aef6f38e375e5a7911 (diff) | |
download | sphinx-git-6ffec123a92ffc903af7e60a776f222d6e01cee8.tar.gz |
Small code style changes, remove unused imports.
Diffstat (limited to 'sphinx/versioning.py')
-rw-r--r-- | sphinx/versioning.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/sphinx/versioning.py b/sphinx/versioning.py index 06acc63dc..430dc1423 100644 --- a/sphinx/versioning.py +++ b/sphinx/versioning.py @@ -18,15 +18,14 @@ try: except ImportError: from itertools import zip_longest -from sphinx.util import PeekableIterator # anything below that ratio is considered equal/changed VERSIONING_RATIO = 65 + def add_uids(doctree, condition): - """ - Adds a unique id to every node in the `doctree` which matches the condition - and yields it. + """Add a unique id to every node in the `doctree` which matches the + condition and yield the nodes. :param doctree: A :class:`docutils.nodes.document` instance. @@ -38,10 +37,10 @@ def add_uids(doctree, condition): node.uid = uuid4().hex yield node + def merge_doctrees(old, new, condition): - """ - Merges the `old` doctree with the `new` one while looking at nodes matching - the `condition`. + """Merge the `old` doctree with the `new` one while looking at nodes + matching the `condition`. Each node which replaces another one or has been added to the `new` doctree will be yielded. @@ -102,16 +101,18 @@ def merge_doctrees(old, new, condition): new_node.uid = uuid4().hex yield new_node + def get_ratio(old, new): - """ - Returns a "similiarity ratio" representing the similarity between the two - strings where 0 is equal and anything above less than equal. + """Return a "similiarity ratio" (in percent) representing the similarity + between the two strings where 0 is equal and anything above less than equal. """ if not all([old, new]): return VERSIONING_RATIO return levenshtein_distance(old, new) / (len(old) / 100.0) + def levenshtein_distance(a, b): + """Return the Levenshtein edit distance between two strings *a* and *b*.""" if a == b: return 0 if len(a) < len(b): |