mirror of
https://github.com/pyapp-kit/superqt.git
synced 2025-12-16 11:10:06 +01:00
update pre-commit (#151)
This commit is contained in:
@@ -12,23 +12,23 @@ repos:
|
|||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
|
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/psf/black
|
||||||
rev: 22.10.0
|
rev: 23.1.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
|
|
||||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
||||||
rev: v0.0.165
|
rev: v0.0.254
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff
|
||||||
args: ["--fix"]
|
args: ["--fix"]
|
||||||
|
|
||||||
- repo: https://github.com/abravalheri/validate-pyproject
|
- repo: https://github.com/abravalheri/validate-pyproject
|
||||||
rev: v0.10.1
|
rev: v0.12.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: validate-pyproject
|
- id: validate-pyproject
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||||
rev: v0.991
|
rev: v1.1.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: mypy
|
- id: mypy
|
||||||
exclude: tests|examples
|
exclude: tests|examples
|
||||||
|
|||||||
@@ -104,7 +104,6 @@ def define_env(env: "MacrosPlugin"):
|
|||||||
out += f"- `{m.name}`\n\n"
|
out += f"- `{m.name}`\n\n"
|
||||||
|
|
||||||
if self_members:
|
if self_members:
|
||||||
|
|
||||||
out += dedent(
|
out += dedent(
|
||||||
f"""
|
f"""
|
||||||
## Methods
|
## Methods
|
||||||
|
|||||||
@@ -110,7 +110,6 @@ class DemoWidget(QtW.QWidget):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|||||||
@@ -369,7 +369,6 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
app = QtWidgets.QApplication(sys.argv)
|
app = QtWidgets.QApplication(sys.argv)
|
||||||
|
|||||||
@@ -98,25 +98,27 @@ src_paths = ["src/superqt", "tests"]
|
|||||||
line-length = 88
|
line-length = 88
|
||||||
target-version = "py37"
|
target-version = "py37"
|
||||||
src = ["src","tests"]
|
src = ["src","tests"]
|
||||||
extend-select = [
|
select = [
|
||||||
"E", # style errors
|
"E", # style errors
|
||||||
"F", # flakes
|
"F", # flakes
|
||||||
"D", # pydocstyle
|
"D", # pydocstyle
|
||||||
"I", # isort
|
"I", # isort
|
||||||
"U", # pyupgrade
|
"UP", # pyupgrade
|
||||||
# "N", # pep8-naming
|
|
||||||
"S", # bandit
|
"S", # bandit
|
||||||
"C", # flake8-comprehensions
|
"C", # flake8-comprehensions
|
||||||
"B", # flake8-bugbear
|
"B", # flake8-bugbear
|
||||||
"A001", # flake8-builtins
|
"A001", # flake8-builtins
|
||||||
"RUF", # ruff-specific rules
|
"RUF", # ruff-specific rules
|
||||||
]
|
]
|
||||||
extend-ignore = [
|
ignore = [
|
||||||
"D100", # Missing docstring in public module
|
"D100", # Missing docstring in public module
|
||||||
|
"D101", # Missing docstring in public class
|
||||||
|
"D104", # Missing docstring in public package
|
||||||
"D107", # Missing docstring in __init__
|
"D107", # Missing docstring in __init__
|
||||||
"D203", # 1 blank line required before class docstring
|
"D203", # 1 blank line required before class docstring
|
||||||
"D212", # Multi-line docstring summary should start at the first line
|
"D212", # Multi-line docstring summary should start at the first line
|
||||||
"D213", # Multi-line docstring summary should start at the second 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
|
"D413", # Missing blank line after last section
|
||||||
"D416", # Section name should end with a colon
|
"D416", # Section name should end with a colon
|
||||||
"C901", # Function is too complex
|
"C901", # Function is too complex
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ class QEnumComboBox(QComboBox):
|
|||||||
super().addItems(list(map(_get_name, self._enum_class.__members__.values())))
|
super().addItems(list(map(_get_name, self._enum_class.__members__.values())))
|
||||||
|
|
||||||
def enumClass(self) -> Optional[EnumMeta]:
|
def enumClass(self) -> Optional[EnumMeta]:
|
||||||
"""return current Enum class."""
|
"""Return current Enum class."""
|
||||||
return self._enum_class
|
return self._enum_class
|
||||||
|
|
||||||
def isOptional(self) -> bool:
|
def isOptional(self) -> bool:
|
||||||
"""return if current enum is with optional annotation."""
|
"""Return if current enum is with optional annotation."""
|
||||||
return self._allow_none
|
return self._allow_none
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import contextlib
|
||||||
from typing import Dict, List, Set, Tuple
|
from typing import Dict, List, Set, Tuple
|
||||||
|
|
||||||
from ._iconfont import IconFontMeta, namespace2font
|
from ._iconfont import IconFontMeta, namespace2font
|
||||||
@@ -9,7 +10,6 @@ except ImportError:
|
|||||||
|
|
||||||
|
|
||||||
class FontIconManager:
|
class FontIconManager:
|
||||||
|
|
||||||
ENTRY_POINT = "superqt.fonticon"
|
ENTRY_POINT = "superqt.fonticon"
|
||||||
_PLUGINS: Dict[str, EntryPoint] = {}
|
_PLUGINS: Dict[str, EntryPoint] = {}
|
||||||
_LOADED: Dict[str, IconFontMeta] = {}
|
_LOADED: Dict[str, IconFontMeta] = {}
|
||||||
@@ -98,10 +98,8 @@ def loaded(load_all=False) -> Dict[str, List[str]]:
|
|||||||
if load_all:
|
if load_all:
|
||||||
discover()
|
discover()
|
||||||
for x in available():
|
for x in available():
|
||||||
try:
|
with contextlib.suppress(Exception):
|
||||||
_manager._get_font_class(x)
|
_manager._get_font_class(x)
|
||||||
except Exception:
|
|
||||||
continue
|
|
||||||
return {
|
return {
|
||||||
key: sorted(filter(lambda x: not x.startswith("_"), cls.__dict__))
|
key: sorted(filter(lambda x: not x.startswith("_"), cls.__dict__))
|
||||||
for key, cls in _manager._LOADED.items()
|
for key, cls in _manager._LOADED.items()
|
||||||
|
|||||||
@@ -345,7 +345,6 @@ class QFontIcon(QIcon):
|
|||||||
|
|
||||||
|
|
||||||
class QFontIconStore(QObject):
|
class QFontIconStore(QObject):
|
||||||
|
|
||||||
# map of key -> (font_family, font_style)
|
# map of key -> (font_family, font_style)
|
||||||
_LOADED_KEYS: dict[str, tuple[str, str]] = {}
|
_LOADED_KEYS: dict[str, tuple[str, str]] = {}
|
||||||
|
|
||||||
@@ -398,7 +397,7 @@ class QFontIconStore(QObject):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _ensure_char(cls, char: str, family: str, style: str) -> str:
|
def _ensure_char(cls, char: str, family: str, style: str) -> str:
|
||||||
"""make sure that `char` is a glyph provided by `family` and `style`."""
|
"""Make sure that `char` is a glyph provided by `family` and `style`."""
|
||||||
if len(char) == 1 and ord(char) > 256:
|
if len(char) == 1 and ord(char) > 256:
|
||||||
return char
|
return char
|
||||||
try:
|
try:
|
||||||
@@ -432,7 +431,7 @@ class QFontIconStore(QObject):
|
|||||||
def addFont(
|
def addFont(
|
||||||
cls, filepath: str, prefix: str, charmap: dict[str, str] | None = None
|
cls, filepath: str, prefix: str, charmap: dict[str, str] | None = None
|
||||||
) -> tuple[str, str] | None:
|
) -> tuple[str, str] | None:
|
||||||
"""Add font at `filepath` to the registry under `key`.
|
r"""Add font at `filepath` to the registry under `key`.
|
||||||
|
|
||||||
If you'd like to later use a fontkey in the form of `key.some-name`, then
|
If you'd like to later use a fontkey in the form of `key.some-name`, then
|
||||||
`charmap` must be provided and provide a mapping for all of the glyph names
|
`charmap` must be provided and provide a mapping for all of the glyph names
|
||||||
@@ -477,7 +476,7 @@ class QFontIconStore(QObject):
|
|||||||
family: str = families[0]
|
family: str = families[0]
|
||||||
|
|
||||||
# in Qt6, everything becomes a static member
|
# in Qt6, everything becomes a static member
|
||||||
QFd: QFontDatabase | "type[QFontDatabase]" = (
|
QFd: QFontDatabase | type[QFontDatabase] = (
|
||||||
QFontDatabase()
|
QFontDatabase()
|
||||||
if tuple(cast(str, QT_VERSION).split(".")) < ("6", "0")
|
if tuple(cast(str, QT_VERSION).split(".")) < ("6", "0")
|
||||||
else QFontDatabase
|
else QFontDatabase
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ warnings.warn(
|
|||||||
# forward any requests for superqt.qtcompat.* to qtpy.*
|
# forward any requests for superqt.qtcompat.* to qtpy.*
|
||||||
class SuperQtImporter(abc.MetaPathFinder):
|
class SuperQtImporter(abc.MetaPathFinder):
|
||||||
def find_spec(self, fullname: str, path, target=None): # type: ignore
|
def find_spec(self, fullname: str, path, target=None): # type: ignore
|
||||||
|
"""Forward any requests for superqt.qtcompat.* to qtpy.*."""
|
||||||
if fullname.startswith(__name__):
|
if fullname.startswith(__name__):
|
||||||
return util.find_spec(fullname.replace(__name__, "qtpy"))
|
return util.find_spec(fullname.replace(__name__, "qtpy"))
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ class _GenericSlider(QSlider, Generic[_T]):
|
|||||||
MAX_DISPLAY = 5000
|
MAX_DISPLAY = 5000
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs) -> None:
|
def __init__(self, *args, **kwargs) -> None:
|
||||||
|
|
||||||
self._minimum = 0.0
|
self._minimum = 0.0
|
||||||
self._maximum = 99.0
|
self._maximum = 99.0
|
||||||
self._pageStep = 10.0
|
self._pageStep = 10.0
|
||||||
@@ -276,7 +275,6 @@ class _GenericSlider(QSlider, Generic[_T]):
|
|||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def wheelEvent(self, e: QtGui.QWheelEvent) -> None:
|
def wheelEvent(self, e: QtGui.QWheelEvent) -> None:
|
||||||
|
|
||||||
e.ignore()
|
e.ignore()
|
||||||
vertical = bool(e.angleDelta().y())
|
vertical = bool(e.angleDelta().y())
|
||||||
delta = e.angleDelta().y() if vertical else e.angleDelta().x()
|
delta = e.angleDelta().y() if vertical else e.angleDelta().x()
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import contextlib
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import Any
|
from typing import Any
|
||||||
@@ -566,10 +567,8 @@ class SliderLabel(QDoubleSpinBox):
|
|||||||
if opt == EdgeLabelMode.LabelIsRange:
|
if opt == EdgeLabelMode.LabelIsRange:
|
||||||
self.setMinimum(-9999999)
|
self.setMinimum(-9999999)
|
||||||
self.setMaximum(9999999)
|
self.setMaximum(9999999)
|
||||||
try:
|
with contextlib.suppress(Exception):
|
||||||
self._slider.rangeChanged.disconnect(self.setRange)
|
self._slider.rangeChanged.disconnect(self.setRange)
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
self.setMinimum(self._slider.minimum())
|
self.setMinimum(self._slider.minimum())
|
||||||
self.setMaximum(self._slider.maximum())
|
self.setMaximum(self._slider.maximum())
|
||||||
|
|||||||
@@ -260,7 +260,6 @@ def parse_color(color: str, default_attr) -> QColor | QGradient:
|
|||||||
|
|
||||||
|
|
||||||
def update_styles_from_stylesheet(obj: _GenericRangeSlider):
|
def update_styles_from_stylesheet(obj: _GenericRangeSlider):
|
||||||
|
|
||||||
qss: str = obj.styleSheet()
|
qss: str = obj.styleSheet()
|
||||||
|
|
||||||
parent = obj.parent()
|
parent = obj.parent()
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ from pygments.lexers import find_lexer_class, get_lexer_by_name
|
|||||||
from pygments.util import ClassNotFound
|
from pygments.util import ClassNotFound
|
||||||
from qtpy import QtGui
|
from qtpy import QtGui
|
||||||
|
|
||||||
|
|
||||||
# inspired by https://github.com/Vector35/snippets/blob/master/QCodeEditor.py
|
# inspired by https://github.com/Vector35/snippets/blob/master/QCodeEditor.py
|
||||||
# (MIT license) and
|
# (MIT license) and
|
||||||
# https://pygments.org/docs/formatterdevelopment/#html-3-2-formatter
|
# https://pygments.org/docs/formatterdevelopment/#html-3-2-formatter
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ def as_generator_function(
|
|||||||
|
|
||||||
|
|
||||||
class WorkerBaseSignals(QObject):
|
class WorkerBaseSignals(QObject):
|
||||||
|
|
||||||
started = Signal() # emitted when the work is started
|
started = Signal() # emitted when the work is started
|
||||||
finished = Signal() # emitted when the work is finished
|
finished = Signal() # emitted when the work is finished
|
||||||
_finished = Signal(object) # emitted when the work is finished to delete
|
_finished = Signal(object) # emitted when the work is finished to delete
|
||||||
@@ -358,7 +357,6 @@ class FunctionWorker(WorkerBase[_R]):
|
|||||||
|
|
||||||
|
|
||||||
class GeneratorWorkerSignals(WorkerBaseSignals):
|
class GeneratorWorkerSignals(WorkerBaseSignals):
|
||||||
|
|
||||||
yielded = Signal(object) # emitted with yielded values (if generator used)
|
yielded = Signal(object) # emitted with yielded values (if generator used)
|
||||||
paused = Signal() # emitted when a running job has successfully paused
|
paused = Signal() # emitted when a running job has successfully paused
|
||||||
resumed = Signal() # emitted when a paused job has successfully resumed
|
resumed = Signal() # emitted when a paused job has successfully resumed
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ class EmissionPolicy(IntFlag):
|
|||||||
|
|
||||||
|
|
||||||
class GenericSignalThrottler(QObject):
|
class GenericSignalThrottler(QObject):
|
||||||
|
|
||||||
triggered = Signal()
|
triggered = Signal()
|
||||||
timeoutChanged = Signal(int)
|
timeoutChanged = Signal(int)
|
||||||
timerTypeChanged = Signal(Qt.TimerType)
|
timerTypeChanged = Signal(Qt.TimerType)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ FIXTURES = Path(__file__).parent / "fixtures"
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def plugin_store(qapp, monkeypatch):
|
def plugin_store(qapp, monkeypatch):
|
||||||
_path = [str(FIXTURES)] + sys.path.copy()
|
_path = [str(FIXTURES), *sys.path.copy()]
|
||||||
store = QFontIconStore().instance()
|
store = QFontIconStore().instance()
|
||||||
with monkeypatch.context() as m:
|
with monkeypatch.context() as m:
|
||||||
m.setattr(sys, "path", _path)
|
m.setattr(sys, "path", _path)
|
||||||
|
|||||||
@@ -116,7 +116,6 @@ def test_press_move_release(gslider: _GenericSlider, qtbot):
|
|||||||
|
|
||||||
@skip_on_linux_qt6
|
@skip_on_linux_qt6
|
||||||
def test_hover(gslider: _GenericSlider):
|
def test_hover(gslider: _GenericSlider):
|
||||||
|
|
||||||
# stub
|
# stub
|
||||||
opt = QStyleOptionSlider()
|
opt = QStyleOptionSlider()
|
||||||
gslider.initStyleOption(opt)
|
gslider.initStyleOption(opt)
|
||||||
|
|||||||
@@ -154,7 +154,6 @@ def test_press_move_release(sld: _GenericSlider, qtbot):
|
|||||||
|
|
||||||
@skip_on_linux_qt6
|
@skip_on_linux_qt6
|
||||||
def test_hover(sld: _GenericSlider):
|
def test_hover(sld: _GenericSlider):
|
||||||
|
|
||||||
_real_sld = getattr(sld, "_slider", sld)
|
_real_sld = getattr(sld, "_slider", sld)
|
||||||
|
|
||||||
opt = QStyleOptionSlider()
|
opt = QStyleOptionSlider()
|
||||||
@@ -179,7 +178,6 @@ def test_hover(sld: _GenericSlider):
|
|||||||
|
|
||||||
|
|
||||||
def test_wheel(sld: _GenericSlider, qtbot):
|
def test_wheel(sld: _GenericSlider, qtbot):
|
||||||
|
|
||||||
if type(sld) is QLabeledSlider and QT_VERSION < (5, 12):
|
if type(sld) is QLabeledSlider and QT_VERSION < (5, 12):
|
||||||
pytest.skip()
|
pytest.skip()
|
||||||
|
|
||||||
@@ -200,7 +198,6 @@ def test_position(sld: _GenericSlider, qtbot):
|
|||||||
|
|
||||||
|
|
||||||
def test_steps(sld: _GenericSlider, qtbot):
|
def test_steps(sld: _GenericSlider, qtbot):
|
||||||
|
|
||||||
sld.setSingleStep(11)
|
sld.setSingleStep(11)
|
||||||
assert sld.singleStep() == 11
|
assert sld.singleStep() == 11
|
||||||
|
|
||||||
@@ -208,7 +205,6 @@ def test_steps(sld: _GenericSlider, qtbot):
|
|||||||
assert sld.pageStep() == 16
|
assert sld.pageStep() == 16
|
||||||
|
|
||||||
if type(sld) is not QLabeledSlider:
|
if type(sld) is not QLabeledSlider:
|
||||||
|
|
||||||
sld.setSingleStep(0.1)
|
sld.setSingleStep(0.1)
|
||||||
assert sld.singleStep() == 0.1
|
assert sld.singleStep() == 0.1
|
||||||
|
|
||||||
|
|||||||
6
tox.ini
6
tox.ini
@@ -46,7 +46,11 @@ platform =
|
|||||||
macos: darwin
|
macos: darwin
|
||||||
linux: linux
|
linux: linux
|
||||||
windows: win32
|
windows: win32
|
||||||
passenv = CI GITHUB_ACTIONS DISPLAY XAUTHORITY
|
passenv =
|
||||||
|
CI
|
||||||
|
GITHUB_ACTIONS
|
||||||
|
DISPLAY
|
||||||
|
XAUTHORITY
|
||||||
deps =
|
deps =
|
||||||
pyqt512: pyqt5==5.12.*
|
pyqt512: pyqt5==5.12.*
|
||||||
pyside512: pyside2==5.12.*
|
pyside512: pyside2==5.12.*
|
||||||
|
|||||||
Reference in New Issue
Block a user