Skip to content

Commit

Permalink
Adopt ruff and address lint (#1046)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Dec 7, 2022
1 parent f38738d commit 4dc3033
Show file tree
Hide file tree
Showing 44 changed files with 222 additions and 208 deletions.
6 changes: 4 additions & 2 deletions .github/dependabot.yml
@@ -1,8 +1,10 @@
version: 2
updates:
# Set update schedule for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every weekday
interval: "weekly"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -66,12 +66,18 @@ jobs:
cd $HOME
python -m ipykernel_launcher --help
pre_commit:
test_lint:
name: Test Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- uses: jupyterlab/maintainer-tools/.github/actions/pre-commit@v1
- name: Run Linters
run: |
hatch run typing:test
hatch run lint:style
pipx run 'validate-pyproject[all]' pyproject.toml
pipx run doc8 --max-line-length=200
check_release:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -177,7 +183,7 @@ jobs:
- test_docs
- test_without_debugpy
- test_miniumum_versions
- pre_commit
- test_lint
- test_prereleases
- check_release
- link_check
Expand Down
84 changes: 13 additions & 71 deletions .pre-commit-config.yaml
@@ -1,3 +1,6 @@
ci:
autoupdate_schedule: monthly

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand All @@ -10,88 +13,27 @@ repos:
- id: check-case-conflict
- id: check-toml
- id: check-yaml
- id: debug-statements
exclude: ipykernel/kernelapp.py
- id: forbid-new-submodules
- id: check-builtin-literals
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
args: ["--line-length", "100"]

- repo: https://github.com/Carreau/velin
rev: 0.0.12
hooks:
- id: velin
args: ["ipykernel"]

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
files: \.py$
args: [--profile=black]

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.10.1
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.19.2
hooks:
- id: validate-pyproject
stages: [manual]
- id: check-github-workflows

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
hooks:
- id: mdformat
additional_dependencies:
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.0
hooks:
- id: pyupgrade
args: [--py38-plus]

- repo: https://github.com/PyCQA/doc8
rev: v1.0.0
hooks:
- id: doc8
args: [--max-line-length=200]
stages: [manual]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy
exclude: "ipykernel.*tests"
args: ["--config-file", "pyproject.toml"]
additional_dependencies:
[tornado, jupyter_client, pytest, traitlets, jupyter_core]
stages: [manual]

- repo: https://github.com/john-hen/Flake8-pyproject
rev: 1.2.2
hooks:
- id: Flake8-pyproject
alias: flake8
additional_dependencies:
["flake8-bugbear==22.6.22", "flake8-implicit-str-concat==0.2.0"]
stages: [manual]

- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.29.0
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: eslint
stages: [manual]
- id: black

- repo: https://github.com/sirosen/check-jsonschema
rev: 0.19.2
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.165
hooks:
- id: check-jsonschema
name: "Check GitHub Workflows"
files: ^\.github/workflows/
types: [yaml]
args: ["--schemafile", "https://json.schemastore.org/github-workflow"]
stages: [manual]
- id: ruff
args: ["--fix"]
2 changes: 1 addition & 1 deletion docs/conf.py
Expand Up @@ -66,7 +66,7 @@
here = os.path.dirname(__file__)
version_py = os.path.join(here, os.pardir, "ipykernel", "_version.py")
with open(version_py) as f:
exec(compile(f.read(), version_py, "exec"), version_ns)
exec(compile(f.read(), version_py, "exec"), version_ns) # noqa

# The short X.Y version.
version = "%i.%i" % version_ns["version_info"][:2]
Expand Down
5 changes: 1 addition & 4 deletions examples/embedding/inprocess_qtconsole.py
Expand Up @@ -30,10 +30,7 @@ def init_asyncio_patch():
import asyncio

try:
from asyncio import (
WindowsProactorEventLoopPolicy,
WindowsSelectorEventLoopPolicy,
)
from asyncio import WindowsProactorEventLoopPolicy, WindowsSelectorEventLoopPolicy
except ImportError:
pass
# not affected
Expand Down
5 changes: 1 addition & 4 deletions examples/embedding/inprocess_terminal.py
Expand Up @@ -30,10 +30,7 @@ def init_asyncio_patch():
import asyncio

try:
from asyncio import (
WindowsProactorEventLoopPolicy,
WindowsSelectorEventLoopPolicy,
)
from asyncio import WindowsProactorEventLoopPolicy, WindowsSelectorEventLoopPolicy
except ImportError:
pass
# not affected
Expand Down
2 changes: 1 addition & 1 deletion examples/embedding/internal_ipkernel.py
Expand Up @@ -19,7 +19,7 @@ def mpl_kernel(gui):
[
"python",
"--matplotlib=%s" % gui,
#'--log-level=10' # noqa
#'--log-level=10'
]
)
return kernel
Expand Down
1 change: 1 addition & 0 deletions examples/embedding/ipkernel_wxapp.py
Expand Up @@ -24,6 +24,7 @@
import wx
from internal_ipkernel import InternalIPKernel


# -----------------------------------------------------------------------------
# Functions and classes
# -----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/_eventloop_macos.py
Expand Up @@ -75,7 +75,7 @@ def C(classname):
CFRunLoopAddTimer.restype = None
CFRunLoopAddTimer.argtypes = [void_p, void_p, void_p]

kCFRunLoopCommonModes = void_p.in_dll(CoreFoundation, "kCFRunLoopCommonModes")
kCFRunLoopCommonModes = void_p.in_dll(CoreFoundation, "kCFRunLoopCommonModes") # noqa


def _NSApp():
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/comm/__init__.py
@@ -1,4 +1,4 @@
__all__ = ["Comm", "CommManager"]

from .comm import Comm # noqa
from .comm import Comm
from .manager import CommManager
2 changes: 1 addition & 1 deletion ipykernel/connect.py
Expand Up @@ -120,7 +120,7 @@ def connect_qtconsole(connection_file=None, argv=None):
stdout=PIPE,
stderr=PIPE,
close_fds=(sys.platform != "win32"),
**kwargs
**kwargs,
)


Expand Down
1 change: 1 addition & 0 deletions ipykernel/embed.py
Expand Up @@ -10,6 +10,7 @@

from .kernelapp import IPKernelApp


# -----------------------------------------------------------------------------
# Code
# -----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/eventloops.py
Expand Up @@ -9,7 +9,7 @@
from functools import partial

import zmq
from packaging.version import Version as V
from packaging.version import Version as V # noqa
from traitlets.config.application import Application


Expand Down
1 change: 1 addition & 0 deletions ipykernel/gui/gtk3embed.py
Expand Up @@ -23,6 +23,7 @@
gi.require_version("Gtk", "3.0")
from gi.repository import GObject, Gtk


# -----------------------------------------------------------------------------
# Classes and functions
# -----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions ipykernel/gui/gtkembed.py
Expand Up @@ -20,6 +20,7 @@
import gobject
import gtk


# -----------------------------------------------------------------------------
# Classes and functions
# -----------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion ipykernel/heartbeat.py
Expand Up @@ -20,13 +20,14 @@
import zmq
from jupyter_client.localinterfaces import localhost


# -----------------------------------------------------------------------------
# Code
# -----------------------------------------------------------------------------


class Heartbeat(Thread):
"A simple ping-pong style heartbeat that runs in a thread."
"""A simple ping-pong style heartbeat that runs in a thread."""

def __init__(self, context, addr=None):
if addr is None:
Expand Down
1 change: 1 addition & 0 deletions ipykernel/inprocess/channels.py
Expand Up @@ -7,6 +7,7 @@

from jupyter_client.channelsabc import HBChannelABC


# -----------------------------------------------------------------------------
# Channel classes
# -----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions ipykernel/inprocess/client.py
Expand Up @@ -27,6 +27,7 @@
# Local imports
from .channels import InProcessChannel, InProcessHBChannel


# -----------------------------------------------------------------------------
# Main kernel Client class
# -----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions ipykernel/inprocess/ipkernel.py
Expand Up @@ -18,6 +18,7 @@
from .constants import INPROCESS_KEY
from .socket import DummySocket


# -----------------------------------------------------------------------------
# Main kernel class
# -----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions ipykernel/inprocess/socket.py
Expand Up @@ -8,6 +8,7 @@
import zmq
from traitlets import HasTraits, Instance, Int


# -----------------------------------------------------------------------------
# Dummy socket class
# -----------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions ipykernel/inprocess/tests/test_kernel.py
Expand Up @@ -31,10 +31,10 @@ def _inject_cell_id(_self, *args, **kwargs):
@contextmanager
def patch_cell_id():
try:
Session.msg = _inject_cell_id
Session.msg = _inject_cell_id # type:ignore
yield
finally:
Session.msg = orig_msg
Session.msg = orig_msg # type:ignore


@pytest.fixture()
Expand Down Expand Up @@ -107,10 +107,10 @@ def test_capfd(kc):


def test_getpass_stream(kc):
"Tests that kernel getpass accept the stream parameter"
"""Tests that kernel getpass accept the stream parameter"""
kernel = InProcessKernel()
kernel._allow_stdin = True
kernel._input_request = lambda *args, **kwargs: None
kernel._input_request = lambda *args, **kwargs: None # type:ignore

kernel.getpass(stream="non empty")

Expand Down
1 change: 1 addition & 0 deletions ipykernel/inprocess/tests/test_kernelmanager.py
Expand Up @@ -5,6 +5,7 @@

from ipykernel.inprocess.manager import InProcessKernelManager


# -----------------------------------------------------------------------------
# Test case
# -----------------------------------------------------------------------------
Expand Down
13 changes: 2 additions & 11 deletions ipykernel/ipkernel.py
Expand Up @@ -12,16 +12,7 @@
import comm
from IPython.core import release
from IPython.utils.tokenutil import line_at_cursor, token_at_cursor
from traitlets import (
Any,
Bool,
HasTraits,
Instance,
List,
Type,
observe,
observe_compat,
)
from traitlets import Any, Bool, HasTraits, Instance, List, Type, observe, observe_compat
from zmq.eventloop.zmqstream import ZMQStream

from .comm.comm import BaseComm
Expand Down Expand Up @@ -629,7 +620,7 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
working.update(ns)
code = f"{resultname} = {fname}(*{argname},**{kwargname})"
try:
exec(code, shell.user_global_ns, shell.user_ns)
exec(code, shell.user_global_ns, shell.user_ns) # noqa
result = working.get(resultname)
finally:
for key in ns:
Expand Down
7 changes: 2 additions & 5 deletions ipykernel/kernelapp.py
Expand Up @@ -625,10 +625,7 @@ def _init_asyncio_patch(self):
import asyncio

try:
from asyncio import (
WindowsProactorEventLoopPolicy,
WindowsSelectorEventLoopPolicy,
)
from asyncio import WindowsProactorEventLoopPolicy, WindowsSelectorEventLoopPolicy
except ImportError:
pass
# not affected
Expand All @@ -644,7 +641,7 @@ def init_pdb(self):
With the non-interruptible version, stopping pdb() locks up the kernel in a
non-recoverable state.
"""
import pdb
import pdb # noqa

from IPython.core import debugger

Expand Down

0 comments on commit 4dc3033

Please sign in to comment.