From df2857fff3c492692ca09f31699972970042bc07 Mon Sep 17 00:00:00 2001 From: Michael Karcher Date: Wed, 12 Jun 2024 22:42:45 +0200 Subject: [PATCH 01/14] Define _POSIX_C_SOURCE for crfsuite source files gcc-14 has "-Werror=implicit-function-declaration" enabled by default. crfsuite uses posix_memalign which only gets defined when _POSIX_C_SOURCE is defined, so make sure the flag is set when compiling crfsuite. On the other hand, openSUSE Tumbleweed has _POSIX_C_SOURCE defined in pyconfig.h, so you must not add "-D_POSIX_C_SOURCE" when compiling the python binding source code. So add it only for the subdir crfsuite. --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 8036363..f0dc370 100755 --- a/setup.py +++ b/setup.py @@ -30,6 +30,7 @@ def build_extensions(self): _compile = c._compile def c_compile(obj, src, ext, cc_args, extra_postargs, pp_opts): + cc_args = cc_args + ['-D_POSIX_C_SOURCE=200112L'] if src.startswith('crfsuite/') else cc_args cc_args = cc_args + ['-std=c99'] if src.endswith('.c') else cc_args return _compile(obj, src, ext, cc_args, extra_postargs, pp_opts) From 4bf558bda40b0ead78841e11d5fed61c7cf022d9 Mon Sep 17 00:00:00 2001 From: Michael Karcher Date: Wed, 12 Jun 2024 22:37:03 +0200 Subject: [PATCH 02/14] Use gcc-specific _compile method for triplet-gcc as well On debian bookworm, distutils invokes gcc as x86_64-linux-gnu-gcc, so allow command line elements ending in "-gcc" as well as command line elements being exactly "gcc". --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8036363..58a5d2c 100755 --- a/setup.py +++ b/setup.py @@ -33,7 +33,8 @@ def c_compile(obj, src, ext, cc_args, extra_postargs, pp_opts): cc_args = cc_args + ['-std=c99'] if src.endswith('.c') else cc_args return _compile(obj, src, ext, cc_args, extra_postargs, pp_opts) - if c.compiler_type == 'unix' and 'gcc' in c.compiler: + if c.compiler_type == 'unix' and \ + any(item == 'gcc' or item.endswith("-gcc") for item in c.compiler): c._compile = c_compile elif self.compiler.compiler_type == "msvc": From a69cb077c62f255919fc4b393cfa077a6f5b4c58 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2024 22:11:32 +0000 Subject: [PATCH 03/14] Bump actions/download-artifact Bumps the github_actions group with 1 update in the /.github/workflows directory: [actions/download-artifact](https://github.com/actions/download-artifact). Updates `actions/download-artifact` from 3 to 4.1.7 - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v3...v4.1.7) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-type: direct:production dependency-group: github_actions ... Signed-off-by: dependabot[bot] --- .github/workflows/build_and_upload.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_upload.yml b/.github/workflows/build_and_upload.yml index 330db85..5036240 100644 --- a/.github/workflows/build_and_upload.yml +++ b/.github/workflows/build_and_upload.yml @@ -56,7 +56,7 @@ jobs: - build_wheels - make_sdist steps: - - uses: "actions/download-artifact@v3" + - uses: "actions/download-artifact@v4.1.7" with: name: artifact path: dist From 414c8263aa43cff66fde54ebc3d909d95b0960ec Mon Sep 17 00:00:00 2001 From: Forest Gregg Date: Thu, 26 Sep 2024 16:59:18 -0400 Subject: [PATCH 04/14] Update build_and_upload.yml --- .github/workflows/build_and_upload.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_upload.yml b/.github/workflows/build_and_upload.yml index 5036240..90d2ab8 100644 --- a/.github/workflows/build_and_upload.yml +++ b/.github/workflows/build_and_upload.yml @@ -20,7 +20,7 @@ jobs: with: submodules: true - name: "Build wheels" - uses: "pypa/cibuildwheel@v2.16.2" + uses: "pypa/cibuildwheel@v2.21.1" env: CIBW_SKIP: "pp*" # FIXME CIBW_BEFORE_BUILD: "pip install -U cython && ./update_cpp.sh" From 4db469a6bee76df4883eeddd90bbc6ec75eda7e0 Mon Sep 17 00:00:00 2001 From: Forest Gregg Date: Mon, 30 Sep 2024 13:41:21 -0400 Subject: [PATCH 05/14] build linux aarch64 wheels, closes #162 --- .github/workflows/build_and_upload.yml | 1 + setup.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_and_upload.yml b/.github/workflows/build_and_upload.yml index b161e24..85ff6d0 100644 --- a/.github/workflows/build_and_upload.yml +++ b/.github/workflows/build_and_upload.yml @@ -23,6 +23,7 @@ jobs: uses: "pypa/cibuildwheel@v2.21.1" env: CIBW_SKIP: "pp*" # FIXME + CIBW_ARCHS_LINUX: "auto aarch64" CIBW_TEST_REQUIRES: "pytest" CIBW_TEST_COMMAND: "pytest {project}/tests --doctest-modules" - uses: "actions/upload-artifact@v3" diff --git a/setup.py b/setup.py index 0f15c5d..ca958c4 100755 --- a/setup.py +++ b/setup.py @@ -6,8 +6,7 @@ from Cython.Build import cythonize from setuptools import Extension, setup -sources = ["pycrfsuite/_pycrfsuite.pyx", - "pycrfsuite/trainer_wrapper.cpp"] +sources = ["pycrfsuite/_pycrfsuite.pyx", "pycrfsuite/trainer_wrapper.cpp"] # crfsuite sources += glob.glob("crfsuite/lib/crf/src/*.c") @@ -34,12 +33,17 @@ def build_extensions(self): _compile = c._compile def c_compile(obj, src, ext, cc_args, extra_postargs, pp_opts): - cc_args = cc_args + ["-D_POSIX_C_SOURCE=200112L"] if src.startswith("crfsuite/") else cc_args + cc_args = ( + cc_args + ["-D_POSIX_C_SOURCE=200112L"] + if src.startswith("crfsuite/") + else cc_args + ) cc_args = cc_args + ["-std=c99"] if src.endswith(".c") else cc_args return _compile(obj, src, ext, cc_args, extra_postargs, pp_opts) - if c.compiler_type == "unix" and \ - any(item == "gcc" or item.endswith("-gcc") for item in c.compiler): + if c.compiler_type == "unix" and any( + item == "gcc" or item.endswith("-gcc") for item in c.compiler + ): c._compile = c_compile elif self.compiler.compiler_type == "msvc": @@ -60,5 +64,5 @@ def c_compile(obj, src, ext, cc_args, extra_postargs, pp_opts): ) ] ), - cmdclass={"build_ext": build_ext_check_gcc} + cmdclass={"build_ext": build_ext_check_gcc}, ) From 75c3081f6a4b98d99c236598d9638dce299f7a05 Mon Sep 17 00:00:00 2001 From: Elijah Rippeth Date: Tue, 21 Jul 2020 21:57:26 -0400 Subject: [PATCH 06/14] add broken tests. --- tests/conftest.py | 19 +++++-------------- tests/test_tagger.py | 17 ++++++----------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 446b357..4782cc5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,25 +12,16 @@ def xseq(): {"clean": 1, "shop": 0.1}, {"walk": 1, "shop": 0.5}, {}, - {"clean": 1}, - {"солнце": "не светит".encode(), "clean": 1}, + {'clean': 1}, + {u'солнце': u'не светит'.encode('utf8'), 'clean': 1}, + {'world': 2} ] @pytest.fixture def yseq(): - return [ - "sunny", - "sunny", - "sunny", - "rainy", - "rainy", - "rainy", - "sunny", - "sunny", - "rainy", - "rainy", - ] + return ['sunny', 'sunny', u'sunny', 'rainy', 'rainy', 'rainy', + 'sunny', 'sunny', 'rainy', 'rainy', '好'] @pytest.fixture diff --git a/tests/test_tagger.py b/tests/test_tagger.py index 40c0218..4abcfc5 100644 --- a/tests/test_tagger.py +++ b/tests/test_tagger.py @@ -171,17 +171,12 @@ def test_info(model_filename): with Tagger().open(model_filename) as tagger: res = tagger.info() - assert res.transitions[("sunny", "sunny")] > res.transitions[("sunny", "rainy")] - assert ( - res.state_features[("walk", "sunny")] - > res.state_features[("walk", "rainy")] - ) - assert ("солнце:не светит", "rainy") in res.state_features - assert res.header["num_labels"] == "2" - assert set(res.labels.keys()) == {"sunny", "rainy"} - assert set(res.attributes.keys()) == { - "shop", "walk", "clean", "солнце:не светит" - } + assert res.transitions[('sunny', 'sunny')] > res.transitions[('sunny', 'rainy')] + assert res.state_features[('walk', 'sunny')] > res.state_features[('walk', 'rainy')] + assert (u'солнце:не светит', u'rainy') in res.state_features + assert res.header['num_labels'] == '3' + assert set(res.labels.keys()) == set(['sunny', 'rainy', '好']) + assert set(res.attributes.keys()) == set(['shop', 'walk', 'clean', u'солнце:не светит', 'world']) # it shouldn't segfault on a closed tagger with pytest.raises(RuntimeError): From 4014eb0244af8bdfbe58662e95acd7fb50bdb1e5 Mon Sep 17 00:00:00 2001 From: Elijah Rippeth Date: Tue, 21 Jul 2020 22:07:22 -0400 Subject: [PATCH 07/14] make default string encoding utf-8 to handle non-ascii X's and y's --- pycrfsuite/_pycrfsuite.pyx | 2 +- tests/conftest.py | 21 ++++++++++++++++----- tests/test_tagger.py | 31 ++++++++++++++++++------------- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/pycrfsuite/_pycrfsuite.pyx b/pycrfsuite/_pycrfsuite.pyx index 09cc379..647f203 100644 --- a/pycrfsuite/_pycrfsuite.pyx +++ b/pycrfsuite/_pycrfsuite.pyx @@ -1,6 +1,6 @@ # cython: embedsignature=True # cython: c_string_type=str -# cython: c_string_encoding=ascii +# cython: c_string_encoding=utf-8 # cython: profile=False # distutils: language=c++ from . cimport crfsuite_api diff --git a/tests/conftest.py b/tests/conftest.py index 4782cc5..60a19d7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,16 +12,27 @@ def xseq(): {"clean": 1, "shop": 0.1}, {"walk": 1, "shop": 0.5}, {}, - {'clean': 1}, - {u'солнце': u'не светит'.encode('utf8'), 'clean': 1}, - {'world': 2} + {"clean": 1}, + {"солнце": "не светит".encode(), "clean": 1}, + {"world": 2}, ] @pytest.fixture def yseq(): - return ['sunny', 'sunny', u'sunny', 'rainy', 'rainy', 'rainy', - 'sunny', 'sunny', 'rainy', 'rainy', '好'] + return [ + "sunny", + "sunny", + "sunny", + "rainy", + "rainy", + "rainy", + "sunny", + "sunny", + "rainy", + "rainy", + "好", + ] @pytest.fixture diff --git a/tests/test_tagger.py b/tests/test_tagger.py index 4abcfc5..3ebb021 100644 --- a/tests/test_tagger.py +++ b/tests/test_tagger.py @@ -171,12 +171,17 @@ def test_info(model_filename): with Tagger().open(model_filename) as tagger: res = tagger.info() - assert res.transitions[('sunny', 'sunny')] > res.transitions[('sunny', 'rainy')] - assert res.state_features[('walk', 'sunny')] > res.state_features[('walk', 'rainy')] - assert (u'солнце:не светит', u'rainy') in res.state_features - assert res.header['num_labels'] == '3' - assert set(res.labels.keys()) == set(['sunny', 'rainy', '好']) - assert set(res.attributes.keys()) == set(['shop', 'walk', 'clean', u'солнце:не светит', 'world']) + assert res.transitions[("sunny", "sunny")] > res.transitions[("sunny", "rainy")] + assert ( + res.state_features[("walk", "sunny")] + > res.state_features[("walk", "rainy")] + ) + assert ("солнце:не светит", "rainy") in res.state_features + assert res.header["num_labels"] == "3" + assert set(res.labels.keys()) == set(["sunny", "rainy", "好"]) + assert set(res.attributes.keys()) == set( + ["shop", "walk", "clean", "солнце:не светит", "world"] + ) # it shouldn't segfault on a closed tagger with pytest.raises(RuntimeError): @@ -222,13 +227,13 @@ def test_append_nested_dicts(tmpdir): with Tagger().open(model_filename) as tagger: info = tagger.info() assert set(info.attributes.keys()) == { - "foo:bar:baz", - "foo:spam", - "foo:egg:x", - "foo:egg:y", - "foo:ham:x", - "foo:ham:y", - "foo:bar:ham", + "foo:bar:baz", + "foo:spam", + "foo:egg:x", + "foo:egg:y", + "foo:ham:x", + "foo:ham:y", + "foo:bar:ham", } for feat in ["foo:bar:baz", "foo:spam", "foo:egg:x", "foo:egg:y"]: From 248699ee15f23d006644dd63dc240b31776feae2 Mon Sep 17 00:00:00 2001 From: Forest Gregg Date: Mon, 30 Sep 2024 14:08:54 -0400 Subject: [PATCH 08/14] set up quemu --- .github/workflows/build_and_upload.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build_and_upload.yml b/.github/workflows/build_and_upload.yml index 85ff6d0..5ba6dda 100644 --- a/.github/workflows/build_and_upload.yml +++ b/.github/workflows/build_and_upload.yml @@ -19,6 +19,11 @@ jobs: - uses: "actions/checkout@v4" with: submodules: true + - name: "Set up QEMU" + if: matrix.os == 'ubuntu-latest' + uses: "docker/setup-qemu-action@v3" + with: + platforms: arm64 - name: "Build wheels" uses: "pypa/cibuildwheel@v2.21.1" env: From 77b47177ee7f6ef8d17762737fbfaa7fcd1bc52a Mon Sep 17 00:00:00 2001 From: Forest Gregg Date: Mon, 30 Sep 2024 16:32:49 -0400 Subject: [PATCH 09/14] bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 73c0598..b2dee39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "python-crfsuite" -version = "0.9.10" +version = "0.9.11" description = "Python binding for CRFsuite" authors = [ {name = "Terry Peng", email = "pengtaoo@gmail.com"}, From 0ca329233e5f6e29a4359481584ca5e433945403 Mon Sep 17 00:00:00 2001 From: Forest Gregg Date: Tue, 1 Oct 2024 09:28:07 -0400 Subject: [PATCH 10/14] compatible upload and download artifacts? --- .github/workflows/build_and_upload.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_and_upload.yml b/.github/workflows/build_and_upload.yml index 5ba6dda..7d81619 100644 --- a/.github/workflows/build_and_upload.yml +++ b/.github/workflows/build_and_upload.yml @@ -31,10 +31,10 @@ jobs: CIBW_ARCHS_LINUX: "auto aarch64" CIBW_TEST_REQUIRES: "pytest" CIBW_TEST_COMMAND: "pytest {project}/tests --doctest-modules" - - uses: "actions/upload-artifact@v3" + - uses: "actions/upload-artifact@v4" with: path: "./wheelhouse/*.whl" - + make_sdist: name: "Build source distribution" runs-on: ubuntu-latest @@ -44,7 +44,7 @@ jobs: submodules: true - name: "Build source distribution" run: "pipx run build --sdist" - - uses: "actions/upload-artifact@v3" + - uses: "actions/upload-artifact@v4" with: path: "./dist/*.tar.gz" @@ -56,7 +56,7 @@ jobs: - build_wheels - make_sdist steps: - - uses: "actions/download-artifact@v4.1.7" + - uses: "actions/download-artifact@v4" with: name: artifact path: dist From a1df05623bf11f1f4e9ffd34bf9f7608d48eb944 Mon Sep 17 00:00:00 2001 From: Forest Gregg Date: Tue, 1 Oct 2024 11:08:20 -0400 Subject: [PATCH 11/14] overwrite --- .github/workflows/build_and_upload.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build_and_upload.yml b/.github/workflows/build_and_upload.yml index 7d81619..ad40e14 100644 --- a/.github/workflows/build_and_upload.yml +++ b/.github/workflows/build_and_upload.yml @@ -34,6 +34,7 @@ jobs: - uses: "actions/upload-artifact@v4" with: path: "./wheelhouse/*.whl" + overwrite: true make_sdist: name: "Build source distribution" @@ -47,6 +48,7 @@ jobs: - uses: "actions/upload-artifact@v4" with: path: "./dist/*.tar.gz" + overwrite: true upload_to_pypi: name: "Upload to PyPI" From 1b2865b632a28797602c46c05171c47131b1782a Mon Sep 17 00:00:00 2001 From: Forest Gregg Date: Tue, 1 Oct 2024 11:45:14 -0400 Subject: [PATCH 12/14] upload and download upgrades --- .github/workflows/build_and_upload.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_and_upload.yml b/.github/workflows/build_and_upload.yml index ad40e14..f1724f6 100644 --- a/.github/workflows/build_and_upload.yml +++ b/.github/workflows/build_and_upload.yml @@ -34,7 +34,7 @@ jobs: - uses: "actions/upload-artifact@v4" with: path: "./wheelhouse/*.whl" - overwrite: true + name: wheel-%{{ matrix.os }} make_sdist: name: "Build source distribution" @@ -48,7 +48,7 @@ jobs: - uses: "actions/upload-artifact@v4" with: path: "./dist/*.tar.gz" - overwrite: true + name: sdist upload_to_pypi: name: "Upload to PyPI" @@ -60,8 +60,8 @@ jobs: steps: - uses: "actions/download-artifact@v4" with: - name: artifact path: dist + merge-multiple: true - uses: "pypa/gh-action-pypi-publish@v1.8.10" with: user: __token__ From e81d4fa33ecfc39053085abe0f1dcb754e13cd70 Mon Sep 17 00:00:00 2001 From: Forest Gregg Date: Tue, 1 Oct 2024 11:52:35 -0400 Subject: [PATCH 13/14] typo --- .github/workflows/build_and_upload.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_upload.yml b/.github/workflows/build_and_upload.yml index f1724f6..45edc09 100644 --- a/.github/workflows/build_and_upload.yml +++ b/.github/workflows/build_and_upload.yml @@ -34,7 +34,7 @@ jobs: - uses: "actions/upload-artifact@v4" with: path: "./wheelhouse/*.whl" - name: wheel-%{{ matrix.os }} + name: wheel-${{ matrix.os }} make_sdist: name: "Build source distribution" From 3b3de4bc62356b2fffd560db823162fcf7365e26 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 5 Sep 2025 10:06:10 +0200 Subject: [PATCH 14/14] Bump pypa/gh-action-pypi-publish (#166) Bumps the github_actions group with 1 update in the /.github/workflows directory: [pypa/gh-action-pypi-publish](https://github.com/pypa/gh-action-pypi-publish). Updates `pypa/gh-action-pypi-publish` from 1.8.10 to 1.13.0 - [Release notes](https://github.com/pypa/gh-action-pypi-publish/releases) - [Commits](https://github.com/pypa/gh-action-pypi-publish/compare/v1.8.10...v1.13.0) --- updated-dependencies: - dependency-name: pypa/gh-action-pypi-publish dependency-version: 1.13.0 dependency-type: direct:production dependency-group: github_actions ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/build_and_upload.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_upload.yml b/.github/workflows/build_and_upload.yml index 45edc09..a8b2f3d 100644 --- a/.github/workflows/build_and_upload.yml +++ b/.github/workflows/build_and_upload.yml @@ -62,7 +62,7 @@ jobs: with: path: dist merge-multiple: true - - uses: "pypa/gh-action-pypi-publish@v1.8.10" + - uses: "pypa/gh-action-pypi-publish@v1.13.0" with: user: __token__ password: ${{ secrets.PYPI_TOKEN }}