From c6d5ad6ce0410a828d65a8c4cf1356dab2ed69a2 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 10 Feb 2024 12:56:52 -0600 Subject: [PATCH] Unpin pytest-asyncio and update ruff config (#1209) --- docs/conf.py | 2 +- hatch_build.py | 1 - ipykernel/__init__.py | 2 +- ipykernel/compiler.py | 2 +- ipykernel/datapub.py | 18 +++++------ ipykernel/debugger.py | 2 +- ipykernel/eventloops.py | 10 +++--- ipykernel/gui/gtk3embed.py | 10 +++--- ipykernel/gui/gtkembed.py | 8 ++--- ipykernel/ipkernel.py | 2 +- ipykernel/kernelspec.py | 3 +- ipykernel/pickleutil.py | 18 +++++------ ipykernel/pylab/backend_inline.py | 2 +- ipykernel/pylab/config.py | 2 +- ipykernel/serialize.py | 15 +++++---- pyproject.toml | 52 +++++++++++++++++-------------- 16 files changed, 74 insertions(+), 75 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 643740ec0..4bb599327 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -37,7 +37,7 @@ ] try: - import enchant + import enchant # noqa: F401 extensions += ["sphinxcontrib.spelling"] except ImportError: diff --git a/hatch_build.py b/hatch_build.py index 410b4603e..934348050 100644 --- a/hatch_build.py +++ b/hatch_build.py @@ -1,5 +1,4 @@ """A custom hatch build hook for ipykernel.""" -import os import shutil import sys from pathlib import Path diff --git a/ipykernel/__init__.py b/ipykernel/__init__.py index bc5fbb726..978700d30 100644 --- a/ipykernel/__init__.py +++ b/ipykernel/__init__.py @@ -4,4 +4,4 @@ kernel_protocol_version_info, version_info, ) -from .connect import * +from .connect import * # noqa: F403 diff --git a/ipykernel/compiler.py b/ipykernel/compiler.py index 0657f5693..e42007ed6 100644 --- a/ipykernel/compiler.py +++ b/ipykernel/compiler.py @@ -45,7 +45,7 @@ def murmur2_x86(data, seed): return h -convert_to_long_pathname = lambda filename: filename +convert_to_long_pathname = lambda filename: filename # noqa: E731 if sys.platform == "win32": try: diff --git a/ipykernel/datapub.py b/ipykernel/datapub.py index 5805c9afd..cc19696db 100644 --- a/ipykernel/datapub.py +++ b/ipykernel/datapub.py @@ -1,17 +1,11 @@ +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. + """Publishing native (typically pickled) objects. """ import warnings -warnings.warn( - "ipykernel.datapub is deprecated. It has moved to ipyparallel.datapub", - DeprecationWarning, - stacklevel=2, -) - -# Copyright (c) IPython Development Team. -# Distributed under the terms of the Modified BSD License. - from traitlets import Any, CBytes, Dict, Instance from traitlets.config import Configurable @@ -26,6 +20,12 @@ from jupyter_client.session import Session, extract_header +warnings.warn( + "ipykernel.datapub is deprecated. It has moved to ipyparallel.datapub", + DeprecationWarning, + stacklevel=2, +) + class ZMQDataPublisher(Configurable): """A zmq data publisher.""" diff --git a/ipykernel/debugger.py b/ipykernel/debugger.py index 728d2dae9..fd192e157 100644 --- a/ipykernel/debugger.py +++ b/ipykernel/debugger.py @@ -21,7 +21,7 @@ try: # This import is required to have the next ones working... - from debugpy.server import api + from debugpy.server import api # noqa: F401 from _pydevd_bundle import pydevd_frame_utils # isort: skip from _pydevd_bundle.pydevd_suspended_frames import ( # isort: skip diff --git a/ipykernel/eventloops.py b/ipykernel/eventloops.py index 401aebd3e..c3ddd301e 100644 --- a/ipykernel/eventloops.py +++ b/ipykernel/eventloops.py @@ -484,24 +484,24 @@ def set_qt_api_env_from_gui(gui): else: if gui == "qt5": try: - import PyQt5 + import PyQt5 # noqa: F401 os.environ["QT_API"] = "pyqt5" except ImportError: try: - import PySide2 + import PySide2 # noqa: F401 os.environ["QT_API"] = "pyside2" except ImportError: os.environ["QT_API"] = "pyqt5" elif gui == "qt6": try: - import PyQt6 + import PyQt6 # noqa: F401 os.environ["QT_API"] = "pyqt6" except ImportError: try: - import PySide6 + import PySide6 # noqa: F401 os.environ["QT_API"] = "pyside6" except ImportError: @@ -516,7 +516,7 @@ def set_qt_api_env_from_gui(gui): # Do the actual import now that the environment variable is set to make sure it works. try: - from IPython.external.qt_for_kernel import QtCore, QtGui + pass except Exception as e: # Clear the environment variable for the next attempt. if "QT_API" in os.environ: diff --git a/ipykernel/gui/gtk3embed.py b/ipykernel/gui/gtk3embed.py index f270b5dd0..3317ecfe4 100644 --- a/ipykernel/gui/gtk3embed.py +++ b/ipykernel/gui/gtk3embed.py @@ -14,16 +14,16 @@ import sys import warnings -warnings.warn( - "The Gtk3 event loop for ipykernel is deprecated", category=DeprecationWarning, stacklevel=2 -) - # Third-party import gi gi.require_version("Gdk", "3.0") gi.require_version("Gtk", "3.0") -from gi.repository import GObject, Gtk +from gi.repository import GObject, Gtk # noqa: E402 + +warnings.warn( + "The Gtk3 event loop for ipykernel is deprecated", category=DeprecationWarning, stacklevel=2 +) # ----------------------------------------------------------------------------- # Classes and functions diff --git a/ipykernel/gui/gtkembed.py b/ipykernel/gui/gtkembed.py index f6b8bf5bb..e87249ead 100644 --- a/ipykernel/gui/gtkembed.py +++ b/ipykernel/gui/gtkembed.py @@ -14,14 +14,14 @@ import sys import warnings -warnings.warn( - "The Gtk3 event loop for ipykernel is deprecated", category=DeprecationWarning, stacklevel=2 -) - # Third-party import gobject import gtk +warnings.warn( + "The Gtk3 event loop for ipykernel is deprecated", category=DeprecationWarning, stacklevel=2 +) + # ----------------------------------------------------------------------------- # Classes and functions # ----------------------------------------------------------------------------- diff --git a/ipykernel/ipkernel.py b/ipykernel/ipkernel.py index 40d57945f..9bea4d56b 100644 --- a/ipykernel/ipkernel.py +++ b/ipykernel/ipkernel.py @@ -381,7 +381,7 @@ async def do_execute( should_run_async = shell.should_run_async accepts_params = _accepts_parameters(run_cell, ["cell_id"]) else: - should_run_async = lambda cell: False # noqa: ARG005 + should_run_async = lambda cell: False # noqa: ARG005, E731 # older IPython, # use blocking run_cell and wrap it in coroutine diff --git a/ipykernel/kernelspec.py b/ipykernel/kernelspec.py index ae77d9cc8..a1d508c38 100644 --- a/ipykernel/kernelspec.py +++ b/ipykernel/kernelspec.py @@ -17,6 +17,7 @@ from jupyter_client.kernelspec import KernelSpecManager from traitlets import Unicode +from traitlets.config import Application try: from .debugger import _is_debugpy_available @@ -171,8 +172,6 @@ def install( # Entrypoint -from traitlets.config import Application - class InstallIPythonKernelSpecApp(Application): """Dummy app wrapping argparse""" diff --git a/ipykernel/pickleutil.py b/ipykernel/pickleutil.py index a52115da2..c6a2e4484 100644 --- a/ipykernel/pickleutil.py +++ b/ipykernel/pickleutil.py @@ -2,25 +2,23 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -import typing -import warnings - -warnings.warn( - "ipykernel.pickleutil is deprecated. It has moved to ipyparallel.", - DeprecationWarning, - stacklevel=2, -) - import copy import pickle import sys +import typing +import warnings from types import FunctionType # This registers a hook when it's imported -from ipyparallel.serialize import codeutil from traitlets.log import get_logger from traitlets.utils.importstring import import_item +warnings.warn( + "ipykernel.pickleutil is deprecated. It has moved to ipyparallel.", + DeprecationWarning, + stacklevel=2, +) + buffer = memoryview class_type = type diff --git a/ipykernel/pylab/backend_inline.py b/ipykernel/pylab/backend_inline.py index cbc253064..fdeece28c 100644 --- a/ipykernel/pylab/backend_inline.py +++ b/ipykernel/pylab/backend_inline.py @@ -5,7 +5,7 @@ import warnings -from matplotlib_inline.backend_inline import * # type:ignore[import-untyped] # analysis: ignore +from matplotlib_inline.backend_inline import * # type:ignore[import-untyped] # noqa: F403 # analysis: ignore warnings.warn( "`ipykernel.pylab.backend_inline` is deprecated, directly " diff --git a/ipykernel/pylab/config.py b/ipykernel/pylab/config.py index f32787283..0048bbf84 100644 --- a/ipykernel/pylab/config.py +++ b/ipykernel/pylab/config.py @@ -5,7 +5,7 @@ import warnings -from matplotlib_inline.config import * # type:ignore[import-untyped] # analysis: ignore +from matplotlib_inline.config import * # type:ignore[import-untyped] # noqa: F403 # analysis: ignore warnings.warn( "`ipykernel.pylab.config` is deprecated, directly use `matplotlib_inline.config`", diff --git a/ipykernel/serialize.py b/ipykernel/serialize.py index 616410c81..22ba5396e 100644 --- a/ipykernel/serialize.py +++ b/ipykernel/serialize.py @@ -3,15 +3,8 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -import warnings - -warnings.warn( - "ipykernel.serialize is deprecated. It has moved to ipyparallel.serialize", - DeprecationWarning, - stacklevel=2, -) - import pickle +import warnings from itertools import chain try: @@ -41,6 +34,12 @@ from jupyter_client.session import MAX_BYTES, MAX_ITEMS +warnings.warn( + "ipykernel.serialize is deprecated. It has moved to ipyparallel.serialize", + DeprecationWarning, + stacklevel=2, +) + # ----------------------------------------------------------------------------- # Serialization Functions # ----------------------------------------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index 3d45d68ee..532b8ffbb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,7 +53,7 @@ test = [ "flaky", "ipyparallel", "pre-commit", - "pytest-asyncio==0.23.4", + "pytest-asyncio>=0.23.5", "pytest-timeout" ] cov = [ @@ -209,29 +209,29 @@ omit = [ line-length = 100 [tool.ruff.lint] -select = [ - "B", # flake8-bugbear - "I", # isort - "ARG", # flake8-unused-arguments - "C4", # flake8-comprehensions - "EM", # flake8-errmsg - "ICN", # flake8-import-conventions - "G", # flake8-logging-format - "PGH", # pygrep-hooks - "PIE", # flake8-pie - "PL", # pylint - "PT", # flake8-pytest-style - "PTH", # flake8-use-pathlib - "RET", # flake8-return - "RUF", # Ruff-specific - "SIM", # flake8-simplify - "T20", # flake8-print - "UP", # pyupgrade - "YTT", # flake8-2020 - "EXE", # flake8-executable - "NPY", # NumPy specific rules - "PD", # pandas-vet - "PYI", # flake8-pyi +extend-select = [ + "B", # flake8-bugbear + "I", # isort + "ARG", # flake8-unused-arguments + "C4", # flake8-comprehensions + "EM", # flake8-errmsg + "ICN", # flake8-import-conventions + "G", # flake8-logging-format + "PGH", # pygrep-hooks + "PIE", # flake8-pie + "PL", # pylint + "PT", # flake8-pytest-style + "PTH", # flake8-use-pathlib + "RET", # flake8-return + "RUF", # Ruff-specific + "SIM", # flake8-simplify + "T20", # flake8-print + "UP", # pyupgrade + "YTT", # flake8-2020 + "EXE", # flake8-executable + "NPY", # NumPy specific rules + "PD", # pandas-vet + "PYI", # flake8-pyi ] ignore = [ "PLR", # Design related pylint codes @@ -265,6 +265,9 @@ unfixable = [ "T201", # Don't touch noqa lines "RUF100", + # Don't touch imports + "F401", + "F403" ] [tool.ruff.lint.per-file-ignores] @@ -277,6 +280,7 @@ unfixable = [ # B018 Found useless expression. Either assign it to a variable or remove it. # S603 `subprocess` call: check for execution of untrusted input "tests/*" = ["B011", "C408", "T201", "B007", "EM", "PTH", "PLW", "PLC1901", "B018", "S603", "ARG", "RET", "PGH"] +"*/__init__.py" = ["F401"] [tool.interrogate] ignore-init-module=true