Skip to content

Commit 1fc2c2d

Browse files
authored
Merge pull request python-control#1118 from roryyorke/lint-lib-only
Lint library code only with `ruff check`
2 parents 5707dcf + 18d3d59 commit 1fc2c2d

33 files changed

Lines changed: 151 additions & 131 deletions

‎.github/workflows/ruff-check.yml‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# run ruff check on library source
2+
# TODO: extend to tests, examples, benchmarks
3+
4+
name: ruff-check
5+
6+
on: [push, pull_request]
7+
8+
jobs:
9+
ruff-check-linux:
10+
# ruff *shouldn't* be sensitive to platform
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout python-control
15+
uses: actions/checkout@v3
16+
17+
- name: Setup environment
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: 3.13 # todo: latest?
21+
22+
- name: Install ruff
23+
run: |
24+
python -m pip install --upgrade pip
25+
python -m pip install ruff
26+
27+
- name: Run ruff check
28+
run: |
29+
ruff check

‎control/__init__.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@
7070
# Import functions from within the control system library
7171
# Note: the functions we use are specified as __all__ variables in the modules
7272

73+
# don't warn about `import *`
74+
# ruff: noqa: F403
75+
# don't warn about unknown names; they come via `import *`
76+
# ruff: noqa: F405
77+
7378
# Input/output system modules
7479
from .iosys import *
7580
from .nlsys import *
@@ -106,8 +111,8 @@
106111
from .sysnorm import *
107112

108113
# Allow access to phase_plane functions as ct.phaseplot.fcn or ct.pp.fcn
109-
from . import phaseplot
110-
from . import phaseplot as pp
114+
from . import phaseplot as phaseplot
115+
pp = phaseplot
111116

112117
# Exceptions
113118
from .exception import *

‎control/canonical.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
import numpy as np
1010

11-
from numpy import zeros, zeros_like, shape, poly, iscomplex, vstack, hstack, \
12-
transpose, empty, finfo, float64
13-
from numpy.linalg import solve, matrix_rank, eig
11+
from numpy import zeros_like, poly, transpose
12+
from numpy.linalg import solve, matrix_rank
1413

1514
from scipy.linalg import schur
1615

‎control/dtime.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"""
4949

5050
from .iosys import isctime
51-
from .statesp import StateSpace
5251

5352
__all__ = ['sample_system', 'c2d']
5453

‎control/exception.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def slycot_check():
7171
global slycot_installed
7272
if slycot_installed is None:
7373
try:
74-
import slycot
74+
import slycot # noqa: F401
7575
slycot_installed = True
7676
except:
7777
slycot_installed = False
@@ -85,7 +85,7 @@ def pandas_check():
8585
global pandas_installed
8686
if pandas_installed is None:
8787
try:
88-
import pandas
88+
import pandas # noqa: F401
8989
pandas_installed = True
9090
except:
9191
pandas_installed = False
@@ -98,7 +98,7 @@ def cvxopt_check():
9898
global cvxopt_installed
9999
if cvxopt_installed is None:
100100
try:
101-
import cvxopt
101+
import cvxopt # noqa: F401
102102
cvxopt_installed = True
103103
except:
104104
cvxopt_installed = False

‎control/flatsys/__init__.py‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,17 @@
6161
"""
6262

6363
# Basis function families
64-
from .basis import BasisFamily
65-
from .poly import PolyFamily
66-
from .bezier import BezierFamily
67-
from .bspline import BSplineFamily
64+
from .basis import BasisFamily as BasisFamily
65+
from .poly import PolyFamily as PolyFamily
66+
from .bezier import BezierFamily as BezierFamily
67+
from .bspline import BSplineFamily as BSplineFamily
6868

6969
# Classes
70-
from .systraj import SystemTrajectory
71-
from .flatsys import FlatSystem, flatsys
72-
from .linflat import LinearFlatSystem
70+
from .systraj import SystemTrajectory as SystemTrajectory
71+
from .flatsys import FlatSystem as FlatSystem
72+
from .flatsys import flatsys as flatsys
73+
from .linflat import LinearFlatSystem as LinearFlatSystem
7374

7475
# Package functions
75-
from .flatsys import point_to_point, solve_flat_ocp
76+
from .flatsys import point_to_point as point_to_point
77+
from .flatsys import solve_flat_ocp as solve_flat_ocp

‎control/flatsys/bspline.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import numpy as np
1010
from .basis import BasisFamily
11-
from scipy.interpolate import BSpline, splev
11+
from scipy.interpolate import BSpline
1212

1313
class BSplineFamily(BasisFamily):
1414
"""B-spline basis functions.

‎control/flatsys/flatsys.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import warnings
99
from .poly import PolyFamily
1010
from .systraj import SystemTrajectory
11+
from ..exception import ControlArgument
1112
from ..nlsys import NonlinearIOSystem
1213
from ..timeresp import _check_convert_array
1314

@@ -245,7 +246,6 @@ def flatsys(*args, updfcn=None, outfcn=None, **kwargs):
245246
"""
246247
from .linflat import LinearFlatSystem
247248
from ..statesp import StateSpace
248-
from ..iosys import _process_iosys_keywords
249249

250250
if len(args) == 1 and isinstance(args[0], StateSpace):
251251
# We were passed a linear system, so call linflat

‎control/frdata.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from warnings import warn
1616

1717
import numpy as np
18-
from numpy import absolute, angle, array, empty, eye, imag, linalg, ones, \
19-
real, sort, where
18+
from numpy import absolute, array, empty, eye, imag, linalg, ones, \
19+
real, sort
2020
from scipy.interpolate import splev, splprep
2121

2222
from . import config

‎control/freqplot.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import itertools
1212
import math
1313
import warnings
14-
from os.path import commonprefix
1514

1615
import matplotlib as mpl
1716
import matplotlib.pyplot as plt
@@ -760,13 +759,11 @@ def _make_line_label(response, output_index, input_index):
760759
if plot_magnitude:
761760
ax_mag.axhline(y=0 if dB else 1, color='k', linestyle=':',
762761
zorder=-20)
763-
mag_ylim = ax_mag.get_ylim()
764762

765763
if plot_phase:
766764
ax_phase.axhline(y=phase_limit if deg else
767765
math.radians(phase_limit),
768766
color='k', linestyle=':', zorder=-20)
769-
phase_ylim = ax_phase.get_ylim()
770767

771768
# Annotate the phase margin (if it exists)
772769
if plot_phase and pm != float('inf') and Wcp != float('nan'):
@@ -2222,7 +2219,7 @@ def gangof4_plot(
22222219
See :class:`ControlPlot` for more detailed information.
22232220
22242221
"""
2225-
if len(args) == 1 and isinstance(arg, FrequencyResponseData):
2222+
if len(args) == 1 and isinstance(args[0], FrequencyResponseData):
22262223
if any([kw is not None
22272224
for kw in [omega, omega_limits, omega_num, Hz]]):
22282225
raise ValueError(

0 commit comments

Comments
 (0)