diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml new file mode 100644 index 0000000..6a27b21 --- /dev/null +++ b/.github/workflows/build_wheels.yml @@ -0,0 +1,44 @@ +name: Build + +on: [push, pull_request] + +jobs: + build_wheels: + name: Build wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: +# os: [ubuntu-20.04, windows-2019, macos-10.15] + os: [ubuntu-20.04] + + steps: + - uses: actions/checkout@v2 + + - name: Build wheels + uses: pypa/cibuildwheel@v1.12.0 + # to supply options, put them in 'env', like: + env: + CIBW_BEFORE_ALL_LINUX: yum install -y wget + # install something required for the build (you might want to use pyproject.toml instead) + CIBW_BEFORE_BUILD: pip install pybind11 && python setup.py install + - uses: actions/upload-artifact@v2 + with: + path: ./wheelhouse/*.whl + + build_sdist: + name: Build source distribution + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-python@v2 + name: Install Python + with: + python-version: '3.8' + + - name: Build sdist + run: python setup.py sdist + + - uses: actions/upload-artifact@v2 + with: + path: dist/*.tar.gz diff --git a/mecab/mecab.py b/mecab/mecab.py index 02a002e..0ac55c7 100644 --- a/mecab/mecab.py +++ b/mecab/mecab.py @@ -43,14 +43,25 @@ class MeCabError(Exception): pass -class MeCab: # APIs are inspried by KoNLPy - def __init__(self, dicpath=''): - argument = '' +class MeCab: # APIs are inspired by KoNLPy + def __init__(self, dicpath=None, mecabrc_path=None): + arguments = [] - if dicpath != '': - argument = '-d %s' % dicpath + if mecabrc_path: + arguments.append(f"-r {mecabrc_path}") - self.tagger = _mecab.Tagger(argument) + if dicpath: + arguments.append(f"-d {dicpath}") + + arguments_str = " ".join(arguments) + + try: + self.tagger = _mecab.Tagger(arguments_str) + except TypeError as e: + raise ValueError( + "Error loading tagger; try specifying the `dic_path' and/or `mecabrc_path`; " + f"({e})" + ) def parse(self, sentence): lattice = _create_lattice(sentence) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..0443bb9 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel", + "pybind11>=2.0", +] +build-backend = "setuptools.build_meta"