Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add py39 wheels to travis/azure #3058

Merged
merged 10 commits into from
Mar 15, 2021
14 changes: 12 additions & 2 deletions gensim/similarities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
"""

# bring classes directly into package namespace, to save some typing

import warnings
try:
import Levenshtein
except ImportError:
warnings.warn(
"The gensim.similarities.levenshtein submodule is disabled, because the optional "
"Levenshtein package <https://pypi.org/project/python-Levenshtein/> is unavailable. "
"Install Levenhstein (e.g. `pip install Levenshtein`) to suppress this warning."
FredHappyface marked this conversation as resolved.
Show resolved Hide resolved
)
LevenshteinSimilarityIndex = None
else:
from .levenshtein import LevenshteinSimilarityIndex
from .docsim import ( # noqa:F401
Similarity,
MatrixSimilarity,
Expand All @@ -15,4 +26,3 @@
UniformTermSimilarityIndex,
WordEmbeddingSimilarityIndex,
SparseTermSimilarityMatrix)
from .levenshtein import LevenshteinSimilarityIndex # noqa:F401
25 changes: 5 additions & 20 deletions gensim/test/test_similarities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1545,11 +1545,8 @@ 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):
try:
import Levenshtein # noqa:F401
except ImportError as e:
raise unittest.SkipTest("Levenshtein library is not available: %s" % e)
t1 = "holiday"
t2 = "day"
max_distance = max(len(t1), len(t2))
Expand All @@ -1561,21 +1558,15 @@ def test_max_distance(self):


class TestLevenshteinSimilarity(unittest.TestCase):
@unittest.skipIf(LevenshteinSimilarityIndex is None, "gensim.similarities.levenshtein is disabled")
def test_empty_strings(self):
try:
import Levenshtein # noqa:F401
except ImportError as e:
raise unittest.SkipTest("Levenshtein library is not available: %s" % e)
t1 = ""
t2 = ""

self.assertEqual(1.0, levsim(t1, t2))

@unittest.skipIf(LevenshteinSimilarityIndex is None, "gensim.similarities.levenshtein is disabled")
def test_negative_hyperparameters(self):
try:
import Levenshtein # noqa:F401
except ImportError as e:
raise unittest.SkipTest("Levenshtein library is not available: %s" % e)
t1 = "holiday"
t2 = "day"
alpha = 2.0
Expand All @@ -1590,11 +1581,8 @@ 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):
try:
import Levenshtein # noqa:F401
except ImportError as e:
raise unittest.SkipTest("Levenshtein library is not available: %s" % e)
t1 = "holiday"
t2 = "day"
alpha = 2.0
Expand Down Expand Up @@ -1623,12 +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."""
try:
import Levenshtein # noqa:F401
except ImportError as e:
raise unittest.SkipTest("Levenshtein library is not available: %s" % e)
index = LevenshteinSimilarityIndex(self.dictionary)
results = list(index.most_similar(u"holiday", topn=1))
self.assertLess(0, len(results))
Expand Down
19 changes: 9 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,20 @@ def run(self):
'Morfessor==2.0.2a4',
]

not_py39_win_testenv = [
'pyemd',
'nmslib',
'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 + not_py39_win_testenv
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.
# See https://github.com/RaRe-Technologies/gensim/pull/2814
win_testenv = core_testenv[:] + not_py39_win_testenv
if sys.version_info > (3,8,999): # py 3.8.1 is greater than 3.8 so set micro to 999
win_testenv = core_testenv[:]
win_testenv = core_testenv[:]

#
# This list partially duplicates requirements_docs.txt.
Expand All @@ -301,7 +300,7 @@ def run(self):
# https://packaging.python.org/discussions/install-requires-vs-requirements/
#

docs_testenv = core_testenv + not_py39_win_testenv + distributed_env + visdom_req + [
docs_testenv = core_testenv + distributed_env + visdom_req + [
'sphinx <= 2.4.4', # avoid `sphinx >= 3.0` that breaks the build
'sphinx-gallery',
'sphinxcontrib.programoutput',
Expand Down