From 067a70f4232c6db4a99a35b349da2e425fcbd750 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 21 Nov 2023 16:54:28 +0200 Subject: [PATCH] Replace Flake8 with Ruff --- .flake8 | 2 -- .pre-commit-config.yaml | 57 +++++++++++------------------------------ pyproject.toml | 29 +++++++++++++++++++-- src/humanize/number.py | 3 +-- tests/test_number.py | 10 ++++---- 5 files changed, 48 insertions(+), 53 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index f4546ad..0000000 --- a/.flake8 +++ /dev/null @@ -1,2 +0,0 @@ -[flake8] -max_line_length = 88 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bf3a88c..11f5dfc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,56 +1,24 @@ repos: - - repo: https://github.com/asottile/pyupgrade - rev: v3.14.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.6 hooks: - - id: pyupgrade - args: [--py38-plus] + - id: ruff + args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.9.1 + rev: 23.11.0 hooks: - id: black - - repo: https://github.com/PyCQA/isort - rev: 5.12.0 - hooks: - - id: isort - args: [--add-import=from __future__ import annotations] - - - repo: https://github.com/PyCQA/autoflake - rev: v2.2.1 - hooks: - - id: autoflake - name: autoflake - args: - [ - "--in-place", - "--remove-unused-variables", - "--remove-all-unused-imports", - ] - language: python - files: \.py$ - - - repo: https://github.com/PyCQA/flake8 - rev: 6.1.0 - hooks: - - id: flake8 - additional_dependencies: - [flake8-2020, flake8-errmsg, flake8-implicit-str-concat] - - - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.10.0 - hooks: - - id: python-check-blanket-noqa - - id: python-no-log-warn - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-case-conflict - id: check-merge-conflict - id: check-json - id: check-toml - id: check-yaml + - id: debug-statements - id: end-of-file-fixer - id: trailing-whitespace exclude: \.github/ISSUE_TEMPLATE\.md|\.github/PULL_REQUEST_TEMPLATE\.md @@ -63,20 +31,20 @@ repos: files: "src/" - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.5.1 + rev: v1.7.0 hooks: - id: mypy additional_dependencies: [pytest, types-freezegun, types-setuptools] args: [--strict, --pretty, --show-error-codes] - repo: https://github.com/tox-dev/pyproject-fmt - rev: 1.2.0 + rev: 1.5.1 hooks: - id: pyproject-fmt additional_dependencies: [tox] - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.14 + rev: v0.15 hooks: - id: validate-pyproject @@ -85,5 +53,10 @@ repos: hooks: - id: tox-ini-fmt + - repo: meta + hooks: + - id: check-hooks-apply + - id: check-useless-excludes + ci: autoupdate_schedule: quarterly diff --git a/pyproject.toml b/pyproject.toml index 431ef31..f4af183 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,8 +62,33 @@ artifacts = [ [tool.hatch.version.raw-options] local_scheme = "no-local-version" -[tool.isort] -profile = "black" +[tool.ruff] +line-length = 88 +select = [ + "E", # pycodestyle errors + "EM", # flake8-errmsg + "F", # pyflakes errors + "I", # isort + "ISC", # flake8-implicit-str-concat + "PGH", # pygrep-hooks + "RUF100", # unused noqa (yesqa) + "UP", # pyupgrade + "W", # pycodestyle warnings + "YTT", # flake8-2020 + # "LOG", # TODO: enable flake8-logging when it's not in preview anymore +] +extend-ignore = [ + "E203", # Whitespace before ':' + "E221", # Multiple spaces before operator + "E226", # Missing whitespace around arithmetic operator + "E241", # Multiple spaces after ',' +] + +[tool.ruff.isort] +required-imports = ["from __future__ import annotations"] + +[tool.ruff.lint.isort] +known-first-party = ["humanize"] [tool.pytest.ini_options] addopts = "--color=yes" diff --git a/src/humanize/number.py b/src/humanize/number.py index ff0c7e2..9329c28 100644 --- a/src/humanize/number.py +++ b/src/humanize/number.py @@ -8,10 +8,9 @@ from typing import TYPE_CHECKING from .i18n import _gettext as _ -from .i18n import _ngettext +from .i18n import _ngettext, decimal_separator, thousands_separator from .i18n import _ngettext_noop as NS_ from .i18n import _pgettext as P_ -from .i18n import decimal_separator, thousands_separator if TYPE_CHECKING: if sys.version_info >= (3, 10): diff --git a/tests/test_number.py b/tests/test_number.py index bc67785..9bb9475 100644 --- a/tests/test_number.py +++ b/tests/test_number.py @@ -190,15 +190,15 @@ def test_fractional(test_input: float | str, expected: str) -> None: ([5781651000], "5.78 x 10⁹"), (["1000"], "1.00 x 10³"), (["99"], "9.90 x 10¹"), - ([float(0.3)], "3.00 x 10⁻¹"), + ([0.3], "3.00 x 10⁻¹"), (["foo"], "foo"), ([None], "None"), ([1000, 1], "1.0 x 10³"), - ([float(0.3), 1], "3.0 x 10⁻¹"), + ([0.3, 1], "3.0 x 10⁻¹"), ([1000, 0], "1 x 10³"), - ([float(0.3), 0], "3 x 10⁻¹"), - ([float(1e20)], "1.00 x 10²⁰"), - ([float(2e-20)], "2.00 x 10⁻²⁰"), + ([0.3, 0], "3 x 10⁻¹"), + ([1e20], "1.00 x 10²⁰"), + ([2e-20], "2.00 x 10⁻²⁰"), ([float(-3e20)], "-3.00 x 10²⁰"), ([float(-4e-20)], "-4.00 x 10⁻²⁰"), ([math.nan], "NaN"),