diff options
author | Takayuki Shimizukawa <shimizukawa@gmail.com> | 2014-10-05 17:25:50 +0400 |
---|---|---|
committer | Takayuki Shimizukawa <shimizukawa@gmail.com> | 2014-10-05 17:25:50 +0400 |
commit | fa30e7b52a2103d07cfeccf9403de4a75ec72184 (patch) | |
tree | 2fabbe5403ef062b803549cd7bb039b4745c49aa /sphinx/versioning.py | |
parent | ee98decec11f4dcdfc115eb4acb7e31ea900dbe5 (diff) |
If the ``python-levenshtein`` 3rd-party package is installed, it will improve the calculation time. refs #1426.
Diffstat (limited to 'sphinx/versioning.py')
-rw-r--r-- | sphinx/versioning.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/sphinx/versioning.py b/sphinx/versioning.py index 22ecda60c..1be4d39bc 100644 --- a/sphinx/versioning.py +++ b/sphinx/versioning.py @@ -16,6 +16,11 @@ from itertools import product from six import iteritems from six.moves import range, zip_longest +try: + import Levenshtein + IS_SPEEDUP = True +except ImportError: + IS_SPEEDUP = False # anything below that ratio is considered equal/changed VERSIONING_RATIO = 65 @@ -109,7 +114,11 @@ def get_ratio(old, new): """ if not all([old, new]): return VERSIONING_RATIO - return levenshtein_distance(old, new) / (len(old) / 100.0) + + if IS_SPEEDUP: + return Levenshtein.distance(old, new) / (len(old) / 100.0) + else: + return levenshtein_distance(old, new) / (len(old) / 100.0) def levenshtein_distance(a, b): |