From f36461dc14172df19cd45f2bfc6e64dd33e67aa0 Mon Sep 17 00:00:00 2001 From: jakub-safetycli Date: Thu, 20 Feb 2025 10:25:24 -0800 Subject: [PATCH] chore: Replaced edit distance with NLTK package --- pyproject.toml | 2 +- safety/tool/utils.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f97cf6e4..80e03ae4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,7 +49,7 @@ dependencies = [ "setuptools>=65.5.1", "typer>=0.12.1", "typing-extensions>=4.7.1", - "python-levenshtein>=0.25.1", + "nltk>=3.9", ] license = "MIT" license-files = ["LICENSES/*"] diff --git a/safety/tool/utils.py b/safety/tool/utils.py index 99c8993f..dfad33f3 100644 --- a/safety/tool/utils.py +++ b/safety/tool/utils.py @@ -8,7 +8,7 @@ from tempfile import mkstemp import typer -from Levenshtein import distance +import nltk from filelock import FileLock from rich.padding import Padding from rich.prompt import Prompt @@ -227,7 +227,7 @@ def __check_typosquatting(self, package_name): for pkg in MOST_FREQUENTLY_DOWNLOADED_PYPI_PACKAGES: if (abs(len(pkg) - len(package_name)) <= max_edit_distance - and distance(pkg, package_name) <= max_edit_distance): + and nltk.edit_distance(pkg, package_name) <= max_edit_distance): return (False, pkg) return (True, package_name)