Skip to content

Commit bc388e0

Browse files
authored
Merge pull request #59 from mideind/modernization
Modernization
2 parents c827bfb + 2f8c75d commit bc388e0

File tree

5 files changed

+98
-102
lines changed

5 files changed

+98
-102
lines changed

.github/workflows/python-package.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
os: [ubuntu-latest]
16-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13.0-rc.1", "pypy-3.9", "pypy-3.10"]
16+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", '3.14.0-beta.4', "pypy-3.9", "pypy-3.10", "pypy-3.11"]
1717

1818
steps:
1919
- uses: actions/checkout@v4
@@ -23,8 +23,12 @@ jobs:
2323
python-version: ${{ matrix.python-version }}
2424
- name: Install GreynirEngine
2525
run: |
26-
python -m pip install --upgrade pip wheel setuptools pytest
27-
python -m pip install -e .
26+
python -m pip install uv
27+
uv pip install --system wheel setuptools pytest ruff
28+
uv pip install --system -e .
29+
- name: Lint with ruff
30+
run: |
31+
ruff check src/reynir
2832
- name: Test with pytest
2933
run: |
3034
python -m pytest

pyproject.toml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0", "cffi>=1.15.1"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "reynir"
7+
version = "3.5.8"
8+
description = "A natural language parser for Icelandic"
9+
authors = [{ name = "Miðeind ehf.", email = "mideind@mideind.is" }]
10+
maintainers = [{ name = "Miðeind ehf.", email = "mideind@mideind.is" }]
11+
readme = { file = "README.md", content-type = "text/markdown" }
12+
license = { text = "MIT License" }
13+
keywords = ["nlp", "parser", "icelandic"]
14+
classifiers = [
15+
# complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers
16+
"Development Status :: 5 - Production/Stable",
17+
"Intended Audience :: Developers",
18+
"Intended Audience :: Science/Research",
19+
"License :: OSI Approved :: MIT License",
20+
"Operating System :: Unix",
21+
"Operating System :: POSIX",
22+
"Operating System :: Microsoft :: Windows",
23+
"Operating System :: MacOS",
24+
"Natural Language :: Icelandic",
25+
"Programming Language :: Python",
26+
"Programming Language :: Python :: 3",
27+
"Programming Language :: Python :: 3.9",
28+
"Programming Language :: Python :: 3.10",
29+
"Programming Language :: Python :: 3.11",
30+
"Programming Language :: Python :: 3.12",
31+
"Programming Language :: Python :: 3.13",
32+
"Programming Language :: Python :: 3.14",
33+
"Programming Language :: Python :: Implementation :: CPython",
34+
"Programming Language :: Python :: Implementation :: PyPy",
35+
"Topic :: Software Development :: Libraries :: Python Modules",
36+
"Topic :: Utilities",
37+
"Topic :: Text Processing :: Linguistic",
38+
]
39+
requires-python = ">=3.9"
40+
dependencies = [
41+
"cffi>=1.17.1",
42+
"tokenizer>=3.5.1",
43+
"islenska>=1.0.4",
44+
"typing_extensions",
45+
]
46+
47+
[project.urls]
48+
Repository = "https://github.com/mideind/GreynirEngine"
49+
Homepage = "https://greynir.is"
50+
Documentation = "https://greynir.is/doc/"
51+
Issues = "https://github.com/mideind/GreynirEngine/issues"
52+
53+
[project.optional-dependencies]
54+
# dev dependencies
55+
dev = ["pytest"]
56+
57+
# *** Configuration of tools ***
58+
59+
[tool.setuptools]
60+
include-package-data = true
61+
62+
[tool.setuptools.packages.find]
63+
where = ["src"]
64+
65+
[tool.setuptools.package-data]
66+
reynir = ["py.typed"]
67+
68+
[tool.ruff]
69+
line-length = 88
70+
71+
[tool.ruff.lint]
72+
#lint.select = ["ALL"] # We use default rules for now
73+
# extend-select = ["E501"] # Complain about line length
74+
# Ignore specific rules
75+
# (we should aim to have these as few as possible)
76+
ignore = [
77+
"E731", # 'E731: Do not assign a lambda expression, use a def'
78+
]
79+
80+
[tool.isort]
81+
# This forces these imports to placed at the top
82+
known_future_library = ["__future__", "typing", "typing_extensions"]
83+
line_length = 88

setup.py

Lines changed: 5 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,14 @@
11
#!/usr/bin/env python3
22
"""
3-
Greynir: Natural language processing for Icelandic
4-
5-
Setup.py
6-
7-
Copyright © 2023 Miðeind ehf.
8-
Original Author: Vilhjálmur Þorsteinsson
9-
10-
This software is licensed under the MIT License:
11-
12-
Permission is hereby granted, free of charge, to any person
13-
obtaining a copy of this software and associated documentation
14-
files (the "Software"), to deal in the Software without restriction,
15-
including without limitation the rights to use, copy, modify, merge,
16-
publish, distribute, sublicense, and/or sell copies of the Software,
17-
and to permit persons to whom the Software is furnished to do so,
18-
subject to the following conditions:
19-
20-
The above copyright notice and this permission notice shall be
21-
included in all copies or substantial portions of the Software.
22-
23-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30-
31-
32-
This module sets up the Greynir package. It uses the cffi_modules
33-
parameter, available in recent versions of setuptools, to
34-
automatically compile the eparser.cpp module to eparser.*.so/.pyd
35-
and build the required CFFI Python wrapper via eparser_build.py.
36-
The same applies to bin.cpp -> bin.*.so and bin_build.py.
37-
38-
Note that installing under PyPy >= 3.9 is supported (and recommended
39-
for best performance).
40-
3+
This file is retained for CFFI compilation.
4+
All package metadata is defined in pyproject.toml.
415
"""
426

43-
from glob import glob
44-
from os.path import basename, splitext
45-
46-
from setuptools import find_packages
47-
from setuptools import setup # type: ignore
48-
49-
50-
with open("README.md", "r", encoding="utf-8") as fh:
51-
long_description = fh.read()
7+
from setuptools import setup
528

9+
# The cffi_modules and zip_safe settings are not yet supported in pyproject.toml
10+
# and must be defined here.
5311
setup(
54-
name="reynir",
55-
version="3.5.7",
56-
license="MIT",
57-
description="A natural language parser for Icelandic",
58-
long_description=long_description,
59-
long_description_content_type="text/markdown",
60-
author="Miðeind ehf",
61-
author_email="mideind@mideind.is",
62-
url="https://github.com/mideind/GreynirEngine",
63-
packages=find_packages("src"),
64-
package_dir={"": "src"},
65-
py_modules=[splitext(basename(path))[0] for path in glob("src/*.py")],
66-
package_data={"reynir": ["py.typed"]},
67-
include_package_data=True,
6812
zip_safe=True,
69-
classifiers=[
70-
# complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers
71-
"Development Status :: 5 - Production/Stable",
72-
"Intended Audience :: Developers",
73-
"Intended Audience :: Science/Research",
74-
"License :: OSI Approved :: MIT License",
75-
"Operating System :: Unix",
76-
"Operating System :: POSIX",
77-
"Operating System :: Microsoft :: Windows",
78-
"Operating System :: MacOS",
79-
"Natural Language :: Icelandic",
80-
"Programming Language :: Python",
81-
"Programming Language :: Python :: 3",
82-
"Programming Language :: Python :: 3.9",
83-
"Programming Language :: Python :: 3.10",
84-
"Programming Language :: Python :: 3.11",
85-
"Programming Language :: Python :: 3.12",
86-
"Programming Language :: Python :: 3.13",
87-
"Programming Language :: Python :: Implementation :: CPython",
88-
"Programming Language :: Python :: Implementation :: PyPy",
89-
"Topic :: Software Development :: Libraries :: Python Modules",
90-
"Topic :: Utilities",
91-
"Topic :: Text Processing :: Linguistic",
92-
],
93-
keywords=["nlp", "parser", "icelandic"],
94-
# Note: cffi 1.15.1 is the version built into PyPy 3.9.
95-
# Do not specify a higher version as that would prevent installation on PyPy 3.9,
96-
# unless you know what you're doing.
97-
setup_requires=["cffi>=1.15.1"],
98-
install_requires=[
99-
"cffi>=1.15.1",
100-
"tokenizer>=3.4.5",
101-
"islenska>=1.0.3",
102-
"typing_extensions",
103-
],
10413
cffi_modules=["src/reynir/eparser_build.py:ffibuilder"],
10514
)

src/reynir/binparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ def match_with_meaning(self, terminal: "BIN_Terminal") -> Union[bool, BIN_Tuple]
15461546

15471547
def matches(self, terminal: Terminal) -> bool:
15481548
"""Return True if this token matches the given terminal"""
1549-
return self.match_with_meaning(cast(BIN_Terminal, terminal)) != False
1549+
return self.match_with_meaning(cast(BIN_Terminal, terminal)) != False # noqa: E712
15501550

15511551
def __repr__(self) -> str:
15521552
return "[" + self.kind + ": " + self.t1 + "]"

src/reynir/grammar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ def apply_to_nonterminals(
10601060
# Found a nonterminal to which this pragma applies
10611061
func(nonterminals[vname], param)
10621062
cnt += 1
1063-
except:
1063+
except Exception:
10641064
raise GrammarError(
10651065
"Invalid pragma argument '{0}'".format(param),
10661066
fname,
@@ -1376,7 +1376,7 @@ def set_score(nt: Nonterminal, score: str) -> None:
13761376
shortcuts: Dict[Nonterminal, Nonterminal] = {}
13771377

13781378
for nt, plist in grammar.items():
1379-
if not "_" in nt.name:
1379+
if "_" not in nt.name:
13801380
# 'Pure' nonterminal with no variants: don't shortcut
13811381
continue
13821382
if self.nt_score(nt) != 0 or nt.has_tags:

0 commit comments

Comments
 (0)