Skip to content

Commit 7c3c09b

Browse files
committed
Use of Ruff
1 parent 90aef38 commit 7c3c09b

12 files changed

+220
-115
lines changed

.flake8

-7
This file was deleted.

.pre-commit-config.yaml

+7-34
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

-2
This file was deleted.

pyproject.toml

+24-13
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

+10-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,16 @@ def file_size(
3333
if gnu:
3434
suffixes = ("K", "M", "G", "T", "P", "E", "Z", "Y")
3535
elif binary:
36-
suffixes = (" KiB", " MiB", " GiB", " TiB", " PiB", " EiB", " ZiB", " YiB")
36+
suffixes = (
37+
" KiB",
38+
" MiB",
39+
" GiB",
40+
" TiB",
41+
" PiB",
42+
" EiB",
43+
" ZiB",
44+
" YiB",
45+
)
3746
else:
3847
suffixes = (" KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB")
3948

src/human_readable/i18n.py

+6-2
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`.
@@ -53,7 +55,9 @@ def activate(locale: str, path: str | None = None) -> gettext_module.NullTransla
5355
"folder. You need to pass the path explicitly."
5456
)
5557
if locale not in _TRANSLATIONS:
56-
translation = gettext_module.translation("human_readable", path, [locale])
58+
translation = gettext_module.translation(
59+
"human_readable", path, [locale]
60+
)
5761
_TRANSLATIONS[locale] = translation
5862
_CURRENT.locale = locale
5963
return _TRANSLATIONS[locale]

0 commit comments

Comments
 (0)