From 5939971158cbac312b778029391d1593153e5ff5 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Mon, 2 Dec 2024 13:43:11 +1300 Subject: [PATCH] Use Ruff instead of other lint/formatting tools --- .pre-commit-config.yaml | 77 +++++++---------------------------------- noxfile.py | 2 ++ pyproject.toml | 23 ++++++++++++ setup.cfg | 6 ---- src/bmipy/__init__.py | 1 + src/bmipy/__main__.py | 1 + src/bmipy/_cmd.py | 1 + src/bmipy/_template.py | 3 +- src/bmipy/bmi.py | 4 +-- tests/cli_test.py | 1 + tests/template_test.py | 4 +-- 11 files changed, 46 insertions(+), 77 deletions(-) delete mode 100644 setup.cfg diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5910e0a..e41049a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,57 +1,14 @@ +ci: + autoupdate_schedule: quarterly repos: -- repo: https://github.com/psf/black - rev: 23.12.1 - hooks: - - id: black - name: black - description: "Black: The uncompromising Python code formatter" - entry: black - language: python - language_version: python3 - minimum_pre_commit_version: 2.9.2 - require_serial: true - types_or: [python, pyi] - - id: black-jupyter - name: black-jupyter - description: - "Black: The uncompromising Python code formatter (with Jupyter Notebook support)" - entry: black - language: python - minimum_pre_commit_version: 2.9.2 - require_serial: true - types_or: [python, pyi, jupyter] - additional_dependencies: [".[jupyter]"] - -- repo: https://github.com/pycqa/flake8 - rev: 7.0.0 - hooks: - - id: flake8 - additional_dependencies: - - flake8-bugbear - - flake8-comprehensions - - flake8-simplify - -- repo: https://gitlab.com/kennon.mckeever/nbhooks - rev: 1.0.1 - hooks: - - id: nb-ensure-clean - name: nb-ensure-clean - description: Ensure that committed Jupyter notebooks contain no outputs. - entry: nb-ensure-clean - files: \.ipynb$ - language: python - -- repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 - hooks: - - id: pyupgrade - args: [--py310-plus] - -- repo: https://github.com/asottile/reorder-python-imports - rev: v3.12.0 - hooks: - - id: reorder-python-imports - args: [--py310-plus, --add-import, "from __future__ import annotations"] +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.8.1 + hooks: + # Run the linter + - id: ruff + args: [ --fix ] + # Run the formatter + - id: ruff-format - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 @@ -75,20 +32,10 @@ repos: .gitignore ) -- repo: https://github.com/PyCQA/pydocstyle - rev: 6.3.0 - hooks: - - id: pydocstyle - files: bmipy/.*\.py$ - args: - - --convention=numpy - - --add-select=D417 - additional_dependencies: [".[toml]"] - - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.8.0 hooks: - id: mypy - language_version: python3.12 - additional_dependencies: [types-all] + #language_version: python3.12 + #additional_dependencies: [types-all] files: src/.*\.py$ diff --git a/noxfile.py b/noxfile.py index cf83476..0aa12fd 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,3 +1,5 @@ +"""Nox configuration.""" + from __future__ import annotations import os diff --git a/pyproject.toml b/pyproject.toml index e8fec2d..8861ee9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,6 +65,29 @@ where = [ [tool.coverage.run] relative_files = true +[tool.ruff.lint] +select = [ + "B", # flake8-bugbear + "C4", # flake8-comprehensions + "C90", # mccabe + "D", # pydocstyle + "E", "W", # pycodestyle + "F", # Pyflakes + "FA", # flake8-future-annotations + "I", # isort + # "SIM", # flake8-simplify + "UP", # pyupgrade +] + +[tool.ruff.lint.per-file-ignores] +"tests/**.py" = ["D"] + +[tool.ruff.lint.mccabe] +max-complexity = 18 + +[tool.ruff.lint.pydocstyle] +convention = "numpy" + [tool.mypy] check_untyped_defs = true disallow_any_generics = true diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index c5c0cdf..0000000 --- a/setup.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[flake8] -exclude = docs, build, .nox -ignore = C901, E203, E266, E501, W503, B905 -max-line-length = 88 -max-complexity = 18 -select = B,C,E,F,W,T4,B9 diff --git a/src/bmipy/__init__.py b/src/bmipy/__init__.py index 27e652a..7e31121 100644 --- a/src/bmipy/__init__.py +++ b/src/bmipy/__init__.py @@ -1,4 +1,5 @@ """The Basic Model Interface (BMI) for Python.""" + from __future__ import annotations from bmipy._version import __version__ diff --git a/src/bmipy/__main__.py b/src/bmipy/__main__.py index 19d6a0c..a9da814 100644 --- a/src/bmipy/__main__.py +++ b/src/bmipy/__main__.py @@ -1,4 +1,5 @@ """The bmipy-render command.""" + from __future__ import annotations from bmipy._cmd import main diff --git a/src/bmipy/_cmd.py b/src/bmipy/_cmd.py index ddd2947..c9c68a6 100644 --- a/src/bmipy/_cmd.py +++ b/src/bmipy/_cmd.py @@ -1,4 +1,5 @@ """Command line interface that create template BMI implementations.""" + from __future__ import annotations import argparse diff --git a/src/bmipy/_template.py b/src/bmipy/_template.py index 5353563..8e6d83a 100644 --- a/src/bmipy/_template.py +++ b/src/bmipy/_template.py @@ -4,8 +4,7 @@ import os import re import textwrap -from collections import defaultdict -from collections import OrderedDict +from collections import OrderedDict, defaultdict from bmipy.bmi import Bmi diff --git a/src/bmipy/bmi.py b/src/bmipy/bmi.py index 2158a5e..9407d3b 100644 --- a/src/bmipy/bmi.py +++ b/src/bmipy/bmi.py @@ -3,10 +3,10 @@ This language specification is derived from the Scientific Interface Definition Language (SIDL) file `bmi.sidl `_. """ + from __future__ import annotations -from abc import ABC -from abc import abstractmethod +from abc import ABC, abstractmethod from typing import Any import numpy as np diff --git a/tests/cli_test.py b/tests/cli_test.py index 5dfdef9..d799eca 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -1,6 +1,7 @@ from __future__ import annotations import pytest + from bmipy._cmd import main diff --git a/tests/template_test.py b/tests/template_test.py index 731df56..f18d6c9 100644 --- a/tests/template_test.py +++ b/tests/template_test.py @@ -1,8 +1,8 @@ from __future__ import annotations import pytest -from bmipy._template import dedent_docstring -from bmipy._template import render_function_signature + +from bmipy._template import dedent_docstring, render_function_signature @pytest.mark.parametrize(