Skip to content

Commit b2bbfb7

Browse files
authored
Switch to ruff (#129)
1 parent 9a1eed6 commit b2bbfb7

File tree

9 files changed

+57
-52
lines changed

9 files changed

+57
-52
lines changed

.pre-commit-config.yaml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@ repos:
99
- id: check-docstring-first
1010
- id: end-of-file-fixer
1111
- id: trailing-whitespace
12-
- repo: https://github.com/PyCQA/isort
13-
rev: 6.0.1
12+
- repo: https://github.com/PyCQA/docformatter
13+
rev: v1.7.7
1414
hooks:
15-
- id: isort
16-
additional_dependencies: [toml]
17-
- repo: https://github.com/asottile/pyupgrade
18-
rev: v3.20.0
15+
- id: docformatter
16+
args: [--in-place, --black]
17+
- repo: https://github.com/astral-sh/ruff-pre-commit
18+
rev: v0.12.4
1919
hooks:
20-
- id: pyupgrade
21-
args: [--py38-plus]
22-
- repo: https://github.com/psf/black-pre-commit-mirror
23-
rev: 25.1.0
20+
- id: ruff-format
21+
- id: ruff-check
22+
args: [ --fix ]
23+
- repo: https://github.com/codespell-project/codespell
24+
rev: v2.4.1
2425
hooks:
25-
- id: black
26-
- repo: https://github.com/PyCQA/flake8
27-
rev: 7.3.0
28-
hooks:
29-
- id: flake8
26+
- id: codespell
27+
# remove toml extra once Python 3.10 is no longer supported
28+
additional_dependencies: ['.[toml]']

pth-tester/pth_tester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
has_socket = False
33

44

5-
# The pth_tester module should be initalized by processing the `.pth` file
5+
# The pth_tester module should be initialized by processing the `.pth` file
66
# created on installation.
77
def init():
88
global initialized

pth-tester/setup.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
# Copied from setuptools:
88
# (https://github.com/pypa/setuptools/blob/7c859e017368360ba66c8cc591279d8964c031bc/setup.py#L40C6-L82)
99
class install_with_pth(install):
10-
"""
11-
Custom install command to install a .pth file.
10+
"""Custom install command to install a .pth file.
1211
1312
This hack is necessary because there's no standard way to install behavior
1413
on startup (and it's debatable if there should be one). This hack (ab)uses
@@ -30,9 +29,7 @@ def finalize_options(self):
3029
self._restore_install_lib()
3130

3231
def _restore_install_lib(self):
33-
"""
34-
Undo secondary effect of `extra_path` adding to `install_lib`
35-
"""
32+
"""Undo secondary effect of `extra_path` adding to `install_lib`"""
3633
suffix = os.path.relpath(self.install_lib, self.install_libbase)
3734

3835
if suffix.strip() == self._pth_contents.strip():

pyproject.toml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ requires = [
3131
(platform_system != 'iOS' and platform_system != 'Android' and python_version < '3.14') \
3232
or (platform_system == 'iOS' and python_version < '3.14') \
3333
or (platform_system == 'Android' and python_version < '3.14')""",
34-
# pillow not available anywhere on 3.14
35-
"""pillow; \
34+
# pillow not available anywhere on 3.14. 11.3.0 wheel is known bad on iOS.
35+
"""pillow != 11.3.0; \
3636
(platform_system != 'iOS' and platform_system != 'Android' and python_version < '3.14') \
3737
or (platform_system == 'iOS' and python_version < '3.14') \
3838
or (platform_system == 'Android' and python_version < '3.14')""",
@@ -108,7 +108,7 @@ flatpak_sdk = "org.gnome.Sdk"
108108

109109
[tool.briefcase.app.testbed.windows]
110110
requires = [
111-
# Python.net isn't avaialble for 3.14 yet.
111+
# Python.net isn't available for 3.14 yet.
112112
"pythonnet>=3.0.0; python_version < '3.14'",
113113
# Windows doesn't provide the zoneinfo TZ database; use the Python provided one
114114
"tzdata",
@@ -143,7 +143,20 @@ build_gradle_dependencies = [
143143

144144
# template = "../../templates/briefcase-android-gradle-template"
145145

146-
[tool.isort]
147-
profile = "black"
148-
split_on_trailing_comma = true
149-
combine_as_imports = true
146+
[tool.ruff.lint]
147+
# In addition to the default rules, these additional rules will be used:
148+
extend-select = [
149+
"E", # pycodestyle
150+
"W", # pycodestyle
151+
"F", # pyflakes
152+
"UP", # pyupgrade
153+
"B", # flake8-bugbear
154+
"YTT", # flake8-2020
155+
"ASYNC", # flake8-async
156+
"C4", # flake8-comprehensions
157+
"I", # isort
158+
# The SIM rules are *very* opinionated, and don't necessarily make for better code.
159+
# They may be worth occasionally turning on just to see if something could actually
160+
# use improvement.
161+
# "SIM", # flake8-simplify
162+
]

setup.cfg

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

tests/test_common.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def test_bootstrap_modules():
5151
except ModuleNotFoundError:
5252
missing.append(module)
5353

54-
assert (
55-
len(missing) == 0
56-
), f"Missing bootstrap modules: {', '.join(str(m) for m in missing)}"
54+
assert len(missing) == 0, (
55+
f"Missing bootstrap modules: {', '.join(str(m) for m in missing)}"
56+
)
5757

5858

5959
def test_stdlib_modules():
@@ -139,9 +139,9 @@ def test_stdlib_modules():
139139
except ModuleNotFoundError:
140140
missing.append(module)
141141

142-
assert (
143-
len(missing) == 0
144-
), f"Missing stdlib modules: {', '.join(str(m) for m in missing)}"
142+
assert len(missing) == 0, (
143+
f"Missing stdlib modules: {', '.join(str(m) for m in missing)}"
144+
)
145145

146146

147147
def test_sysconfig_data():
@@ -284,9 +284,9 @@ def test_hashlib():
284284
digest_args = []
285285
msg = getattr(hashlib, algorithm)()
286286
msg.update(b"Hello world")
287-
assert (
288-
msg.hexdigest(*digest_args) == expected
289-
), f"{algorithm} digest was {msg.hexdigest(*digest_args)}"
287+
assert msg.hexdigest(*digest_args) == expected, (
288+
f"{algorithm} digest was {msg.hexdigest(*digest_args)}"
289+
)
290290

291291

292292
def test_sqlite3():

tests/test_macOS.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ def test_stdlib_modules():
8181
except ModuleNotFoundError:
8282
missing.append(module)
8383

84-
assert (
85-
len(missing) == 0
86-
), f"Missing stdlib modules: {', '.join(str(m) for m in missing)}"
84+
assert len(missing) == 0, (
85+
f"Missing stdlib modules: {', '.join(str(m) for m in missing)}"
86+
)

tests/test_thirdparty.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
def xfail_if_not_installed(package_name):
1313
"""A test decorator that xfails a test if the named package isn't installed.
14-
The third-party tests are dependant on packages being built. During pre-release some
14+
15+
The third-party tests are dependent on packages being built. During pre-release some
1516
packages won't be compilable. So - the pyproject.toml installs third party packages
1617
with some conditional gating.
1718
@@ -191,10 +192,10 @@ def test_pandas():
191192

192193
# Pandas 1.5 changed the API for to_csv()
193194
if tuple(int(v) for v in __version__.split(".")[:2]) < (1, 5):
194-
kwargs = dict(line_terminator="\n")
195+
kwargs = {"line_terminator": "\n"}
195196
else:
196-
kwargs = dict(lineterminator="\n")
197+
kwargs = {"lineterminator": "\n"}
197198

198-
assert (
199-
",Letter,Number\n" "0,alpha,1\n" "1,bravo,2\n" "2,charlie,3\n"
200-
) == df.to_csv(**kwargs)
199+
assert (",Letter,Number\n0,alpha,1\n1,bravo,2\n2,charlie,3\n") == df.to_csv(
200+
**kwargs
201+
)

tests/testbed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def run_tests():
3232
# macOS, output the log sentinel multiple times to decrease the chance of
3333
# this happening.
3434
if sys.platform in {"darwin", "ios"}:
35-
for i in range(0, 6):
35+
for _ in range(0, 6):
3636
time.sleep(0.5)
3737
print(f">>>>>>>>>> EXIT {returncode} <<<<<<<<<<")
3838
else:

0 commit comments

Comments
 (0)