diff --git a/.travis.yml b/.travis.yml
index 120597a745..b887cac1b6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -29,6 +29,9 @@ matrix:
- os: linux
env:
- MB_PYTHON_VERSION=3.8
+ - os: linux
+ env:
+ - MB_PYTHON_VERSION=3.9
before_install:
- source multibuild/common_utils.sh
- source multibuild/travis_steps.sh
@@ -46,4 +49,4 @@ notifications:
email:
- penkov+gensimwheels@pm.me
on_success: always
- on_failure: always
\ No newline at end of file
+ on_failure: always
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index dfe8f22fb4..8e8102fa12 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -12,6 +12,9 @@ strategy:
py38:
python.version: '3.8'
TOXENV: "py38-win"
+ py39:
+ python.version: '3.9'
+ TOXENV: "py39-win"
steps:
- task: UsePythonVersion@0
diff --git a/gensim/similarities/__init__.py b/gensim/similarities/__init__.py
index 3ab45261ad..15fa6af536 100644
--- a/gensim/similarities/__init__.py
+++ b/gensim/similarities/__init__.py
@@ -3,7 +3,18 @@
"""
# bring classes directly into package namespace, to save some typing
-
+import warnings
+try:
+ import Levenshtein # noqa:F401
+except ImportError:
+ warnings.warn(
+ "The gensim.similarities.levenshtein submodule is disabled, because the optional "
+ "Levenshtein package is unavailable. "
+ "Install Levenhstein (e.g. `pip install python-Levenshtein`) to suppress this warning."
+ )
+ LevenshteinSimilarityIndex = None
+else:
+ from .levenshtein import LevenshteinSimilarityIndex # noqa:F401
from .docsim import ( # noqa:F401
Similarity,
MatrixSimilarity,
@@ -15,4 +26,3 @@
UniformTermSimilarityIndex,
WordEmbeddingSimilarityIndex,
SparseTermSimilarityMatrix)
-from .levenshtein import LevenshteinSimilarityIndex # noqa:F401
diff --git a/gensim/test/test_similarities.py b/gensim/test/test_similarities.py
index ee10550da3..4929082c2a 100644
--- a/gensim/test/test_similarities.py
+++ b/gensim/test/test_similarities.py
@@ -1545,6 +1545,7 @@ def test_inner_product_corpus_corpus_true_true(self):
class TestLevenshteinDistance(unittest.TestCase):
+ @unittest.skipIf(LevenshteinSimilarityIndex is None, "gensim.similarities.levenshtein is disabled")
def test_max_distance(self):
t1 = "holiday"
t2 = "day"
@@ -1557,12 +1558,14 @@ def test_max_distance(self):
class TestLevenshteinSimilarity(unittest.TestCase):
+ @unittest.skipIf(LevenshteinSimilarityIndex is None, "gensim.similarities.levenshtein is disabled")
def test_empty_strings(self):
t1 = ""
t2 = ""
self.assertEqual(1.0, levsim(t1, t2))
+ @unittest.skipIf(LevenshteinSimilarityIndex is None, "gensim.similarities.levenshtein is disabled")
def test_negative_hyperparameters(self):
t1 = "holiday"
t2 = "day"
@@ -1578,6 +1581,7 @@ def test_negative_hyperparameters(self):
with self.assertRaises(AssertionError):
levsim(t1, t2, -alpha, -beta)
+ @unittest.skipIf(LevenshteinSimilarityIndex is None, "gensim.similarities.levenshtein is disabled")
def test_min_similarity(self):
t1 = "holiday"
t2 = "day"
@@ -1607,9 +1611,9 @@ def setUp(self):
self.documents = [[u"government", u"denied", u"holiday"], [u"holiday", u"slowing", u"hollingworth"]]
self.dictionary = Dictionary(self.documents)
+ @unittest.skipIf(LevenshteinSimilarityIndex is None, "gensim.similarities.levenshtein is disabled")
def test_most_similar(self):
"""Test most_similar returns expected results."""
-
index = LevenshteinSimilarityIndex(self.dictionary)
results = list(index.most_similar(u"holiday", topn=1))
self.assertLess(0, len(results))
diff --git a/setup.py b/setup.py
index 07fd74d2ae..e2a7ac7d28 100644
--- a/setup.py
+++ b/setup.py
@@ -17,9 +17,9 @@
import platform
import shutil
import sys
-from setuptools import setup, find_packages, Extension
-from setuptools.command.build_ext import build_ext
+from setuptools import Extension, find_packages, setup
+from setuptools.command.build_ext import build_ext
c_extensions = {
'gensim.models.word2vec_inner': 'gensim/models/word2vec_inner.c',
@@ -270,15 +270,19 @@ def run(self):
# 'pytest-rerunfailures', # disabled 2020-08-28 for
'mock',
'cython',
- 'nmslib',
- 'pyemd',
'testfixtures',
'Morfessor==2.0.2a4',
- 'python-Levenshtein >= 0.10.2',
]
+if not (sys.platform.lower().startswith("win") and sys.version_info[:2] >= (3, 9)):
+ core_testenv.extend([
+ 'pyemd',
+ 'nmslib',
+ 'python-Levenshtein >= 0.10.2',
+ ])
+
# Add additional requirements for testing on Linux that are skipped on Windows.
-linux_testenv = core_testenv[:] + visdom_req + ['pyemd', ]
+linux_testenv = core_testenv[:] + visdom_req
# Skip problematic/uninstallable packages (& thus related conditional tests) in Windows builds.
# We still test them in Linux via Travis, see linux_testenv above.
@@ -308,7 +312,6 @@ def run(self):
'nltk',
'testfixtures',
'statsmodels',
- 'pyemd',
'pandas',
]
diff --git a/tox.ini b/tox.ini
index f73dedf3d7..12811b8ba5 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,6 +1,6 @@
[tox]
minversion = 2.0
-envlist = {py36,py37,py38}-{win,linux}, flake8, docs, docs-upload, download-wheels, upload-wheels, test-pypi
+envlist = {py36,py37,py38, py39}-{win,linux}, flake8, docs, docs-upload, download-wheels, upload-wheels, test-pypi
skipsdist = True
platform = linux: linux
win: win64