summaryrefslogtreecommitdiff
path: root/sphinx/versioning.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/versioning.py')
-rw-r--r--sphinx/versioning.py29
1 files changed, 13 insertions, 16 deletions
diff --git a/sphinx/versioning.py b/sphinx/versioning.py
index 78383464c..d39c9538e 100644
--- a/sphinx/versioning.py
+++ b/sphinx/versioning.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
"""
sphinx.versioning
~~~~~~~~~~~~~~~~~
@@ -9,15 +8,13 @@
:copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
+import pickle
import warnings
-from itertools import product
+from itertools import product, zip_longest
from operator import itemgetter
+from os import path
from uuid import uuid4
-from six import iteritems
-from six.moves import cPickle as pickle
-from six.moves import range, zip_longest
-
from sphinx.deprecation import RemovedInSphinx30Warning
from sphinx.transforms import SphinxTransform
@@ -102,7 +99,7 @@ def merge_doctrees(old, new, condition):
# choose the old node with the best ratio for each new node and set the uid
# as long as the ratio is under a certain value, in which case we consider
# them not changed but different
- ratios = sorted(iteritems(ratios), key=itemgetter(1)) # type: ignore
+ ratios = sorted(ratios.items(), key=itemgetter(1)) # type: ignore
for (old_node, new_node), ratio in ratios:
if new_node in seen:
continue
@@ -121,7 +118,7 @@ def merge_doctrees(old, new, condition):
def get_ratio(old, new):
- # type: (unicode, unicode) -> float
+ # type: (str, str) -> float
"""Return a "similiarity ratio" (in percent) representing the similarity
between the two strings where 0 is equal and anything above less than equal.
"""
@@ -135,7 +132,7 @@ def get_ratio(old, new):
def levenshtein_distance(a, b):
- # type: (unicode, unicode) -> int
+ # type: (str, str) -> int
"""Return the Levenshtein edit distance between two strings *a* and *b*."""
if a == b:
return 0
@@ -143,7 +140,7 @@ def levenshtein_distance(a, b):
a, b = b, a
if not a:
return len(b)
- previous_row = range(len(b) + 1)
+ previous_row = list(range(len(b) + 1))
for i, column1 in enumerate(a):
current_row = [i + 1]
for j, column2 in enumerate(b):
@@ -151,7 +148,7 @@ def levenshtein_distance(a, b):
deletions = current_row[j] + 1
substitutions = previous_row[j] + (column1 != column2)
current_row.append(min(insertions, deletions, substitutions))
- previous_row = current_row # type: ignore
+ previous_row = current_row
return previous_row[-1]
@@ -159,8 +156,8 @@ class UIDTransform(SphinxTransform):
"""Add UIDs to doctree for versioning."""
default_priority = 880
- def apply(self):
- # type: () -> None
+ def apply(self, **kwargs):
+ # type: (Any) -> None
env = self.env
old_doctree = None
if not env.versioning_condition:
@@ -169,10 +166,10 @@ class UIDTransform(SphinxTransform):
if env.versioning_compare:
# get old doctree
try:
- filename = env.doc2path(env.docname, env.doctreedir, '.doctree')
+ filename = path.join(env.doctreedir, env.docname + '.doctree')
with open(filename, 'rb') as f:
old_doctree = pickle.load(f)
- except EnvironmentError:
+ except OSError:
pass
# add uids for versioning
@@ -183,7 +180,7 @@ class UIDTransform(SphinxTransform):
def prepare(document):
- # type: (nodes.Node) -> None
+ # type: (nodes.document) -> None
"""Simple wrapper for UIDTransform."""
warnings.warn('versioning.prepare() is deprecated. Use UIDTransform instead.',
RemovedInSphinx30Warning, stacklevel=2)