1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
From: Emmanuel Arias <eamanu@yaerobi.com>
Date: Fri, 6 Jan 2023 01:18:41 -0300
Subject: Stop using rapidfuzz. Revert upstream change in Debian.
Upstream introduce rapidfuzz instead of pylev because the first one
improve performance on find_similar_names. This brekas the build in
Debian because rapidfuzz is not in Debian yet. This patch revert that
change. We should remove this patch when rapidfuzz is in Debian. Also,
add pylev in pyproject.toml file.
---
src/cleo/_utils.py | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
Index: cleo/src/cleo/_utils.py
===================================================================
--- cleo.orig/src/cleo/_utils.py 2023-01-17 18:42:28.057211553 -0300
+++ cleo/src/cleo/_utils.py 2023-01-17 18:42:28.053211495 -0300
@@ -5,7 +5,7 @@
from dataclasses import dataclass
from html.parser import HTMLParser
-from rapidfuzz.distance import Levenshtein
+from pylev import levenshtein
class TagStripper(HTMLParser):
@@ -53,10 +53,11 @@
"""
threshold = 1e3
distance_by_name = {}
+ suggested_names = []
for actual_name in names:
# Get Levenshtein distance between the input and each command name
- distance = Levenshtein.distance(name, actual_name)
+ distance = levenshtein(name, actual_name)
is_similar = distance <= len(name) / 3
is_sub_string = actual_name.find(name) != -1
@@ -72,7 +73,11 @@
k: v for k, v in distance_by_name.items() if v[0] < 2 * threshold
}
# Display results with shortest distance first
- return sorted(distance_by_name, key=lambda x: distance_by_name[x])
+ for k, _v in sorted(distance_by_name.items(), key=lambda i: (i[1][0], i[1][1])):
+ if k not in suggested_names:
+ suggested_names.append(k)
+
+ return suggested_names
@dataclass
Index: cleo/pyproject.toml
===================================================================
--- cleo.orig/pyproject.toml 2023-01-17 18:42:28.057211553 -0300
+++ cleo/pyproject.toml 2023-01-17 18:42:28.053211495 -0300
@@ -33,7 +33,7 @@
[tool.poetry.dependencies]
python = "^3.7"
crashtest = "^0.4.1"
-rapidfuzz = "^2.2.0"
+pylev = "^1.4.0"
[tool.poetry.group.dev.dependencies]
pytest = "^7.1.2"
|