Skip to content

Commit

Permalink
Replace flake8 and autopep8 with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
mbkumar committed Oct 5, 2023
1 parent 085177e commit a3419b7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 26 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install python dependencies
run: |
pip install flake8
- name: Run ruff
uses: chartboost/ruff-action@v1

- name: Run linting tests
run: |
export EXCLUDE="E226,E265,E266,E4,E5,E7,W,F"
flake8 --ignore $EXCLUDE src/
flake8 --ignore $EXCLUDE tests/
flake8 --ignore $EXCLUDE examples/
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@ requires = ["setuptools>=45", "wheel", "oldest-supported-numpy", "cmake", "ninja
build-backend = "setuptools.build_meta"

[tools.setuptools_scm]

[tool.ruff]
src = ["src/simsopt"]
ignore = ["E226","E265","E266","E4","E501","E701","E702","E712","E722","E731","E741","F403","F405","F406","W5"]
[tool.ruff.per-file-ignores]
"__init__.py" = ["E402","F401"]
"tests/verify_MPI_not_initialized.py" = ["F401"]
"tests/geo/test_plot.py" = ["F401"]
"tests/geo/test_curve.py" = ["F401"]

3 changes: 2 additions & 1 deletion run_autopep
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
set -ex

EXCLUDE="E226,E265,E266,E4,E5,E7,W,F"
# EXCLUDE="E226,E265,E266,E4,E5,E7,W,F"
EXCLUDE="E226,E265,E266,E4,E501,E722,F403,F405,F406,W5"
flake8 --ignore $EXCLUDE src/ || (exit 0)
flake8 --ignore $EXCLUDE tests/ || (exit 0)
flake8 --ignore $EXCLUDE examples/ || (exit 0)
Expand Down
7 changes: 7 additions & 0 deletions run_ruff
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
# https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
set -ex

ruff check . || (exit 0)
ruff check --fix .
ruff check .
5 changes: 2 additions & 3 deletions tests/geo/test_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

try:
import pyevtk
pyevtk_found = True
except ImportError:
pyevtk_found = False
pyevtk = None

logger = logging.getLogger(__name__)
#logging.basicConfig(level=logging.INFO)
Expand Down Expand Up @@ -386,7 +385,7 @@ def test_curve_dkappa_by_dphi_derivative(self):
with self.subTest(curvetype=curvetype, rotated=rotated):
self.subtest_curve_dkappa_by_dphi_derivative(curvetype, rotated)

@unittest.skipIf(not pyevtk_found, "pyevtk not found")
@unittest.skipIf(pyevtk is None, "pyevtk not found")
def test_curve_to_vtk(self):
curve0 = get_curve(self.curvetypes[0], False)
curve1 = get_curve(self.curvetypes[1], True)
Expand Down
14 changes: 6 additions & 8 deletions tests/mhd/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
from monty.tempfile import ScratchDir

try:
import spec
spec_found = True
import spec as spec_mod
except ImportError:
spec_found = False
spec_mod = None

try:
import pyoculus
pyoculus_found = True
except ImportError:
pyoculus_found = False
pyoculus = None

try:
from mpi4py import MPI
Expand All @@ -29,7 +27,7 @@
from simsopt.objectives import LeastSquaresProblem
from simsopt.solve import least_squares_serial_solve

if (MPI is not None) and spec_found:
if (MPI is not None) and (spec_mod is not None):
from simsopt.mhd import Spec, Residue

from . import TEST_DIR
Expand All @@ -38,7 +36,7 @@
# logging.basicConfig(level=logging.DEBUG)


@unittest.skipIf(not spec_found, "SPEC python module not found")
@unittest.skipIf(spec_mod is None, "SPEC python module not found")
class SpecTests(unittest.TestCase):
def test_init_defaults(self):
"""
Expand Down Expand Up @@ -439,7 +437,7 @@ def test_integrated_stellopt_scenarios_2dof(self):
self.assertAlmostEqual(equil.iota(), -0.4114567, places=3)
self.assertAlmostEqual(prob.objective(), 7.912501330E-04, places=3)

@unittest.skipIf((not spec_found) or (not pyoculus_found),
@unittest.skipIf((spec_mod is None) or (pyoculus is None),
"SPEC python module or pyoculus not found")
def test_residue(self):
"""
Expand Down
9 changes: 4 additions & 5 deletions tests/mhd/test_vmec.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
MPI = None

try:
import vmec
vmec_found = True
import vmec as vmec_mod
except ImportError:
vmec_found = False
vmec_mod = None

from simsopt._core.optimizable import make_optimizable
from simsopt.objectives.least_squares import LeastSquaresProblem
Expand Down Expand Up @@ -159,7 +158,7 @@ def test_error_on_rerun(self):
iota2 = vmec.mean_iota()


@unittest.skipIf((MPI is not None) and (vmec_found), "Interface to MPI and VMEC found")
@unittest.skipIf((MPI is not None) and (vmec_mod is not None), "Interface to MPI and VMEC found")
class VmecTestsWithoutMPIorvmec(unittest.TestCase):
def test_runnable_raises(self):
"""
Expand All @@ -171,7 +170,7 @@ def test_runnable_raises(self):
v = Vmec()


@unittest.skipIf((MPI is None) or (not vmec_found), "Valid Python interface to VMEC not found")
@unittest.skipIf((MPI is None) or (vmec_mod is None), "Valid Python interface to VMEC not found")
class VmecTests(unittest.TestCase):
def test_init_defaults(self):
"""
Expand Down

0 comments on commit a3419b7

Please sign in to comment.