Skip to content

Commit

Permalink
Code formatting, linting and pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
gremid committed Sep 27, 2024
1 parent b1b8397 commit 27b022a
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 68 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ __pycache__

.python-version
.dir-locals.el

*.temp
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions COPYING → LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include VERSION COPYING README.md
include VERSION LICENSE README.md
graft src
graft python
graft tests
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -24,7 +28,7 @@ instructions.
pip install sfst-transduce
```

## Usage
## Usage

```python
import sfst_transduce
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.2
1.0.2
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ build-backend = "setuptools.build_meta"
[tool.cibuildwheel]
test-requires = "pytest"
test-command = "pytest {project}/tests"

[tool.isort]
profile = "black"
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
flake8
mypy
pre-commit
pytest
19 changes: 6 additions & 13 deletions scripts/release
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 41 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
[flake8]
max_line_length=132
[metadata]
name = sfst-transduce
version = file: VERSION
author = Gregor Middell
author_email = [email protected]
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]
[options]
python_requires = >=3.6
49 changes: 17 additions & 32 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
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'
]
}
)
4 changes: 1 addition & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
pytest_plugins = [
'tests.fixtures'
]
pytest_plugins = ["tests.fixtures"]
7 changes: 4 additions & 3 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
@@ -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())
6 changes: 3 additions & 3 deletions tests/test_transducers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ def assert_single_result(expected, results):


def test_transducer(transducer):
assert_single_result('easy<ADJ><pos>', transducer.analyse('easy'))
assert_single_result('easier', transducer.generate('easy<ADJ><comp>'))
assert_single_result("easy<ADJ><pos>", transducer.analyse("easy"))
assert_single_result("easier", transducer.generate("easy<ADJ><comp>"))


def test_compact_transducer(compact_transducer):
assert_single_result('easy<ADJ><pos>', compact_transducer.analyse('easy'))
assert_single_result("easy<ADJ><pos>", compact_transducer.analyse("easy"))

0 comments on commit 27b022a

Please sign in to comment.