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

Modernize setup and supported versions #118

Merged
merged 7 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: jamspell build and test

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install c++ dependencies
run: |
sudo apt-get install swig4.0 build-essential cmake libgtest-dev -y
- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements_test.txt
mkdir build
cd build
cmake ..
make
ls -l
cd ..
python setup.py install
- name: Test with pytest
run: |
pytest -vv
33 changes: 33 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: jamspell publish

on:
push:
branches:
- main
- master
tags:
- v*

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Verify that git tag matches version
run: python setup.py verify
- name: Install build deps
run: |
pip install -U pip
pip install build --user
- name: Create package
run: python -m build --sdist --wheel --outdir dist/ .
# FIXME: Deploy to pypi
- name: Deploy package to Gemfury
if: startsWith(github.ref, 'refs/tags')
run: |
pip install --user secretstorage twine
python ~/.local/bin/twine upload dist/* --repository-url https://push.fury.io/${{ secrets.FURY_ORGANIZATION }} -u ${{ secrets.FURY_PUSH_TOKEN }} -p ""
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.idea/
*.txt
*.pyc
*.aff
*.dic
Expand All @@ -10,3 +9,10 @@
*.tar.gz
*.spell
*.cache

*.egg-info/
build/
dist/
jamspell.py
*.so
jamspell_wrap.cpp
35 changes: 0 additions & 35 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 2.8.12)
project(jamspell)

option(USE_BOOST_CONVERT "use Boost.Locale instead of std::codecvt for string conversion" OFF)
Expand Down
12 changes: 7 additions & 5 deletions evaluate/evaluate.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import codecs
import random
import argparse
import typo_model
import time
import copy
from utils import normalize, loadText, generateSentences
import utils

try:
import readline
except:
pass

from evaluate import typo_model
from evaluate import utils

from .utils import normalize, loadText, generateSentences



class STATE:
NONE = 0
Expand Down Expand Up @@ -186,7 +188,7 @@ def evaluateCorrector(correctorName, corrector, originalSentences, erroredSenten

def testMode(corrector):
while True:
sentence = raw_input(">> ").lower().strip()
sentence = input(">> ").lower().strip()
sentence = normalize(sentence).split()
if not sentence:
continue
Expand Down
4 changes: 3 additions & 1 deletion evaluate/typo_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

import random
import bisect

from scipy.stats import binom
import utils

from evaluate import utils

# todo: calculate correct typo probabilities

Expand Down
2 changes: 1 addition & 1 deletion jamspell/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

add_library(jamspell_lib spell_corrector.cpp lang_model.cpp utils.cpp perfect_hash.cpp bloom_filter)
add_library(jamspell_lib spell_corrector.cpp lang_model.cpp utils.cpp perfect_hash.cpp bloom_filter.cpp)
target_link_libraries(jamspell_lib phf cityhash)

if(Boost_FOUND)
Expand Down
2 changes: 2 additions & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scipy
pytest
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[metadata]
description-file = README.md
description_file = README.md
19 changes: 11 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import os
import sys
import re
from distutils.command.build import build
from distutils.command.build_ext import build_ext
from setuptools.command.install import install
from distutils.spawn import find_executable
from distutils.version import LooseVersion
from setuptools import setup
from setuptools.extension import Extension
import subprocess
Expand All @@ -26,7 +24,7 @@
os.path.join('jamspell.i'),
],
extra_compile_args=['-std=c++11', '-O2'],
swig_opts=['-c++'],
swig_opts=['-c++', '-py3'],
)

if sys.platform == 'darwin':
Expand All @@ -43,11 +41,11 @@ def run(self):
self.run_command('build_ext')
install.run(self)

class Swig3Ext(build_ext):
class Swig4Ext(build_ext):
def find_swig(self):
swigBinary = find_executable('swig3.0') or find_executable('swig')
swigBinary = find_executable('swig4.0') or find_executable('swig')
assert swigBinary is not None
assert subprocess.check_output([swigBinary, "-version"]).find(b'SWIG Version 3') != -1
assert subprocess.check_output([swigBinary, "-version"]).find(b'SWIG Version 4') != -1
return swigBinary

VERSION = '0.0.12'
Expand All @@ -63,16 +61,21 @@ def find_swig(self):
long_description='context-based spell checker',
keywords=['nlp', 'spell', 'spell-checker', 'jamspell'],
classifiers=[
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'License :: OSI Approved :: MIT License',
],
python_requires='>=3.6',
py_modules=['jamspell'],
ext_modules=[jamspell],
zip_safe=False,
cmdclass={
'build': CustomBuild,
'install': CustomInstall,
'build_ext': Swig3Ext,
'build_ext': Swig4Ext,
},
include_package_data=True,
)
4 changes: 3 additions & 1 deletion test_jamspell.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import pytest
from pytest import approx
import jamspell

from evaluate import generate_dataset
from evaluate.evaluate import evaluateJamspell

Expand Down Expand Up @@ -39,4 +41,4 @@ def test_evaluation(sourceFile, alphabetFile, expected):
generate_dataset.generateDatasetTxt(TEST_DATA + sourceFile, TEMP)
trainLangModel(TEMP_TRAIN, alphabetFile, TEMP_MODEL)
results = evaluateJamspell(TEMP_MODEL, TEMP_TEST, alphabetFile)
assert results == expected
assert results == approx(expected, rel=1)