Skip to content

Commit

Permalink
Add py39 wheels to travis/azure (#3058)
Browse files Browse the repository at this point in the history
* Add py39 wheels to travis/azure

* fix nms, pyemd, Levenshtein for py39win

* fix docs gen

* fix some tests for Levenshtein

* fix tests + flake8

* address comments

* manually revert gensim/similarities/levenshtein.py

* add # noqa:F401 to code in __init__

* Update gensim/similarities/__init__.py

Co-authored-by: Michael Penkov <m@penkov.dev>

Co-authored-by: Michael Penkov <m@penkov.dev>
  • Loading branch information
FredHappyface and mpenkov authored Mar 15, 2021
1 parent 1300929 commit aa92604
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,4 +49,4 @@ notifications:
email:
- penkov+gensimwheels@pm.me
on_success: always
on_failure: always
on_failure: always
3 changes: 3 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 # noqa:F401
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 python-Levenshtein`) to suppress this warning."
)
LevenshteinSimilarityIndex = None
else:
from .levenshtein import LevenshteinSimilarityIndex # noqa:F401
from .docsim import ( # noqa:F401
Similarity,
MatrixSimilarity,
Expand All @@ -15,4 +26,3 @@
UniformTermSimilarityIndex,
WordEmbeddingSimilarityIndex,
SparseTermSimilarityMatrix)
from .levenshtein import LevenshteinSimilarityIndex # noqa:F401
6 changes: 5 additions & 1 deletion gensim/test/test_similarities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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))
Expand Down
17 changes: 10 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -270,15 +270,19 @@ def run(self):
# 'pytest-rerunfailures', # disabled 2020-08-28 for <https://github.com/pytest-dev/pytest-rerunfailures/issues/128>
'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.
Expand Down Expand Up @@ -308,7 +312,6 @@ def run(self):
'nltk',
'testfixtures',
'statsmodels',
'pyemd',
'pandas',
]

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit aa92604

Please sign in to comment.