Skip to content
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

Use Ruff instead of other lint/formatting tools #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
77 changes: 12 additions & 65 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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$
2 changes: 2 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Nox configuration."""

from __future__ import annotations

import os
Expand Down
23 changes: 23 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions setup.cfg

This file was deleted.

1 change: 1 addition & 0 deletions src/bmipy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The Basic Model Interface (BMI) for Python."""

from __future__ import annotations

from bmipy._version import __version__
Expand Down
1 change: 1 addition & 0 deletions src/bmipy/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The bmipy-render command."""

from __future__ import annotations

from bmipy._cmd import main
Expand Down
1 change: 1 addition & 0 deletions src/bmipy/_cmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Command line interface that create template BMI implementations."""

from __future__ import annotations

import argparse
Expand Down
3 changes: 1 addition & 2 deletions src/bmipy/_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/bmipy/bmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
This language specification is derived from the Scientific Interface
Definition Language (SIDL) file `bmi.sidl <https://github.com/csdms/bmi>`_.
"""

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
Expand Down
1 change: 1 addition & 0 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import pytest

from bmipy._cmd import main


Expand Down
4 changes: 2 additions & 2 deletions tests/template_test.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Loading