Skip to content

Commit

Permalink
style: use ruff format instead of black, update pre-commit, restrict …
Browse files Browse the repository at this point in the history
…pyside6 tests (#235)

* style: use ruff format

* fix import

* disallow pyside 6.6.2

* pin in tests too

* pyside6.4 on windows

* fix greedy imports

* double quote

* run sliders last

* try 6.6.1 again
  • Loading branch information
tlambert03 authored Mar 6, 2024
1 parent 56f65ff commit 16f9ef9
Show file tree
Hide file tree
Showing 30 changed files with 90 additions and 111 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@ jobs:
backend: pyside2

include:
# https://bugreports.qt.io/browse/PYSIDE-2627
- python-version: "3.10"
platform: macos-latest
backend: pyside6
backend: "'pyside6!=6.6.2'"
- python-version: "3.11"
platform: macos-latest
backend: pyside6
backend: "'pyside6!=6.6.2'"
- python-version: "3.10"
platform: windows-latest
backend: pyside6
backend: "'pyside6!=6.6.2'"
- python-version: "3.11"
platform: windows-latest
backend: pyside6
backend: "'pyside6!=6.6.2'"

- python-version: "3.12"
platform: macos-latest
Expand Down
19 changes: 4 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,15 @@ ci:
autoupdate_commit_msg: "ci: [pre-commit.ci] autoupdate"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-docstring-first
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.9
rev: v0.3.0
hooks:
- id: ruff
args: ["--fix"]
args: [--fix, --unsafe-fixes]
- id: ruff-format

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.15
rev: v0.16
hooks:
- id: validate-pyproject

Expand Down
2 changes: 1 addition & 1 deletion docs/_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def show_widget(context, width: int = 500) -> list[Path]:
)
src = src.replace("app.exec_()", "")

exec(src) # noqa: S102
exec(src)
_grab(dest, width)
return (
f"![{page.title}](../{dest.parent.name}/{dest.name})"
Expand Down
1 change: 1 addition & 0 deletions examples/qcollapsible.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Example for QCollapsible."""

from qtpy.QtWidgets import QApplication, QLabel, QPushButton

from superqt import QCollapsible
Expand Down
38 changes: 17 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ dependencies = [
[project.optional-dependencies]
test = ["pint", "pytest", "pytest-cov", "pytest-qt", "numpy", "cmap", "pyconify"]
dev = [
"black",
"ipython",
"ruff",
"mypy",
Expand All @@ -66,7 +65,8 @@ pyside2 = ["pyside2"]
# see issues surrounding usage of Generics in pyside6.5.x
# https://github.com/pyapp-kit/superqt/pull/177
# https://github.com/pyapp-kit/superqt/pull/164
pyside6 = ["pyside6 !=6.5.0,!=6.5.1"]
# https://bugreports.qt.io/browse/PYSIDE-2627
pyside6 = ["pyside6 !=6.5.0,!=6.5.1,!=6.6.2"]
pyqt5 = ["pyqt5"]
pyqt6 = ["pyqt6"]
font-fa5 = ["fonticon-fontawesome5"]
Expand Down Expand Up @@ -111,49 +111,44 @@ matrix.qt.extra-dependencies = [
{value = "pyqt5==5.12", if = ["pyqt5.12"]},
]

# https://pycqa.github.io/isort/docs/configuration/options.html
[tool.isort]
profile = "black"
src_paths = ["src/superqt", "tests"]

# https://github.com/charliermarsh/ruff
[tool.ruff]
line-length = 88
target-version = "py38"
src = ["src", "tests"]

# https://docs.astral.sh/ruff/rules
[tool.ruff.lint]
pydocstyle = { convention = "numpy" }
select = [
"E", # style errors
"W", # style warnings
"F", # flakes
"W", # flakes
"D", # pydocstyle
"D417", # Missing argument descriptions in Docstrings
"I", # isort
"UP", # pyupgrade
"S", # bandit
"C4", # flake8-comprehensions
"B", # flake8-bugbear
"A001", # flake8-builtins
"RUF", # ruff-specific rules
"TID", # tidy imports
"TCH", # flake8-type-checking
"TID", # flake8-tidy-imports
]
ignore = [
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D104", # Missing docstring in public package
"D107", # Missing docstring in __init__
"D203", # 1 blank line required before class docstring
"D212", # Multi-line docstring summary should start at the first line
"D213", # Multi-line docstring summary should start at the second line
"D401", # First line should be in imperative mood
"D413", # Missing blank line after last section
"D416", # Section name should end with a colon
"D401", # First line should be in imperative mood (remove to opt in)
]


[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/*.py" = ["D", "S101"]
"examples/demo_widget.py" = ["E501"]
"examples/*.py" = ["B", "D"]

# https://docs.astral.sh/ruff/formatter/
[tool.ruff.format]
docstring-code-format = true

# https://docs.pytest.org/en/6.2.x/customize.html
[tool.pytest.ini_options]
minversion = "6.0"
Expand Down Expand Up @@ -189,6 +184,7 @@ allow_redefinition = true
source = ["superqt"]

[tool.coverage.report]
show_missing = true
exclude_lines = [
"pragma: no cover",
"if TYPE_CHECKING:",
Expand Down
5 changes: 3 additions & 2 deletions src/superqt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""superqt is a collection of Qt components for python."""

from importlib.metadata import PackageNotFoundError, version
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -50,8 +51,8 @@
]

if TYPE_CHECKING:
from .combobox import QColormapComboBox
from .spinbox._quantity import QQuantity
from .combobox import QColormapComboBox # noqa: TCH004
from .spinbox._quantity import QQuantity # noqa: TCH004


def __getattr__(name: str) -> Any:
Expand Down
2 changes: 1 addition & 1 deletion src/superqt/cmap/_catalog_combo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from cmap import Colormap
from qtpy.QtCore import Qt, Signal
from qtpy.QtGui import QKeyEvent
from qtpy.QtWidgets import QComboBox, QCompleter, QWidget

from ._cmap_item_delegate import QColormapItemDelegate
Expand All @@ -13,6 +12,7 @@

if TYPE_CHECKING:
from cmap._catalog import Category, Interpolation
from qtpy.QtGui import QKeyEvent


class CmapCatalogComboBox(QComboBox):
Expand Down
6 changes: 4 additions & 2 deletions src/superqt/cmap/_cmap_item_delegate.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from __future__ import annotations

from typing import cast
from typing import TYPE_CHECKING, cast

from cmap import Colormap
from qtpy.QtCore import QModelIndex, QObject, QPersistentModelIndex, QRect, QSize, Qt
from qtpy.QtGui import QColor, QPainter
from qtpy.QtWidgets import QStyle, QStyledItemDelegate, QStyleOptionViewItem

from ._cmap_utils import CMAP_ROLE, draw_colormap, pick_font_color, try_cast_colormap

if TYPE_CHECKING:
from cmap import Colormap

DEFAULT_SIZE = QSize(80, 22)
DEFAULT_BORDER_COLOR = QColor(Qt.GlobalColor.transparent)

Expand Down
6 changes: 5 additions & 1 deletion src/superqt/cmap/_cmap_line_edit.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from __future__ import annotations

from cmap import Colormap
from typing import TYPE_CHECKING

from qtpy.QtCore import Qt
from qtpy.QtGui import QIcon, QPainter, QPaintEvent, QPalette
from qtpy.QtWidgets import QApplication, QLineEdit, QStyle, QWidget

from ._cmap_utils import draw_colormap, pick_font_color, try_cast_colormap

if TYPE_CHECKING:
from cmap import Colormap

MISSING = QStyle.StandardPixmap.SP_TitleBarContextHelpButton


Expand Down
4 changes: 3 additions & 1 deletion src/superqt/cmap/_cmap_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ def draw_colormap(
from qtpy.QtWidgets import QWidget
from superqt.utils import draw_colormap
viridis = 'viridis' # or cmap.Colormap('viridis')
viridis = "viridis" # or cmap.Colormap('viridis')
class W(QWidget):
def paintEvent(self, event) -> None:
draw_colormap(self, viridis, event.rect())
# or draw onto a QPixmap
pm = QPixmap(200, 200)
draw_colormap(pm, viridis)
Expand Down
1 change: 1 addition & 0 deletions src/superqt/collapsible/_collapsible.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A collapsible widget to hide and unhide child widgets."""

from __future__ import annotations

from qtpy.QtCore import (
Expand Down
2 changes: 1 addition & 1 deletion src/superqt/combobox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


if TYPE_CHECKING:
from superqt.cmap import QColormapComboBox
from superqt.cmap import QColormapComboBox # noqa: TCH004


def __getattr__(name: str) -> Any: # pragma: no cover
Expand Down
4 changes: 2 additions & 2 deletions src/superqt/fonticon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def icon(
plugin is installed)
>>> btn = QPushButton()
>>> btn.setIcon(icon('fa5s.smile'))
>>> btn.setIcon(icon("fa5s.smile"))
can also directly import from fonticon_fa5
>>> from fonticon_fa5 import FA5S
Expand All @@ -130,7 +130,7 @@ def icon(
... "disabled": {
... "color": "green",
... "scale_factor": 0.8,
... "animation": spin(btn)
... "animation": spin(btn),
... },
... },
... )
Expand Down
11 changes: 6 additions & 5 deletions src/superqt/fonticon/_qfont_icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections import abc, defaultdict
from dataclasses import dataclass
from pathlib import Path
from typing import ClassVar, DefaultDict, Sequence, Tuple, Union, cast
from typing import TYPE_CHECKING, ClassVar, DefaultDict, Sequence, Tuple, Union, cast

from qtpy import QT_VERSION
from qtpy.QtCore import QObject, QPoint, QRect, QSize, Qt
Expand All @@ -25,7 +25,8 @@

from superqt.utils import QMessageHandler

from ._animations import Animation
if TYPE_CHECKING:
from ._animations import Animation


class Unset:
Expand Down Expand Up @@ -157,9 +158,9 @@ class _QFontIconEngine(QIconEngine):

def __init__(self, options: _IconOptions):
super().__init__()
self._opts: defaultdict[
QIcon.State, dict[QIcon.Mode, _IconOptions | None]
] = DefaultDict(dict)
self._opts: defaultdict[QIcon.State, dict[QIcon.Mode, _IconOptions | None]] = (
DefaultDict(dict)
)
self._opts[QIcon.State.Off][QIcon.Mode.Normal] = options
self.update_hash()

Expand Down
2 changes: 2 additions & 0 deletions src/superqt/qtcompat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

# forward any requests for superqt.qtcompat.* to qtpy.*
class SuperQtImporter(abc.MetaPathFinder):
"""Pseudo-importer to forward superqt.qtcompat.* to qtpy.*."""

def find_spec(self, fullname: str, path, target=None): # type: ignore
"""Forward any requests for superqt.qtcompat.* to qtpy.*."""
if fullname.startswith(__name__):
Expand Down
1 change: 1 addition & 0 deletions src/superqt/sliders/_generic_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
scalar (with one handle per item), and it forms the basis of
QRangeSlider.
"""

import os
import platform
from typing import TypeVar
Expand Down
24 changes: 8 additions & 16 deletions src/superqt/sliders/_labeled.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,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 +261,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 +296,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 +539,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
Loading

0 comments on commit 16f9ef9

Please sign in to comment.