Skip to content

Commit 35e2d21

Browse files
authored
Replace Flake8 with Ruff (#157)
2 parents 5034791 + 478ac1b commit 35e2d21

File tree

14 files changed

+91
-76
lines changed

14 files changed

+91
-76
lines changed

.flake8

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ pre-commit run --all-files # to run on all files now
1313

1414
## Docstrings
1515

16-
Follow [Google style](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings)
16+
Follow
17+
[Google style](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings)
1718
for docstrings.
1819

1920
## Localization

.github/ISSUE_TEMPLATE.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
Please include **code** that reproduces the issue.
1414

15-
The [best reproductions](https://stackoverflow.com/help/minimal-reproducible-example) are [self-contained scripts](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) with minimal dependencies.
15+
The [best reproductions](https://stackoverflow.com/help/minimal-reproducible-example)
16+
are
17+
[self-contained scripts](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)
18+
with minimal dependencies.
1619

1720
```python
1821
code goes here

.github/SECURITY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Security policy
22

3-
Security reports can be made via [Tidelift](https://tidelift.com/security).
4-
Tidelift will coordinate the fix and disclosure.
3+
Security reports can be made via [Tidelift](https://tidelift.com/security). Tidelift
4+
will coordinate the fix and disclosure.

.github/workflows/labels.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
name: Sync labels
2+
3+
permissions:
4+
pull-requests: write
5+
26
on:
37
push:
48
branches:

.github/workflows/lint.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ name: Lint
22

33
on: [push, pull_request, workflow_dispatch]
44

5+
env:
6+
FORCE_COLOR: 1
7+
8+
permissions:
9+
contents: read
10+
511
jobs:
612
lint:
713
runs-on: ubuntu-latest

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ jobs:
2424
allow-prereleases: true
2525
cache: pip
2626

27-
2827
- name: Install Linux dependencies
2928
if: startsWith(matrix.os, 'ubuntu')
3029
run: |

.pre-commit-config.yaml

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,24 @@
11
repos:
2-
- repo: https://github.com/asottile/pyupgrade
3-
rev: v3.14.0
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.1.6
44
hooks:
5-
- id: pyupgrade
6-
args: [--py38-plus]
5+
- id: ruff
6+
args: [--fix, --exit-non-zero-on-fix]
77

88
- repo: https://github.com/psf/black-pre-commit-mirror
9-
rev: 23.9.1
9+
rev: 23.11.0
1010
hooks:
1111
- id: black
1212

13-
- repo: https://github.com/PyCQA/isort
14-
rev: 5.12.0
15-
hooks:
16-
- id: isort
17-
args: [--add-import=from __future__ import annotations]
18-
19-
- repo: https://github.com/PyCQA/autoflake
20-
rev: v2.2.1
21-
hooks:
22-
- id: autoflake
23-
name: autoflake
24-
args:
25-
[
26-
"--in-place",
27-
"--remove-unused-variables",
28-
"--remove-all-unused-imports",
29-
]
30-
language: python
31-
files: \.py$
32-
33-
- repo: https://github.com/PyCQA/flake8
34-
rev: 6.1.0
35-
hooks:
36-
- id: flake8
37-
additional_dependencies:
38-
[flake8-2020, flake8-errmsg, flake8-implicit-str-concat]
39-
40-
- repo: https://github.com/pre-commit/pygrep-hooks
41-
rev: v1.10.0
42-
hooks:
43-
- id: python-check-blanket-noqa
44-
- id: python-no-log-warn
45-
4613
- repo: https://github.com/pre-commit/pre-commit-hooks
47-
rev: v4.4.0
14+
rev: v4.5.0
4815
hooks:
4916
- id: check-case-conflict
5017
- id: check-merge-conflict
5118
- id: check-json
5219
- id: check-toml
5320
- id: check-yaml
21+
- id: debug-statements
5422
- id: end-of-file-fixer
5523
- id: trailing-whitespace
5624
exclude: \.github/ISSUE_TEMPLATE\.md|\.github/PULL_REQUEST_TEMPLATE\.md
@@ -63,20 +31,20 @@ repos:
6331
files: "src/"
6432

6533
- repo: https://github.com/pre-commit/mirrors-mypy
66-
rev: v1.5.1
34+
rev: v1.7.0
6735
hooks:
6836
- id: mypy
6937
additional_dependencies: [pytest, types-freezegun, types-setuptools]
7038
args: [--strict, --pretty, --show-error-codes]
7139

7240
- repo: https://github.com/tox-dev/pyproject-fmt
73-
rev: 1.2.0
41+
rev: 1.5.1
7442
hooks:
7543
- id: pyproject-fmt
7644
additional_dependencies: [tox]
7745

7846
- repo: https://github.com/abravalheri/validate-pyproject
79-
rev: v0.14
47+
rev: v0.15
8048
hooks:
8149
- id: validate-pyproject
8250

@@ -85,5 +53,17 @@ repos:
8553
hooks:
8654
- id: tox-ini-fmt
8755

56+
- repo: https://github.com/pre-commit/mirrors-prettier
57+
rev: v3.1.0
58+
hooks:
59+
- id: prettier
60+
args: [--prose-wrap=always, --print-width=88]
61+
exclude: \.github/ISSUE_TEMPLATE\.md|\.github/PULL_REQUEST_TEMPLATE\.md
62+
63+
- repo: meta
64+
hooks:
65+
- id: check-hooks-apply
66+
- id: check-useless-excludes
67+
8868
ci:
8969
autoupdate_schedule: quarterly

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
[![MIT License](https://img.shields.io/github/license/python-humanize/humanize.svg)](LICENCE)
1010
[![Tidelift](https://tidelift.com/badges/package/pypi/humanize)](https://tidelift.com/subscription/pkg/pypi-humanize?utm_source=pypi-humanize&utm_medium=badge)
1111

12-
This modest package contains various common humanization utilities, like turning
13-
a number into a fuzzy human-readable duration ("3 minutes ago") or into a
14-
human-readable size or throughput. It is localized to:
12+
This modest package contains various common humanization utilities, like turning a
13+
number into a fuzzy human-readable duration ("3 minutes ago") or into a human-readable
14+
size or throughput. It is localized to:
1515

1616
- Arabic
1717
- Basque

RELEASING.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Release Checklist
22

33
- [ ] Get `main` to the appropriate code release state.
4-
[GitHub Actions](https://github.com/python-humanize/humanize/actions) should be running
5-
cleanly for all merges to `main`.
4+
[GitHub Actions](https://github.com/python-humanize/humanize/actions) should be
5+
running cleanly for all merges to `main`.
66
[![GitHub Actions status](https://github.com/python-humanize/humanize/workflows/Test/badge.svg)](https://github.com/python-humanize/humanize/actions)
77

88
* [ ] Start from a freshly cloned repo:
@@ -16,7 +16,7 @@ cd humanize
1616
scripts/generate-translation-binaries.sh
1717
```
1818

19-
* [ ] (Optional) Create a distribution and release on **TestPyPI**:
19+
- [ ] (Optional) Create a distribution and release on **TestPyPI**:
2020

2121
```bash
2222
pip install -U pip build keyring twine
@@ -33,13 +33,13 @@ pip3 install -U -i https://test.pypi.org/simple/ humanize --pre
3333
python3 -c "import humanize; print(humanize.__version__)"
3434
```
3535

36-
* [ ] Tag with the version number:
36+
- [ ] Tag with the version number:
3737

3838
```bash
3939
git tag -a 2.1.0 -m "Release 2.1.0"
4040
```
4141

42-
* [ ] Create a distribution and release on **live PyPI**:
42+
- [ ] Create a distribution and release on **live PyPI**:
4343

4444
```bash
4545
pip install -U pip build keyring twine
@@ -48,21 +48,23 @@ python -m build
4848
twine check --strict dist/* && twine upload --repository pypi dist/*
4949
```
5050

51-
* [ ] Check installation:
51+
- [ ] Check installation:
5252

5353
```bash
5454
pip uninstall -y humanize
5555
pip install -U humanize
5656
python3 -c "import humanize; print(humanize.__version__)"
5757
```
5858

59-
* [ ] Push tag:
60-
```bash
59+
- [ ] Push tag:
60+
61+
```bash
6162
git push --tags
6263
```
6364

64-
* [ ] Edit release draft, adjust text if needed: https://github.com/python-humanize/humanize/releases
65+
- [ ] Edit release draft, adjust text if needed:
66+
https://github.com/python-humanize/humanize/releases
6567

66-
* [ ] Check next tag is correct, amend if needed
68+
- [ ] Check next tag is correct, amend if needed
6769

68-
* [ ] Publish release
70+
- [ ] Publish release

docs/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
Welcome to the humanize API reference.
44

5-
* [Number](number.md)
6-
* [Time](time.md)
7-
* [Filesize](filesize.md)
8-
* [I18n](i18n.md)
5+
- [Number](number.md)
6+
- [Time](time.md)
7+
- [Filesize](filesize.md)
8+
- [I18n](i18n.md)
99

1010
{%
1111
include-markdown "../README.md"

pyproject.toml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,31 @@ artifacts = [
6262
[tool.hatch.version.raw-options]
6363
local_scheme = "no-local-version"
6464

65-
[tool.isort]
66-
profile = "black"
65+
[tool.ruff]
66+
line-length = 88
67+
select = [
68+
"E", # pycodestyle errors
69+
"EM", # flake8-errmsg
70+
"F", # pyflakes errors
71+
"I", # isort
72+
"ISC", # flake8-implicit-str-concat
73+
"PGH", # pygrep-hooks
74+
"RUF100", # unused noqa (yesqa)
75+
"UP", # pyupgrade
76+
"W", # pycodestyle warnings
77+
"YTT", # flake8-2020
78+
# "LOG", # TODO: enable flake8-logging when it's not in preview anymore
79+
]
80+
extend-ignore = [
81+
"E203", # Whitespace before ':'
82+
"E221", # Multiple spaces before operator
83+
"E226", # Missing whitespace around arithmetic operator
84+
"E241", # Multiple spaces after ','
85+
]
86+
87+
[tool.ruff.isort]
88+
required-imports = ["from __future__ import annotations"]
89+
known-first-party = ["humanize"]
6790

6891
[tool.pytest.ini_options]
6992
addopts = "--color=yes"

src/humanize/number.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
from typing import TYPE_CHECKING
99

1010
from .i18n import _gettext as _
11-
from .i18n import _ngettext
11+
from .i18n import _ngettext, decimal_separator, thousands_separator
1212
from .i18n import _ngettext_noop as NS_
1313
from .i18n import _pgettext as P_
14-
from .i18n import decimal_separator, thousands_separator
1514

1615
if TYPE_CHECKING:
1716
if sys.version_info >= (3, 10):

tests/test_number.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,15 @@ def test_fractional(test_input: float | str, expected: str) -> None:
190190
([5781651000], "5.78 x 10⁹"),
191191
(["1000"], "1.00 x 10³"),
192192
(["99"], "9.90 x 10¹"),
193-
([float(0.3)], "3.00 x 10⁻¹"),
193+
([0.3], "3.00 x 10⁻¹"),
194194
(["foo"], "foo"),
195195
([None], "None"),
196196
([1000, 1], "1.0 x 10³"),
197-
([float(0.3), 1], "3.0 x 10⁻¹"),
197+
([0.3, 1], "3.0 x 10⁻¹"),
198198
([1000, 0], "1 x 10³"),
199-
([float(0.3), 0], "3 x 10⁻¹"),
200-
([float(1e20)], "1.00 x 10²⁰"),
201-
([float(2e-20)], "2.00 x 10⁻²⁰"),
199+
([0.3, 0], "3 x 10⁻¹"),
200+
([1e20], "1.00 x 10²⁰"),
201+
([2e-20], "2.00 x 10⁻²⁰"),
202202
([float(-3e20)], "-3.00 x 10²⁰"),
203203
([float(-4e-20)], "-4.00 x 10⁻²⁰"),
204204
([math.nan], "NaN"),

0 commit comments

Comments
 (0)