Skip to content

Commit

Permalink
Using ruff instead of black and isort
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreRaybaut committed Mar 29, 2024
1 parent 5c8ec26 commit f665ad7
Show file tree
Hide file tree
Showing 27 changed files with 106 additions and 69 deletions.
2 changes: 0 additions & 2 deletions .isort.cfg

This file was deleted.

23 changes: 5 additions & 18 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,12 @@
"files.trimTrailingWhitespace": true,
"python.defaultInterpreterPath": "${env:PPSTACK_PYTHONEXE}",
"editor.formatOnSave": true,
"isort.args": [
"--profile",
"black"
],
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.analysis.autoFormatStrings": true,
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.pytestPath": "pytest",
"python.testing.pytestArgs": [
"-v",
"--cov",
"--cov-report=html",
"plotpy"
],
"python.analysis.autoFormatStrings": true,
"python.analysis.typeCheckingMode": "off",
"python.testing.pytestArgs": [],
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
},
}
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,34 @@
"clear": true
}
},
{
"label": "Run Ruff",
"type": "shell",
"command": "cmd",
"args": [
"/c",
"run_ruff.bat",
],
"options": {
"cwd": "scripts",
"env": {
"PYTHON": "${env:PPSTACK_PYTHONEXE}",
"UNATTENDED": "1"
}
},
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "dedicated",
"showReuseMessage": true,
"clear": true
}
},
{
"label": "Clean Up",
"type": "shell",
Expand Down
3 changes: 1 addition & 2 deletions doc/dev/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ To run test with coverage support, use the following command::
Code formatting
^^^^^^^^^^^^^^^

The code is formatted with `black <https://black.readthedocs.io/en/stable/>`_
and `isort <https://isort.readthedocs.io/en/stable/>`_.
The code is formatted with `ruff <https://pypi.org/project/ruff/>`_.

If you are using `Visual Studio Code <https://code.visualstudio.com/>`_,
the formatting is done automatically when you save a file, thanks to the
Expand Down
2 changes: 1 addition & 1 deletion doc/intro/motivation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ What are PlotPy V2 advantages over PlotPy V1?
From a developer point of view, PlotPy V2 is a major overhaul of PlotPy V1:

* Architecture has been redesigned to be more modular and extensible, and more simple.
* Code quality has been improved introducing `black`, `isort` and typing annotations
* Code quality has been improved introducing `ruff` and typing annotations
all over the codebase

.. note::
Expand Down
25 changes: 8 additions & 17 deletions plotpy/external/sliders/_labeled.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
)

from ._misc import signals_blocked

from ._sliders import QDoubleRangeSlider, QDoubleSlider, QRangeSlider


Expand Down Expand Up @@ -133,14 +132,12 @@ class QLabeledSlider(_SliderProxy, QAbstractSlider):
_slider: QSlider

@overload
def __init__(self, parent: QWidget | None = ...) -> None:
...
def __init__(self, parent: QWidget | None = ...) -> None: ...

@overload
def __init__(
self, orientation: Qt.Orientation, parent: QWidget | None = ...
) -> None:
...
) -> None: ...

def __init__(self, *args: Any, **kwargs: Any) -> None:
parent, orientation = _handle_overloaded_slider_sig(args, kwargs)
Expand Down Expand Up @@ -263,14 +260,12 @@ class QLabeledDoubleSlider(QLabeledSlider):
_frangeChanged = Signal(float, float)

@overload
def __init__(self, parent: QWidget | None = ...) -> None:
...
def __init__(self, parent: QWidget | None = ...) -> None: ...

@overload
def __init__(
self, orientation: Qt.Orientation, parent: QWidget | None = ...
) -> None:
...
) -> None: ...

def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -300,14 +295,12 @@ class QLabeledRangeSlider(_SliderProxy, QAbstractSlider):
_slider: QRangeSlider

@overload
def __init__(self, parent: QWidget | None = ...) -> None:
...
def __init__(self, parent: QWidget | None = ...) -> None: ...

@overload
def __init__(
self, orientation: Qt.Orientation, parent: QWidget | None = ...
) -> None:
...
) -> None: ...

def __init__(self, *args: Any, **kwargs: Any) -> None:
parent, orientation = _handle_overloaded_slider_sig(args, kwargs)
Expand Down Expand Up @@ -545,14 +538,12 @@ class QLabeledDoubleRangeSlider(QLabeledRangeSlider):
_frangeChanged = Signal(float, float)

@overload
def __init__(self, parent: QWidget | None = ...) -> None:
...
def __init__(self, parent: QWidget | None = ...) -> None: ...

@overload
def __init__(
self, orientation: Qt.Orientation, parent: QWidget | None = ...
) -> None:
...
) -> None: ...

def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion plotpy/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def _import_dcm():
# is to check if pydicom is installed:
# pylint: disable=import-outside-toplevel
# pylint: disable=import-error
from pydicom import dicomio # type:ignore
from pydicom import dicomio # type:ignore # noqa: F401

logger.setLevel(logging.WARNING)

Expand Down
2 changes: 1 addition & 1 deletion plotpy/items/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def get_legend_size(
"""
width = 0
height = 0
for text, _, _, _ in legenditems:
for text, _, _, _ in legenditems: # noqa
sz = text.size()
if sz.width() > width:
width = sz.width()
Expand Down
2 changes: 1 addition & 1 deletion plotpy/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from guidata.configtools import get_module_data_path

import plotpy
import plotpy # noqa: F401

TESTDATAPATH = get_module_data_path("plotpy", osp.join("tests", "data"))

Expand Down
2 changes: 0 additions & 2 deletions plotpy/tests/features/test_autoscale_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
from guidata.qthelpers import qt_app_context

from plotpy.builder import make
from plotpy.items import PolygonShape
from plotpy.plot import PlotDialog
from plotpy.styles import ShapeParam
from plotpy.tools import (
AnnotatedCircleTool,
AnnotatedEllipseTool,
Expand Down
8 changes: 4 additions & 4 deletions plotpy/tests/features/test_colormap_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def test_colormap_editor() -> None:
cmap_tuples = tuple((int(val * 255 + 1), color) for val, color in cmap_tuples)
print(
"Initialization of a new default colormap editor, "
"modified post-initialization with the previous colormap with stops scaled by "
"255 + 1: ",
"modified post-initialization with the previous colormap "
"with stops scaled by 255 + 1: ",
cmap_tuples,
)
new_cmap = EditableColormap.from_iterable(cmap_tuples)
Expand All @@ -70,8 +70,8 @@ def test_colormap_editor() -> None:

print(
"Initialization of a new default colormap editor, "
"modified post-initialization with the previous colormap where the red stop is "
"replaced with a green stop: ",
"modified post-initialization with the previous colormap "
"where the red stop is replaced with a green stop: ",
cmap_tuples,
)

Expand Down
6 changes: 5 additions & 1 deletion plotpy/tests/features/test_imagefilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def imshow(x, y, data, filter_area, yreverse=True):
plot = win.manager.get_plot()
plot.add_item(image)
xmin, xmax, ymin, ymax = filter_area
ifilter = lambda x, y, data: gaussian_filter(data, 5)

def ifilter(x, y, data):
"""Image filter function"""
return gaussian_filter(data, 5)

flt = make.imagefilter(xmin, xmax, ymin, ymax, image, filter=ifilter)
plot.add_item(flt, z=1)
plot.replot()
Expand Down
2 changes: 0 additions & 2 deletions plotpy/tests/items/test_svgshapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

# guitest: show

import os.path as osp

from guidata.qthelpers import qt_app_context

from plotpy.builder import make
Expand Down
1 change: 0 additions & 1 deletion plotpy/tests/tools/test_get_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from guidata.qthelpers import qt_app_context

from plotpy.builder import make
from plotpy.config import _
from plotpy.coords import axes_to_canvas
from plotpy.tools import AnnotatedSegmentTool
from plotpy.widgets.selectdialog import SelectDialog, select_with_shape_tool
Expand Down
1 change: 0 additions & 1 deletion plotpy/tests/unit/test_aspect_ratio_tool.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import qtpy.QtCore as QC
from guidata.qthelpers import exec_dialog, qt_app_context

from plotpy.interfaces.items import IImageItemType
Expand Down
2 changes: 1 addition & 1 deletion plotpy/tests/unit/test_baseplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from plotpy.tests import vistools as ptv
from plotpy.tests.features.test_auto_curve_image import make_curve_image_legend
from plotpy.tools.curve import DownSamplingTool, EditPointTool, SelectPointsTool
from plotpy.tools.curve import EditPointTool, SelectPointsTool


def test_baseplot_api():
Expand Down
2 changes: 0 additions & 2 deletions plotpy/tests/unit/test_builder_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ def test_builder_svgshape():
svg_path = get_path("svg_target.svg")
with open(svg_path, "rb") as f:
svg_data = f.read()
x = np.linspace(0, 1, 10)
y = x**2
for shape_str in ("circle", "rectangle", "square"):
for data_or_path in (svg_data, svg_path):
items.append(
Expand Down
3 changes: 1 addition & 2 deletions plotpy/tests/widgets/test_dotarraydemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
from qtpy import QtGui as QG
from qtpy import QtWidgets as QW

import plotpy.config # Loading icons
import plotpy.widgets
import plotpy.config # Loading icons # noqa: F401
from plotpy.interfaces import IImageItemType
from plotpy.items import RawImageItem
from plotpy.items.curve.errorbar import vmap
Expand Down
2 changes: 1 addition & 1 deletion plotpy/tests/widgets/test_filtertest1.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from guidata.qthelpers import qt_app_context
from qtpy import QtWidgets as QW

import plotpy.config # Loading icons
import plotpy.config # Loading icons # noqa: F401
from plotpy.builder import make


Expand Down
2 changes: 1 addition & 1 deletion plotpy/tests/widgets/test_filtertest2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from guidata.qthelpers import qt_app_context, win32_fix_title_bar_background
from qtpy import QtWidgets as QW

import plotpy.config # Loading icons
import plotpy.config # Loading icons # noqa: F401
from plotpy.builder import make
from plotpy.plot import BasePlot, BasePlotOptions
from plotpy.plot.manager import PlotManager
Expand Down
1 change: 0 additions & 1 deletion plotpy/tests/widgets/test_resize_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pytest
from guidata.qthelpers import exec_dialog, qt_app_context
from qtpy import QtCore as QC
from qtpy.QtCore import Qt

from plotpy.widgets.resizedialog import ResizeDialog

Expand Down
1 change: 0 additions & 1 deletion plotpy/tests/widgets/test_syncplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from qtpy import QtGui as QG

from plotpy.builder import make
from plotpy.config import _
from plotpy.plot import BasePlot, PlotOptions
from plotpy.plot.plotwidget import SyncPlotWindow
from plotpy.tests.data import gen_2d_gaussian
Expand Down
6 changes: 4 additions & 2 deletions plotpy/tools/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,10 @@ def activate_command(self, plot, checked):
"""<b>Keyboard/mouse shortcuts:</b><br><br>
- <u>single left-click</u>: item (curve, image, ...) selection<br>
- <u>single right-click</u>: context-menu relative to selected item<br>
- <u>shift</u>: on-active-curve (or image) cursor (+ <u>control</u> to maintain cursor visible)<br>
- <u>shift + control</u>: on-active-curve cursor (+ <u>control</u> to maintain cursor visible)<br>
- <u>shift</u>: on-active-curve (or image) cursor (+ <u>control</u> to maintain
cursor visible)<br>
- <u>shift + control</u>: on-active-curve cursor (+ <u>control</u> to maintain
cursor visible)<br>
- <u>alt</u>: free cursor<br>
- <u>left-click + mouse move</u>: move item (when available)<br>
- <u>middle-click + mouse move</u>: pan<br>
Expand Down
4 changes: 3 additions & 1 deletion plotpy/widgets/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@
update_dataset,
)
from guidata.qthelpers import create_groupbox, exec_dialog
from numpy import inf # Do not remove this import (used by optimization funcs)

# Do not remove this import (used by optimization funcs)
from numpy import inf # noqa: F401
from qtpy import QtCore as QC
from qtpy import QtWidgets as QW
from qtpy.QtWidgets import QWidget # only to help intersphinx find QWidget
Expand Down
24 changes: 23 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Documentation = "https://plotpy.readthedocs.io/en/latest/"
plotpy-tests = "plotpy.tests:run"

[project.optional-dependencies]
dev = ["black", "isort", "pylint", "Coverage", "Cython"]
dev = ["ruff", "pylint", "Coverage", "Cython"]
doc = [
"PyQt5",
"sphinx",
Expand All @@ -74,3 +74,25 @@ include = ["plotpy*"]

[tool.setuptools.dynamic]
version = { attr = "plotpy.__version__" }

[tool.ruff]
exclude = [".git", ".vscode", "build", "dist"]
line-length = 88 # Same as Black.
indent-width = 4 # Same as Black.
target-version = "py38" # Assume Python 3.8

[tool.ruff.lint]
# all rules can be found here: https://beta.ruff.rs/docs/rules/
select = ["E", "F", "W", "I"]
ignore = [
"E203", # space before : (needed for how black formats slicing)
]

[tool.ruff.format]
quote-style = "double" # Like Black, use double quotes for strings.
indent-style = "space" # Like Black, indent with spaces, rather than tabs.
skip-magic-trailing-comma = false # Like Black, respect magic trailing commas.
line-ending = "auto" # Like Black, automatically detect the appropriate line ending.

[tool.ruff.lint.per-file-ignores]
"doc/*" = ["E402"]
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ tifffile
PyQt5
PythonQwt>=0.12.1
SciPy>=1.3
black
guidata>=3.4
isort
pylint
ruff
pytest
pytest-xvfb
python-docs-theme
Expand Down
Loading

0 comments on commit f665ad7

Please sign in to comment.