From 898d16cb666268780d3427eb6d9f6bcbc7237047 Mon Sep 17 00:00:00 2001 From: Fabio Kepler Date: Fri, 3 Sep 2021 08:37:18 +0100 Subject: [PATCH 1/6] Add Action for building wheel distributions --- .github/workflows/build_wheels.yml | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/build_wheels.yml diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml new file mode 100644 index 0000000..0cde2c9 --- /dev/null +++ b/.github/workflows/build_wheels.yml @@ -0,0 +1,43 @@ +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, macos-10.15] + + steps: + - uses: actions/checkout@v2 + + - name: Build wheels + uses: pypa/cibuildwheel@v1.12.0 + # to supply options, put them in 'env', like: + # env: + # CIBW_SOME_OPTION: value + + - 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 From 83ef2f0cbae0942c3becef733766a45d38981d6b Mon Sep 17 00:00:00 2001 From: Fabio Kepler Date: Fri, 3 Sep 2021 08:44:38 +0100 Subject: [PATCH 2/6] Attempt to install missing pybind11 dep --- .github/workflows/build_wheels.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 0cde2c9..93a983b 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -14,12 +14,15 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Setup requirements + run: pip install -r requirements.txt + - name: Build wheels uses: pypa/cibuildwheel@v1.12.0 # to supply options, put them in 'env', like: - # env: - # CIBW_SOME_OPTION: value - + env: + # install something required for the build (you might want to use pyproject.toml instead) + CIBW_BEFORE_BUILD: pip install pybind11 - uses: actions/upload-artifact@v2 with: path: ./wheelhouse/*.whl From 8ef073680de7b99d126be76721018964ae3f5532 Mon Sep 17 00:00:00 2001 From: Fabio Kepler Date: Fri, 3 Sep 2021 09:46:29 +0100 Subject: [PATCH 3/6] Add setup.py install --- .github/workflows/build_wheels.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 93a983b..d9fe7b7 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -14,15 +14,12 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Setup requirements - run: pip install -r requirements.txt - - name: Build wheels uses: pypa/cibuildwheel@v1.12.0 # to supply options, put them in 'env', like: env: # install something required for the build (you might want to use pyproject.toml instead) - CIBW_BEFORE_BUILD: pip install pybind11 + CIBW_BEFORE_BUILD: pip install pybind11 && python setup.py install - uses: actions/upload-artifact@v2 with: path: ./wheelhouse/*.whl From 32de9597cdad274977433cc46a1d8a56e12255d5 Mon Sep 17 00:00:00 2001 From: Fabio Kepler Date: Fri, 3 Sep 2021 09:53:35 +0100 Subject: [PATCH 4/6] Add pyproject.toml and install wget on build --- .github/workflows/build_wheels.yml | 1 + pyproject.toml | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 pyproject.toml diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index d9fe7b7..e5ddace 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -18,6 +18,7 @@ jobs: 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 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" From 3cbc25188f4165832b1b076644fe3ab8dd07e84d Mon Sep 17 00:00:00 2001 From: Fabio Kepler Date: Fri, 3 Sep 2021 10:38:36 +0100 Subject: [PATCH 5/6] Build wheel only for linux for now --- .github/workflows/build_wheels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index e5ddace..6a27b21 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: # os: [ubuntu-20.04, windows-2019, macos-10.15] - os: [ubuntu-20.04, macos-10.15] + os: [ubuntu-20.04] steps: - uses: actions/checkout@v2 From 28b54dc9a173915fdd8be9ffb9a136114f5cdffe Mon Sep 17 00:00:00 2001 From: Fabio Kepler Date: Wed, 10 Nov 2021 12:43:45 +0000 Subject: [PATCH 6/6] Add support for specifying a mecabrc path --- mecab/mecab.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) 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)