Skip to content

Commit

Permalink
Merge pull request #113 from boutproject/ruff-lint
Browse files Browse the repository at this point in the history
Switch to `ruff` for linting and formatting
  • Loading branch information
ZedThree authored Oct 8, 2024
2 parents bfd3ca0 + e0d5471 commit 4a1a8c4
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 57 deletions.
21 changes: 9 additions & 12 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,23 @@ jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install black
- name: Install ruff
run: |
python -m pip install --upgrade pip
pip install black isort
pip install ruff
- name: Version
run: |
python --version
black --version
isort --version
- name: Run isort
run: |
isort src
- name: Run black
run: |
black src
ruff --version
- name: Run ruff, sort imports
run: ruff check --select I . --fix
- name: Run ruff format
run: ruff format .
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "[skip ci] Apply black/isort changes"
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ jobs:
if: always()

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Lint with flake8
run: |
flake8 && echo "flake8 successful"
pip install ruff
# Update output format to enable automatic inline annotations.
- name: Run Ruff
run: ruff check --output-format=github .
38 changes: 38 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ tests = [
docs = [
"sphinx>=3.4,<5",
]
lint = [
"ruff"
]

[project.scripts]
bout-squashoutput = "boutdata.scripts.bout_squashoutput:main"
Expand All @@ -57,3 +60,38 @@ version = { attr = "setuptools_scm.get_version" }

[tool.setuptools_scm]
write_to = "src/boutdata/_version.py"

[tool.ruff.lint]
extend-select = [
# "B", # flake8-bugbear
"I", # isort
# "ARG", # flake8-unused-arguments
# "C4", # flake8-comprehensions
# "ICN", # flake8-import-conventions
# "G", # flake8-logging-format
# "PGH", # pygrep-hooks
# "PIE", # flake8-pie
# "PL", # pylint
# "PT", # flake8-pytest-style
# "PTH", # flake8-use-pathlib
# "RET", # flake8-return
# "RUF", # Ruff-specific
# "SIM", # flake8-simplify
# "UP", # pyupgrade
# "YTT", # flake8-2020
# "EXE", # flake8-executable
# "NPY", # NumPy specific rules
# "PD", # pandas-vet
# "FURB", # refurb
]
ignore = [
"PLR2004", # magic-comparison
# "B9", # flake8-bugbear opinionated warnings
# "PLC0414", # useless-import-alias
"PLR0913", # too-many-arguments
"PLR0917", # too-many-positional
"PLR0914", # too-many-locals
"PLR0915", # too-many-statements
"PLR0912", # too-many-branches
"PTH123", # builtin-open
]
4 changes: 1 addition & 3 deletions src/boutdata/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Routines for exchanging data to/from BOUT++ """
"""Routines for exchanging data to/from BOUT++"""

from boutdata.collect import attributes, collect
from boututils.boutarray import BoutArray
Expand All @@ -15,8 +15,6 @@
__all__ = [
"attributes",
"collect",
"gen_surface",
"pol_slice",
"BoutArray",
"alwayswarn",
"launch",
Expand Down
5 changes: 3 additions & 2 deletions src/boutdata/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,9 @@ def _check_fieldperp_attributes(
# and check they are unique
if yindex_global is not None and yindex_global != temp_yindex:
raise ValueError(
"Found FieldPerp {} at different global y-indices, {} "
"and {}".format(varname, temp_yindex, yindex_global)
"Found FieldPerp {} at different global y-indices, {} " "and {}".format(
varname, temp_yindex, yindex_global
)
)
yindex_global = temp_yindex
if fieldperp_yproc is not None and fieldperp_yproc != pe_yind:
Expand Down
18 changes: 16 additions & 2 deletions src/boutdata/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,23 @@
from numpy import arctan as atan # noqa: F401
from numpy import arctan2 as atan2 # noqa: F401
from numpy import arctanh as atanh # noqa: F401
from numpy import ceil, cos, cosh, exp, floor, log, log10, pi # noqa: F401
from numpy import ( # noqa: F401 # noqa: F401
ceil,
cos,
cosh,
exp,
floor,
log,
log10,
pi,
round,
sin,
sinh,
sqrt,
tan,
tanh,
)
from numpy import power as pow # noqa: F401
from numpy import round, sin, sinh, sqrt, tan, tanh # noqa: F401

from boutdata.collect import (
_check_fieldperp_attributes,
Expand Down
4 changes: 1 addition & 3 deletions src/boutdata/gen_surface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Flux surface generator for tokamak grid files
"""
"""Flux surface generator for tokamak grid files"""

from __future__ import print_function

Expand Down
4 changes: 1 addition & 3 deletions src/boutdata/griddata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Routines for manipulating grid files
"""
"""Routines for manipulating grid files"""

import matplotlib.pyplot as plt
import numpy as np
Expand Down
4 changes: 1 addition & 3 deletions src/boutdata/input.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Fourier transform data for input to BOUT++
"""
"""Fourier transform data for input to BOUT++"""

from numpy import ndarray
from numpy.fft import rfft
Expand Down
4 changes: 2 additions & 2 deletions src/boutdata/mms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
""" Functions for calculating sources for the
Method of Manufactured Solutions (MMS)
"""Functions for calculating sources for the
Method of Manufactured Solutions (MMS)
"""

Expand Down
4 changes: 1 addition & 3 deletions src/boutdata/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Parse BOUT.inp settings file
"""
"""Parse BOUT.inp settings file"""


def get(filename, name, section=None):
Expand Down
2 changes: 1 addition & 1 deletion src/boutdata/tests/test_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ def test_core_min_files_append_time_split_raises(self, core_min, tmp_path):
"""
Check output from a core-only case using the minimum number of processes
"""
data_path, expected, fieldperp_global_yind = core_min
data_path, _expected, _fieldperp_global_yind = core_min
symlink_dump_files(data_path, tmp_path)

collect_kwargs = {"xguards": True, "yguards": "include_upper"}
Expand Down
2 changes: 1 addition & 1 deletion src/boututils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Generic routines, useful for all data """
"""Generic routines, useful for all data"""

__all__ = []

Expand Down
4 changes: 1 addition & 3 deletions src/boututils/ask.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Ask a yes/no question and return the answer.
"""
"""Ask a yes/no question and return the answer."""

import sys

Expand Down
4 changes: 1 addition & 3 deletions src/boututils/boutarray.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Wrapper for ndarray with extra attributes for BOUT++ fields.
"""
"""Wrapper for ndarray with extra attributes for BOUT++ fields."""

import numpy

Expand Down
4 changes: 1 addition & 3 deletions src/boututils/check_scaling.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Functions for checking the error scaling of MMS or MES results
"""
"""Functions for checking the error scaling of MMS or MES results"""

from numpy import array, isclose, log, polyfit

Expand Down
4 changes: 1 addition & 3 deletions src/boututils/surface_average.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Average over a surface
"""
"""Average over a surface"""

import numpy as np
import scipy
Expand Down
4 changes: 1 addition & 3 deletions src/boututils/volume_integral.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Integrate over a volume
"""
"""Integrate over a volume"""

import numpy as np
from past.utils import old_div
Expand Down

0 comments on commit 4a1a8c4

Please sign in to comment.