diff options
author | shimizukawa <shimizukawa@gmail.com> | 2014-10-05 22:25:50 +0900 |
---|---|---|
committer | shimizukawa <shimizukawa@gmail.com> | 2014-10-05 22:25:50 +0900 |
commit | c4b6db9e044695190057ce3c8e3d3e7cc8b95106 (patch) | |
tree | 2fabbe5403ef062b803549cd7bb039b4745c49aa | |
parent | 91d42c2828313a3078374241a1b299f546415154 (diff) | |
download | sphinx-c4b6db9e044695190057ce3c8e3d3e7cc8b95106.tar.gz |
If the ``python-levenshtein`` 3rd-party package is installed, it will improve the calculation time. refs #1426.
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | doc/config.rst | 4 | ||||
-rw-r--r-- | sphinx/versioning.py | 11 |
3 files changed, 16 insertions, 1 deletions
@@ -22,6 +22,8 @@ Incompatible changes method to make the `any` role work properly. * gettext builder: gettext doesn't emit uuid information to generated pot files by default. Please set ``True`` to `gettext_uuid` to emit uuid information. + Additionally, if the ``python-levenshtein`` 3rd-party package is installed, + it will improve the calculation time. * gettext builder: disable extracting/apply 'index' node by default. Please set 'index' to :confval:`gettext_enables` to enable extracting index entries. diff --git a/doc/config.rst b/doc/config.rst index 067a2654..c5a57267 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -430,6 +430,10 @@ documentation on :ref:`intl` for details. * Calculate similarity between new msgids and previously saved old msgids. This calculation take many time. + If you need a speed for the calculation, you can use ``python-levenshtein`` + 3rd-party package written in C by using + :command:`pip install python-levenshtein`. + The default is ``False``. .. versionadded:: 1.3 diff --git a/sphinx/versioning.py b/sphinx/versioning.py index 22ecda60..1be4d39b 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): |