From 27b022a9682f3869b6172a74513cbc5afa64b099 Mon Sep 17 00:00:00 2001 From: Gregor Middell Date: Fri, 27 Sep 2024 13:40:18 +0200 Subject: [PATCH] Code formatting, linting and pre-commit hooks --- .github/workflows/test.yml | 5 ++-- .gitignore | 2 ++ .pre-commit-config.yaml | 30 +++++++++++++++++++++++ COPYING => LICENSE | 8 +++---- MANIFEST.in | 2 +- README.md | 12 +++++++--- VERSION | 2 +- pyproject.toml | 3 +++ requirements-dev.txt | 4 ++++ scripts/release | 19 +++++---------- setup.cfg | 44 +++++++++++++++++++++++++++++++--- setup.py | 49 +++++++++++++------------------------- tests/conftest.py | 4 +--- tests/fixtures.py | 7 +++--- tests/test_transducers.py | 6 ++--- 15 files changed, 129 insertions(+), 68 deletions(-) create mode 100644 .pre-commit-config.yaml rename COPYING => LICENSE (99%) create mode 100644 requirements-dev.txt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 59bad9c..d36297c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,8 +27,9 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip - python -m pip install '.[dev]' + pip install -U pip + pip install -r requirements-dev.txt + pip install . shell: bash - name: Test with pytest diff --git a/.gitignore b/.gitignore index a336ef5..fb65127 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ __pycache__ .python-version .dir-locals.el + +*.temp diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..7b257f6 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,30 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + exclude: ^src/ + - id: end-of-file-fixer + exclude: ^src/ + - id: check-yaml + exclude: ^src/ + - id: check-added-large-files + exclude: ^src/ +- repo: https://github.com/psf/black + rev: 22.10.0 + hooks: + - id: black +- repo: https://github.com/PyCQA/flake8 + rev: 7.0.0 + hooks: + - id: flake8 +- repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.8.0 + hooks: + - id: mypy diff --git a/COPYING b/LICENSE similarity index 99% rename from COPYING rename to LICENSE index 5a965fb..ccfd6fd 100644 --- a/COPYING +++ b/LICENSE @@ -55,7 +55,7 @@ patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. - + GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION @@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions: License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) - + These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in @@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. - + 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is @@ -225,7 +225,7 @@ impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. - + 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License diff --git a/MANIFEST.in b/MANIFEST.in index 368021e..9aa008b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include VERSION COPYING README.md +include VERSION LICENSE README.md graft src graft python graft tests diff --git a/README.md b/README.md index daa19a3..84f5e90 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,11 @@ _Python bindings for SFST focusing on transducer usage_ -[![PyPI](https://img.shields.io/pypi/v/sfst-transduce.svg "PyPI")](https://pypi.org/project/sfst-transduce/) +![PyPI - Version](https://img.shields.io/pypi/v/sfst-transduce) +![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sfst-transduce) +![PyPI - Wheel](https://img.shields.io/pypi/wheel/sfst-transduce) +![GitHub License](https://img.shields.io/github/license/gremid/sfst-transduce) + A Python library providing bindings for the Stuttgart Finite State Transducer system with a focus on the usage of compiled and serialized transducers, @@ -24,7 +28,7 @@ instructions. pip install sfst-transduce ``` -## Usage +## Usage ```python import sfst_transduce @@ -52,7 +56,9 @@ transducer.analyse('easier') ## Development ```bash -rm -rf build ; pip install -e '.[dev]' +pip install -e . +pip install -r requirements-dev.txt +pre-commit install ``` ## Release diff --git a/VERSION b/VERSION index e6d5cb8..6d7de6e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.2 \ No newline at end of file +1.0.2 diff --git a/pyproject.toml b/pyproject.toml index 36adfa7..0c00742 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,3 +8,6 @@ build-backend = "setuptools.build_meta" [tool.cibuildwheel] test-requires = "pytest" test-command = "pytest {project}/tests" + +[tool.isort] +profile = "black" diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..0f41955 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,4 @@ +flake8 +mypy +pre-commit +pytest diff --git a/scripts/release b/scripts/release index 4f0876d..a6a97ac 100755 --- a/scripts/release +++ b/scripts/release @@ -4,22 +4,15 @@ import pathlib import subprocess import sys -project_dir = (pathlib.Path(__file__) / '..' / '..').resolve() +project_dir = (pathlib.Path(__file__) / ".." / "..").resolve() version = sys.argv[1] -(project_dir / 'VERSION').write_text(version) +(project_dir / "VERSION").write_text(version + "\n") +subprocess.check_call(["git", "add", "VERSION"], cwd=project_dir) subprocess.check_call( - ["git", "add", "VERSION"], - cwd=project_dir -) -subprocess.check_call( - ["git", "commit", "-m", f"Updates VERSION: {version}"], - cwd=project_dir -) -subprocess.check_call( - ["git", "tag", version], - cwd=project_dir + ["git", "commit", "-m", f"Updates VERSION: {version}"], cwd=project_dir ) +subprocess.check_call(["git", "tag", version], cwd=project_dir) -# manually push commit and tags +# manually push commit and tags diff --git a/setup.cfg b/setup.cfg index 88ff1a0..14f6bb2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,42 @@ -[flake8] -max_line_length=132 +[metadata] +name = sfst-transduce +version = file: VERSION +author = Gregor Middell +author_email = gregor.middell@bbaw.de +project_urls = + Homepage = https://github.com/gremid/sfst-transduce + Repository = https://github.com/gremid/sfst-transduce.git +description = Python bindings for SFST focusing on transducer usage +long_description = file: README.md, LICENSE +long_description_content_type = text/markdown +license = GNU GPL2 +license_files = LICENSE +keywords = + Finite-state Transducer + Morphological Analysis + Natural Language Processing + NLP + SFST +classifiers = + Development Status :: 5 - Production/Stable + Intended Audience :: Developers + Intended Audience :: Science/Research + License :: OSI Approved :: GNU General Public License v2 (GPLv2) + Operating System :: MacOS + Operating System :: Microsoft :: Windows + Operating System :: POSIX :: Linux + Programming Language :: C++ + Programming Language :: Python + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 + Programming Language :: Python :: Implementation + Programming Language :: Python :: Implementation :: CPython + Programming Language :: Python :: Implementation :: PyPy + Topic :: Education + Topic :: Scientific/Engineering + Topic :: Text Processing :: Linguistic -[tool.pytest] \ No newline at end of file +[options] +python_requires = >=3.6 diff --git a/setup.py b/setup.py index 899787f..1681354 100644 --- a/setup.py +++ b/setup.py @@ -2,39 +2,24 @@ from pybind11.setup_helpers import Pybind11Extension, build_ext from setuptools import setup -__version__ = open('VERSION').read().strip() - setup( - name="sfst-transduce", - version=__version__, - author="Gregor Middell", - author_email="gregor@middell.net", - description="Python bindings for SFST focusing on transducer usage", - long_description=open('README.md').read(), - long_description_content_type="text/markdown", - url="https://github.com/gremid/sfst-transduce", - license="GPLv2", - ext_modules=[Pybind11Extension( - "sfst_transduce", - ["src/basic.cpp", - "src/compact.cpp", - "src/utf8.cpp", - "src/alphabet.cpp", - "src/fst.cpp", - "src/operators.cpp", - "src/determinise.cpp", - "src/hopcroft.cpp", - "python/sfst_transduce.cpp"], - define_macros=[("SFST_VERSION", __version__)] - )], cmdclass={"build_ext": build_ext}, - #package_dir={"": "python"}, + ext_modules=[ + Pybind11Extension( + "sfst_transduce", + [ + "src/basic.cpp", + "src/compact.cpp", + "src/utf8.cpp", + "src/alphabet.cpp", + "src/fst.cpp", + "src/operators.cpp", + "src/determinise.cpp", + "src/hopcroft.cpp", + "python/sfst_transduce.cpp", + ], + define_macros=[("SFST_VERSION", open("VERSION").read().strip())], + ) + ], zip_safe=False, - extras_require={ - 'dev': [ - 'pytest', - 'autoflake', - 'flake8' - ] - } ) diff --git a/tests/conftest.py b/tests/conftest.py index 28c8b9a..b05447a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1 @@ -pytest_plugins = [ - 'tests.fixtures' -] +pytest_plugins = ["tests.fixtures"] diff --git a/tests/fixtures.py b/tests/fixtures.py index 54e7f01..2060fde 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -1,16 +1,17 @@ from pathlib import Path + from pytest import fixture import sfst_transduce -tests_dir = (Path(__file__) / '..').resolve() +tests_dir = (Path(__file__) / "..").resolve() @fixture def transducer(): - return sfst_transduce.Transducer((tests_dir / 'easy.a').as_posix()) + return sfst_transduce.Transducer((tests_dir / "easy.a").as_posix()) @fixture def compact_transducer(): - return sfst_transduce.CompactTransducer((tests_dir / 'easy.ca').as_posix()) + return sfst_transduce.CompactTransducer((tests_dir / "easy.ca").as_posix()) diff --git a/tests/test_transducers.py b/tests/test_transducers.py index ae98f49..73e8d07 100644 --- a/tests/test_transducers.py +++ b/tests/test_transducers.py @@ -5,9 +5,9 @@ def assert_single_result(expected, results): def test_transducer(transducer): - assert_single_result('easy', transducer.analyse('easy')) - assert_single_result('easier', transducer.generate('easy')) + assert_single_result("easy", transducer.analyse("easy")) + assert_single_result("easier", transducer.generate("easy")) def test_compact_transducer(compact_transducer): - assert_single_result('easy', compact_transducer.analyse('easy')) + assert_single_result("easy", compact_transducer.analyse("easy"))