Skip to content

Switch to ruff #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@ repos:
- id: check-docstring-first
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/PyCQA/isort
rev: 6.0.1
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.7
hooks:
- id: isort
additional_dependencies: [toml]
- repo: https://github.com/asottile/pyupgrade
rev: v3.20.0
- id: docformatter
args: [--in-place, --black]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.4
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.1.0
- id: ruff-format
- id: ruff-check
args: [ --fix ]
- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 7.3.0
hooks:
- id: flake8
- id: codespell
# remove toml extra once Python 3.10 is no longer supported
additional_dependencies: ['.[toml]']
2 changes: 1 addition & 1 deletion pth-tester/pth_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
has_socket = False


# The pth_tester module should be initalized by processing the `.pth` file
# The pth_tester module should be initialized by processing the `.pth` file
# created on installation.
def init():
global initialized
Expand Down
7 changes: 2 additions & 5 deletions pth-tester/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
# Copied from setuptools:
# (https://github.com/pypa/setuptools/blob/7c859e017368360ba66c8cc591279d8964c031bc/setup.py#L40C6-L82)
class install_with_pth(install):
"""
Custom install command to install a .pth file.
"""Custom install command to install a .pth file.

This hack is necessary because there's no standard way to install behavior
on startup (and it's debatable if there should be one). This hack (ab)uses
Expand All @@ -30,9 +29,7 @@ def finalize_options(self):
self._restore_install_lib()

def _restore_install_lib(self):
"""
Undo secondary effect of `extra_path` adding to `install_lib`
"""
"""Undo secondary effect of `extra_path` adding to `install_lib`"""
suffix = os.path.relpath(self.install_lib, self.install_libbase)

if suffix.strip() == self._pth_contents.strip():
Expand Down
27 changes: 20 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ requires = [
(platform_system != 'iOS' and platform_system != 'Android' and python_version < '3.14') \
or (platform_system == 'iOS' and python_version < '3.14') \
or (platform_system == 'Android' and python_version < '3.14')""",
# pillow not available anywhere on 3.14
"""pillow; \
# pillow not available anywhere on 3.14. 11.3.0 wheel is known bad on iOS.
"""pillow != 11.3.0; \
(platform_system != 'iOS' and platform_system != 'Android' and python_version < '3.14') \
or (platform_system == 'iOS' and python_version < '3.14') \
or (platform_system == 'Android' and python_version < '3.14')""",
Expand Down Expand Up @@ -108,7 +108,7 @@ flatpak_sdk = "org.gnome.Sdk"

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

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

[tool.isort]
profile = "black"
split_on_trailing_comma = true
combine_as_imports = true
[tool.ruff.lint]
# In addition to the default rules, these additional rules will be used:
extend-select = [
"E", # pycodestyle
"W", # pycodestyle
"F", # pyflakes
"UP", # pyupgrade
"B", # flake8-bugbear
"YTT", # flake8-2020
"ASYNC", # flake8-async
"C4", # flake8-comprehensions
"I", # isort
# The SIM rules are *very* opinionated, and don't necessarily make for better code.
# They may be worth occasionally turning on just to see if something could actually
# use improvement.
# "SIM", # flake8-simplify
]
5 changes: 0 additions & 5 deletions setup.cfg

This file was deleted.

18 changes: 9 additions & 9 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def test_bootstrap_modules():
except ModuleNotFoundError:
missing.append(module)

assert (
len(missing) == 0
), f"Missing bootstrap modules: {', '.join(str(m) for m in missing)}"
assert len(missing) == 0, (
f"Missing bootstrap modules: {', '.join(str(m) for m in missing)}"
)


def test_stdlib_modules():
Expand Down Expand Up @@ -139,9 +139,9 @@ def test_stdlib_modules():
except ModuleNotFoundError:
missing.append(module)

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


def test_sysconfig_data():
Expand Down Expand Up @@ -284,9 +284,9 @@ def test_hashlib():
digest_args = []
msg = getattr(hashlib, algorithm)()
msg.update(b"Hello world")
assert (
msg.hexdigest(*digest_args) == expected
), f"{algorithm} digest was {msg.hexdigest(*digest_args)}"
assert msg.hexdigest(*digest_args) == expected, (
f"{algorithm} digest was {msg.hexdigest(*digest_args)}"
)


def test_sqlite3():
Expand Down
6 changes: 3 additions & 3 deletions tests/test_macOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ def test_stdlib_modules():
except ModuleNotFoundError:
missing.append(module)

assert (
len(missing) == 0
), f"Missing stdlib modules: {', '.join(str(m) for m in missing)}"
assert len(missing) == 0, (
f"Missing stdlib modules: {', '.join(str(m) for m in missing)}"
)
13 changes: 7 additions & 6 deletions tests/test_thirdparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

def xfail_if_not_installed(package_name):
"""A test decorator that xfails a test if the named package isn't installed.
The third-party tests are dependant on packages being built. During pre-release some

The third-party tests are dependent on packages being built. During pre-release some
packages won't be compilable. So - the pyproject.toml installs third party packages
with some conditional gating.

Expand Down Expand Up @@ -191,10 +192,10 @@ def test_pandas():

# Pandas 1.5 changed the API for to_csv()
if tuple(int(v) for v in __version__.split(".")[:2]) < (1, 5):
kwargs = dict(line_terminator="\n")
kwargs = {"line_terminator": "\n"}
else:
kwargs = dict(lineterminator="\n")
kwargs = {"lineterminator": "\n"}

assert (
",Letter,Number\n" "0,alpha,1\n" "1,bravo,2\n" "2,charlie,3\n"
) == df.to_csv(**kwargs)
assert (",Letter,Number\n0,alpha,1\n1,bravo,2\n2,charlie,3\n") == df.to_csv(
**kwargs
)
2 changes: 1 addition & 1 deletion tests/testbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def run_tests():
# macOS, output the log sentinel multiple times to decrease the chance of
# this happening.
if sys.platform in {"darwin", "ios"}:
for i in range(0, 6):
for _ in range(0, 6):
time.sleep(0.5)
print(f">>>>>>>>>> EXIT {returncode} <<<<<<<<<<")
else:
Expand Down
Loading