From 2070307c9d4d476d6e3ac727f7d6f5fa5d08df00 Mon Sep 17 00:00:00 2001 From: Klemek Date: Fri, 1 May 2020 22:59:40 +0200 Subject: [PATCH] making levenstein lib optional --- meme_otron/utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/meme_otron/utils.py b/meme_otron/utils.py index 8dc8e66..417a663 100644 --- a/meme_otron/utils.py +++ b/meme_otron/utils.py @@ -6,7 +6,11 @@ from urllib.error import URLError, HTTPError from urllib.parse import urlparse import os.path as path from typing import List, Optional, Union, Tuple, BinaryIO -from Levenshtein import distance + +try: + from Levenshtein import distance +except ModuleNotFoundError: + distance = None # region path utils @@ -137,6 +141,8 @@ def split_arguments(args: Union[List[str], Tuple[str]], separator: str) -> List[ def find_nearest(word: str, wlist: List[str], threshold: int = 5) -> Optional[str]: + if distance is None: + return None distances = [ (distance(word, w), # distance abs(len(w) - len(word)), # length diff