Skip to content

Commit

Permalink
Transition to pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
synesthesiam committed Dec 31, 2024
1 parent 6a84331 commit e26874c
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 64 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.2.0

- Fix use of optional sub part with zero remainder
- Transition to pyproject.toml

## 2.1.0

- Ensure all supported languages can load
Expand Down
2 changes: 0 additions & 2 deletions MANIFEST.in

This file was deleted.

3 changes: 2 additions & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ disable=
missing-class-docstring,
missing-function-docstring,
import-error,
consider-using-with
consider-using-with,
too-many-positional-arguments

[FORMAT]
expected-line-ending-format=LF
41 changes: 41 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[build-system]
requires = ["setuptools>=62.3"]
build-backend = "setuptools.build_meta"

[project]
name = "unicode-rbnf"
version = "2.2.0"
license = {text = "MIT"}
description = "Rule-based number formatting using Unicode CLDR data"
readme = "README.md"
authors = [
{name = "Michael Hansen", email = "[email protected]"}
]
keywords = ["rbnf", "unicode", "number", "format"]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Topic :: Text Processing :: Linguistic",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
requires-python = ">=3.8.0"

[project.urls]
"Source Code" = "https://github.com/rhasspy/unicode-rbnf"

[tool.setuptools]
platforms = ["any"]
zip-safe = true
include-package-data = true

[tool.setuptools.packages.find]
include = ["unicode_rbnf"]

[tool.setuptools.package-data]
unicode_rbnf = ["rbnf/*.xml"]
13 changes: 7 additions & 6 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
black==22.12.0
flake8==6.0.0
isort==5.11.3
mypy==0.991
pylint==2.15.9
pytest==7.4.3
build>=1,<2
black>=24,<25
flake8>=7,<8
isort>=5,<6
mypy>=1,<2
pylint>=3,<4
pytest>=7,<8
2 changes: 1 addition & 1 deletion script/package
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ _VENV_DIR = _PROGRAM_DIR / ".venv"

context = venv.EnvBuilder().ensure_directories(_VENV_DIR)
subprocess.check_call(
[context.env_exe, _PROGRAM_DIR / "setup.py", "sdist", "bdist_wheel"]
[context.env_exe, "-m", "build", "--sdist", "--wheel"]
)
46 changes: 0 additions & 46 deletions setup.py

This file was deleted.

38 changes: 38 additions & 0 deletions tests/test_de.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,46 @@

def test_german():
engine = RbnfEngine.for_language("de")
assert engine.format_number(1).text == "eins"
assert engine.format_number(2).text == "zwei"
assert engine.format_number(3).text == "drei"
assert engine.format_number(4).text == "vier"
assert engine.format_number(5).text == "fünf"
assert engine.format_number(6).text == "sechs"
assert engine.format_number(7).text == "sieben"
assert engine.format_number(8).text == "acht"
assert engine.format_number(9).text == "neun"
assert engine.format_number(10).text == "zehn"
assert engine.format_number(11).text == "elf"
assert engine.format_number(12).text == "zwölf"
assert engine.format_number(13).text == "dreizehn"
assert engine.format_number(14).text == "vierzehn"
assert engine.format_number(15).text == "fünfzehn"
assert engine.format_number(16).text == "sechzehn"
assert engine.format_number(17).text == "siebzehn"
assert engine.format_number(18).text == "achtzehn"
assert engine.format_number(19).text == "neunzehn"
assert engine.format_number(20).text == "zwanzig"
assert engine.format_number(21).text == "einundzwanzig"
assert engine.format_number(22).text == "zweiundzwanzig"
assert engine.format_number(23).text == "dreiundzwanzig"
assert engine.format_number(24).text == "vierundzwanzig"
assert engine.format_number(25).text == "fünfundzwanzig"
assert engine.format_number(26).text == "sechsundzwanzig"
assert engine.format_number(27).text == "siebenundzwanzig"
assert engine.format_number(28).text == "achtundzwanzig"
assert engine.format_number(29).text == "neunundzwanzig"
assert engine.format_number(30).text == "dreißig"
assert engine.format_number(32).text == "zweiunddreißig"
assert engine.format_number(100).text == "einhundert"
assert engine.format_number(101).text == "einhunderteins"
assert engine.format_number(120).text == "einhundertzwanzig"
assert engine.format_number(121).text == "einhunderteinundzwanzig"
assert engine.format_number(200).text == "zweihundert"
assert engine.format_number(1000).text == "eintausend"
assert engine.format_number(1001).text == "eintausendeins"
assert engine.format_number(1100).text == "eintausendeinhundert"
assert engine.format_number(1234).text == "eintausendzweihundertvierunddreißig"

# All genders, cases
assert set(engine.format_number(1).text_by_ruleset.values()) == {
Expand Down
1 change: 1 addition & 0 deletions tests/test_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def test_german():
assert engine.format_number(5).text == "cinco"
assert engine.format_number(2).text == "dos"
assert engine.format_number(5.2).text == "cinco coma dos"
assert engine.format_number(21).text == "veintiuno"

# All genders
assert set(engine.format_number(1).text_by_ruleset.values()) == {
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
env_list =
py{38,39,310,311,312}
py{38,39,310,311,312,313}
minversion = 4.12.1

[testenv]
Expand Down
1 change: 0 additions & 1 deletion unicode_rbnf/VERSION

This file was deleted.

7 changes: 4 additions & 3 deletions unicode_rbnf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from pathlib import Path
"""Rule-based number formatting using Unicode CLDR data."""

import importlib.metadata

from .engine import FormatOptions, FormatPurpose, FormatResult, RbnfEngine

_DIR = Path(__file__).parent
__version__ = importlib.metadata.version("unicode_rbnf")

__version__ = (_DIR / "VERSION").read_text(encoding="utf-8").strip()

__all__ = [
"__version__",
Expand Down
1 change: 1 addition & 0 deletions unicode_rbnf/decimal_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
See: https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classicu_1_1DecimalFormat.html
"""

from decimal import Decimal
from typing import Union

Expand Down
12 changes: 9 additions & 3 deletions unicode_rbnf/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,12 @@ def iter_format_number(
if part.text:
yield part.text
elif isinstance(part, SubRulePart):
if (part.type == SubType.QUOTIENT) and (q > 0):
if (q == 0) and (part.ruleset_name is None):
sub_part: SubRulePart = part

if part.type == SubType.QUOTIENT:
if (q == 0) and (
sub_part.is_optional or (part.ruleset_name is None)
):
# Rulesets can use quotients of zero
continue

Expand All @@ -614,7 +618,9 @@ def iter_format_number(
if part.text_after:
yield part.text_after
elif part.type == SubType.REMAINDER:
if (r == 0) and (part.ruleset_name is None):
if (r == 0) and (
sub_part.is_optional or (part.ruleset_name is None)
):
# Rulesets can use remainders of zero
continue

Expand Down

0 comments on commit e26874c

Please sign in to comment.