Skip to content

Commit cc3e9e3

Browse files
authored
Merge pull request #709 from staticdev/fix/652
Use of Ruff
2 parents 90aef38 + f560a68 commit cc3e9e3

File tree

14 files changed

+246
-115
lines changed

14 files changed

+246
-115
lines changed

.flake8

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

.pre-commit-config.yaml

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
repos:
2-
# Modifiers
3-
- repo: https://github.com/psf/black
4-
rev: 24.10.0
5-
hooks:
6-
- id: black
7-
8-
- repo: https://github.com/pre-commit/mirrors-prettier
9-
rev: v4.0.0-alpha.8
10-
hooks:
11-
- id: prettier
12-
132
- repo: https://github.com/pre-commit/pre-commit-hooks
143
rev: v5.0.0
154
hooks:
@@ -21,27 +10,11 @@ repos:
2110
- id: check-yaml
2211
- id: end-of-file-fixer
2312

24-
- repo: https://github.com/asottile/pyupgrade
25-
rev: v3.19.1
26-
hooks:
27-
- id: pyupgrade
28-
args: [--py39-plus]
29-
30-
- repo: https://github.com/pycqa/isort
31-
rev: 5.13.2
32-
hooks:
33-
- id: isort
34-
args: ["--filter-files"]
35-
36-
- repo: https://github.com/pycqa/flake8
37-
rev: 7.1.1
38-
hooks:
39-
- id: flake8
40-
41-
# Static Checkers
42-
- repo: https://github.com/PyCQA/bandit
43-
rev: 1.7.10
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
# Ruff version.
15+
rev: v0.9.1
4416
hooks:
45-
- id: bandit
46-
additional_dependencies: [".[toml]"]
47-
args: ["-c", "bandit.yml"]
17+
# Run the linter.
18+
- id: ruff
19+
# Run the formatter.
20+
- id: ruff-format

bandit.yml

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

pyproject.toml

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,11 @@ python = ["3.9", "3.10", "3.11", "3.12"]
6161

6262
[tool.hatch.envs.pre-commit]
6363
dependencies = [
64-
"bandit",
65-
"black",
66-
"flake8",
67-
"flake8-bugbear == 22.*",
68-
"flake8-docstrings",
69-
"isort",
70-
"pep8-naming",
64+
"ruff",
7165
"pre-commit",
7266
"pre-commit-hooks",
73-
"pyupgrade",
7467
]
68+
7569
[tool.hatch.envs.pre-commit.scripts]
7670
run = [
7771
"pre-commit run --all-files --show-diff-on-failure",
@@ -92,6 +86,7 @@ dependencies = [
9286
"pytest",
9387
"freezegun",
9488
]
89+
9590
[tool.hatch.envs.mypy.scripts]
9691
run = [
9792
"mypy src/ tests/ docs/conf.py",
@@ -105,6 +100,7 @@ dependencies = [
105100
"pygments",
106101
"freezegun",
107102
]
103+
108104
[tool.hatch.envs.tests.scripts]
109105
run = [
110106
"coverage run --parallel -m pytest"
@@ -114,11 +110,13 @@ run = [
114110
dependencies = [
115111
"coverage[toml]",
116112
]
113+
117114
[tool.hatch.envs.coverage.scripts]
118115
run = [
119116
"- coverage combine",
120117
"coverage report",
121118
]
119+
122120
run-xml = [
123121
"coverage xml"
124122
]
@@ -131,6 +129,7 @@ dependencies = [
131129
"typeguard",
132130
"pygments",
133131
]
132+
134133
[tool.hatch.envs.typeguard.scripts]
135134
run = [
136135
"pytest --typeguard-packages=human_readable",
@@ -140,6 +139,7 @@ run = [
140139
dependencies = [
141140
"xdoctest[colors]",
142141
]
142+
143143
[tool.hatch.envs.xdoctest.scripts]
144144
run = [
145145
"python -m xdoctest human_readable all",
@@ -151,6 +151,7 @@ dependencies = [
151151
"furo",
152152
"myst-parser",
153153
]
154+
154155
[tool.hatch.envs.docs-build.scripts]
155156
run = [
156157
"rm -rf docs/_build",
@@ -164,6 +165,7 @@ dependencies = [
164165
"furo",
165166
"myst-parser",
166167
]
168+
167169
[tool.hatch.envs.docs.scripts]
168170
run = [
169171
"rm -rf docs/_build",
@@ -182,10 +184,20 @@ source = ["human_readable", "tests"]
182184
show_missing = true
183185
fail_under = 100
184186

185-
[tool.isort]
186-
profile = "black"
187-
force_single_line = true
188-
lines_after_imports = 2
187+
[tool.ruff]
188+
line-length = 80
189+
190+
[tool.ruff.lint]
191+
select = ["B", "B9", "C", "D", "E", "F", "N", "W"]
192+
ignore = ["E203", "E501", "B905"]
193+
per-file-ignores = { "times.py" = ["N806"] }
194+
195+
[tool.ruff.lint.mccabe]
196+
max-complexity = 10
197+
198+
[tool.ruff.lint.isort]
199+
force-single-line = true
200+
lines-after-imports = 2
189201

190202
[tool.mypy]
191203
strict = true
@@ -195,7 +207,6 @@ show_column_numbers = true
195207
show_error_codes = true
196208
show_error_context = true
197209

198-
199210
[[tool.mypy.overrides]]
200211
module = ["pytest_mock"]
201212
ignore_missing_imports = true

src/human_readable/files.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,21 @@ def file_size(
2929
3030
Returns:
3131
str: file size in natural language.
32+
3233
"""
3334
if gnu:
3435
suffixes = ("K", "M", "G", "T", "P", "E", "Z", "Y")
3536
elif binary:
36-
suffixes = (" KiB", " MiB", " GiB", " TiB", " PiB", " EiB", " ZiB", " YiB")
37+
suffixes = (
38+
" KiB",
39+
" MiB",
40+
" GiB",
41+
" TiB",
42+
" PiB",
43+
" EiB",
44+
" ZiB",
45+
" YiB",
46+
)
3747
else:
3848
suffixes = (" KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB")
3949

src/human_readable/i18n.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def get_translation() -> gettext_module.NullTranslations:
2929
return _TRANSLATIONS[""]
3030

3131

32-
def activate(locale: str, path: str | None = None) -> gettext_module.NullTranslations:
32+
def activate(
33+
locale: str, path: str | None = None
34+
) -> gettext_module.NullTranslations:
3335
"""Activate internationalisation.
3436
3537
Set `locale` as current locale. Search for locale in directory `path`.
@@ -43,6 +45,7 @@ def activate(locale: str, path: str | None = None) -> gettext_module.NullTransla
4345
4446
Raises:
4547
Exception: If human readable cannot find the locale folder.
48+
4649
"""
4750
if path is None:
4851
path = _get_default_locale_path()
@@ -53,7 +56,9 @@ def activate(locale: str, path: str | None = None) -> gettext_module.NullTransla
5356
"folder. You need to pass the path explicitly."
5457
)
5558
if locale not in _TRANSLATIONS:
56-
translation = gettext_module.translation("human_readable", path, [locale])
59+
translation = gettext_module.translation(
60+
"human_readable", path, [locale]
61+
)
5762
_TRANSLATIONS[locale] = translation
5863
_CURRENT.locale = locale
5964
return _TRANSLATIONS[locale]
@@ -72,6 +77,7 @@ def gettext(message: str) -> str:
7277
7378
Returns:
7479
Translated text.
80+
7581
"""
7682
return get_translation().gettext(message)
7783

@@ -88,6 +94,7 @@ def pgettext(msgctxt: str, message: str) -> str:
8894
8995
Returns:
9096
Translated text.
97+
9198
"""
9299
return get_translation().pgettext(msgctxt, message)
93100

@@ -103,6 +110,7 @@ def ngettext(message: str, plural: str, num: int) -> str:
103110
104111
Returns:
105112
Translated text.
113+
106114
"""
107115
return get_translation().ngettext(message, plural, num)
108116

@@ -120,5 +128,6 @@ def gettext_noop(message: str) -> str:
120128
121129
Returns:
122130
Original text, unchanged.
131+
123132
"""
124133
return message

src/human_readable/lists.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def listing(items: list[str], separator: str, conjunction: str = "") -> str:
1818
1919
Returns:
2020
str: list in natural language.
21+
2122
"""
2223
len_items = len(items)
2324
if len_items == 0:

src/human_readable/numbers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def _thousands_separator() -> str:
2525
2626
Returns:
2727
str: Thousands separator.
28+
2829
"""
2930
try:
3031
sep = _THOUSANDS_SEPARATOR[i18n._CURRENT.locale]
@@ -45,6 +46,7 @@ def ordinal(value: int | str) -> str:
4546
4647
Returns:
4748
str: ordinal string.
49+
4850
"""
4951
suffixes = (
5052
P_("0", "th"),
@@ -76,6 +78,7 @@ def int_comma(value: str | float) -> str:
7678
7779
Returns:
7880
str: formatted number with commas.
81+
7982
"""
8083
sep = _thousands_separator()
8184
if isinstance(value, str):
@@ -123,6 +126,7 @@ def int_word(value: float, formatting: str = ".1f") -> str:
123126
124127
Returns:
125128
str: number formatted with scale words.
129+
126130
"""
127131
if value < POWERS[0]:
128132
return str(value)
@@ -147,6 +151,7 @@ def ap_number(value: float | str) -> str | float:
147151
148152
Returns:
149153
Union[str, float]: spelled 1-9 numbers or original number.
154+
150155
"""
151156
value = int(value)
152157
if not 0 <= value < 10:
@@ -194,6 +199,7 @@ def fractional(value: str | float) -> str:
194199
195200
Returns:
196201
str: human readable number.
202+
197203
"""
198204
number = float(value)
199205
whole_number = int(number)
@@ -233,6 +239,7 @@ def scientific_notation(value: float | str, precision: int = 2) -> str:
233239
234240
Returns:
235241
str: Number in scientific notation z.wq x 10ⁿ.
242+
236243
"""
237244
exponents = {
238245
"0": "⁰",

0 commit comments

Comments
 (0)