From c3da09a25feb2892064fa47f5a619090c2242199 Mon Sep 17 00:00:00 2001 From: "Austin E. Soplata" Date: Fri, 8 Nov 2024 17:24:35 -0500 Subject: [PATCH] style: fix doc lints, introduce ruff linting --- .github/workflows/unix_unit_tests.yml | 8 ++++++++ Makefile | 5 +++++ doc/conf.py | 1 - examples/howto/plot_connectivity.py | 2 -- examples/howto/plot_firing_pattern.py | 1 - examples/howto/plot_hnn_animation.py | 4 +--- examples/howto/plot_simulate_mpi_backend.py | 2 -- examples/workflows/plot_simulate_alpha.py | 4 +--- examples/workflows/plot_simulate_evoked.py | 5 ----- pyproject.toml | 8 ++++++++ 10 files changed, 23 insertions(+), 17 deletions(-) diff --git a/.github/workflows/unix_unit_tests.yml b/.github/workflows/unix_unit_tests.yml index 53969ca09..e21068a84 100644 --- a/.github/workflows/unix_unit_tests.yml +++ b/.github/workflows/unix_unit_tests.yml @@ -54,6 +54,14 @@ shell: bash -el {0} run: | pip install --verbose '.[opt, parallel, test, gui]' + - name: Lint with ruff + shell: bash -el {0} + run: | + ruff check --no-fix + - name: Check formatting with ruff + shell: bash -el {0} + run: | + ruff format --check - name: Test with pytest shell: bash -el {0} run: | diff --git a/Makefile b/Makefile index 9faa0a1ec..19fb07e93 100644 --- a/Makefile +++ b/Makefile @@ -16,8 +16,13 @@ check-manifest: format: ruff format +lint: + ruff check + modl: cd hnn_core/mod/ && nrnivmodl test: + ruff format --check + ruff check --no-fix pytest . diff --git a/doc/conf.py b/doc/conf.py index 09ebc4058..ad948dd52 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -16,7 +16,6 @@ import sys # sys.path.insert(0, os.path.abspath('.')) -import sphinx_gallery from sphinx_gallery.sorting import ExampleTitleSortKey, ExplicitOrder import sphinx_bootstrap_theme diff --git a/examples/howto/plot_connectivity.py b/examples/howto/plot_connectivity.py index 3a0302a5a..b944cfa71 100644 --- a/examples/howto/plot_connectivity.py +++ b/examples/howto/plot_connectivity.py @@ -10,12 +10,10 @@ # sphinx_gallery_thumbnail_number = 2 -import os.path as op ############################################################################### # Let us import ``hnn_core``. -import hnn_core from hnn_core import jones_2009_model, simulate_dipole ############################################################################### diff --git a/examples/howto/plot_firing_pattern.py b/examples/howto/plot_firing_pattern.py index 4e916ec90..d32eac9b5 100644 --- a/examples/howto/plot_firing_pattern.py +++ b/examples/howto/plot_firing_pattern.py @@ -16,7 +16,6 @@ ############################################################################### # Let us import ``hnn_core``. -import hnn_core from hnn_core import read_spikes, jones_2009_model, simulate_dipole ############################################################################### diff --git a/examples/howto/plot_hnn_animation.py b/examples/howto/plot_hnn_animation.py index 3e2ebb17c..58bda7a42 100644 --- a/examples/howto/plot_hnn_animation.py +++ b/examples/howto/plot_hnn_animation.py @@ -11,10 +11,8 @@ ############################################################################### # First, we'll import the necessary modules for instantiating a network and # running a simulation that we would like to animate. -import os.path as op -import hnn_core -from hnn_core import jones_2009_model, simulate_dipole, read_params +from hnn_core import jones_2009_model, simulate_dipole from hnn_core.network_models import add_erp_drives_to_jones_model ############################################################################### diff --git a/examples/howto/plot_simulate_mpi_backend.py b/examples/howto/plot_simulate_mpi_backend.py index 4cbac1c35..b64e7cbaf 100644 --- a/examples/howto/plot_simulate_mpi_backend.py +++ b/examples/howto/plot_simulate_mpi_backend.py @@ -18,9 +18,7 @@ ############################################################################### # Let us import hnn_core -import os.path as op -import hnn_core from hnn_core import simulate_dipole, jones_2009_model ############################################################################### diff --git a/examples/workflows/plot_simulate_alpha.py b/examples/workflows/plot_simulate_alpha.py index c5766ea1e..59c7852ea 100644 --- a/examples/workflows/plot_simulate_alpha.py +++ b/examples/workflows/plot_simulate_alpha.py @@ -20,12 +20,10 @@ # Nick Tolley # Christopher Bailey -import os.path as op ############################################################################### # Let us import hnn_core -import hnn_core from hnn_core import simulate_dipole, jones_2009_model ############################################################################### @@ -72,7 +70,7 @@ # included in our biophysical model. We can confirm that what we simulate is # indeed 10 Hz activity by plotting the power spectral density (PSD). import matplotlib.pyplot as plt -from hnn_core.viz import plot_dipole, plot_psd +from hnn_core.viz import plot_psd fig, axes = plt.subplots(2, 1, constrained_layout=True) tmin, tmax = 10, 300 # exclude the initial burn-in period from the plots diff --git a/examples/workflows/plot_simulate_evoked.py b/examples/workflows/plot_simulate_evoked.py index 699a2d602..6cfc93b12 100644 --- a/examples/workflows/plot_simulate_evoked.py +++ b/examples/workflows/plot_simulate_evoked.py @@ -21,15 +21,10 @@ # sphinx_gallery_thumbnail_number = 3 -import os.path as op -import tempfile - -import matplotlib.pyplot as plt ############################################################################### # Let us import hnn_core -import hnn_core from hnn_core import simulate_dipole, jones_2009_model from hnn_core.viz import plot_dipole diff --git a/pyproject.toml b/pyproject.toml index 102644c78..abfc924ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,3 +12,11 @@ ignore-words-list = 'tha,nam,sherif,dout' exclude = ["*.ipynb"] [tool.ruff.format] quote-style = "single" +[tool.ruff.lint] +exclude = ["__init__.py"] +# We don't include rule "W504", which was in our old flake8 "setup.cfg" file for 2 reasons: it is an +# invalid option for the ruff linter, and the ruff formatter already applies that rule. +ignore = [ + "E402", # Needed for notes at beginning of example scripts + "E722", # From original flake8 'setup.cfg' file, needed in viz.py +]