Skip to content

Commit

Permalink
Adopt ruff and reduce pre-commit usage (#895)
Browse files Browse the repository at this point in the history
* Adopt ruff and reduce pre-commit usage

* adopt ruff and address lint

* auto-fix unused imports

* restore print

* restore print

* fix tests_check

* clean up typings

* undo api change

* fix type check
  • Loading branch information
blink1073 authored Dec 8, 2022
1 parent b135ada commit ff33adf
Show file tree
Hide file tree
Showing 51 changed files with 531 additions and 602 deletions.
6 changes: 4 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
22 changes: 14 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ defaults:


jobs:
pre_commit:
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

check_release:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -84,6 +77,19 @@ jobs:
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- run: hatch run docs:build

lint:
name: Test Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@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 --ignore-path=docs/source/other/full-config.rst
test_minimum_verisons:
name: Test Minimum Versions
runs-on: ubuntu-latest
Expand Down Expand Up @@ -135,9 +141,9 @@ jobs:
needs:
- test
- docs
- lint
- check_links
- test_minimum_verisons
- pre_commit
- test_prereleases
- test_sdist
runs-on: ubuntu-latest
Expand Down
71 changes: 13 additions & 58 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
ci:
autoupdate_schedule: monthly

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand All @@ -15,71 +18,23 @@ repos:
- id: check-builtin-literals
- id: trailing-whitespace

- repo: https://github.com/asottile/reorder_python_imports
rev: v3.9.0
hooks:
- id: reorder-python-imports

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

- 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

- 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/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-mypy
rev: v0.991
hooks:
- id: mypy
exclude: tests
args: ["--config-file", "pyproject.toml"]
additional_dependencies: [pyzmq, tornado, types-paramiko, traitlets, "jupyter_core>=5.0", ipykernel]
stages: [manual]

- repo: https://github.com/PyCQA/doc8
rev: v1.0.0
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: doc8
args: [--max-line-length=100]
- 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
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
here = os.path.dirname(__file__)
version_py = os.path.join(here, os.pardir, 'jupyter_client', '_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
3 changes: 1 addition & 2 deletions jupyter_client/_version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import re
from typing import List
from typing import Union
from typing import List, Union

__version__ = "8.0.0b1"

Expand Down
5 changes: 1 addition & 4 deletions jupyter_client/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
# Distributed under the terms of the Modified BSD License.
import json
import re
from typing import Any
from typing import Dict
from typing import List
from typing import Tuple
from typing import Any, Dict, List, Tuple

from jupyter_client import protocol_version_info

Expand Down
9 changes: 3 additions & 6 deletions jupyter_client/asynchronous/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
import asyncio

import zmq.asyncio
from traitlets import Instance
from traitlets import Type
from traitlets import Instance, Type

from jupyter_client.channels import AsyncZMQSocketChannel
from jupyter_client.channels import HBChannel
from jupyter_client.client import KernelClient
from jupyter_client.client import reqrep
from jupyter_client.channels import AsyncZMQSocketChannel, HBChannel
from jupyter_client.client import KernelClient, reqrep


def wrapped(meth, channel):
Expand Down
7 changes: 3 additions & 4 deletions jupyter_client/blocking/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
# Distributed under the terms of the Modified BSD License.
from traitlets import Type

from jupyter_client.channels import HBChannel, ZMQSocketChannel
from jupyter_client.client import KernelClient, reqrep

from ..utils import run_sync
from jupyter_client.channels import HBChannel
from jupyter_client.channels import ZMQSocketChannel
from jupyter_client.client import KernelClient
from jupyter_client.client import reqrep


def wrapped(meth, channel):
Expand Down
10 changes: 5 additions & 5 deletions jupyter_client/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
import time
import typing as t
from queue import Empty
from threading import Event
from threading import Thread
from threading import Event, Thread

import zmq.asyncio

from .channelsabc import HBChannelABC
from .session import Session
from jupyter_client import protocol_version_info
from jupyter_client.utils import ensure_async

from .channelsabc import HBChannelABC
from .session import Session

# import ZMQError in top-level namespace, to avoid ugly attribute-error messages
# during garbage collection of threads at exit

Expand All @@ -26,7 +26,7 @@
major_protocol_version = protocol_version_info[0]


class InvalidPortNumber(Exception):
class InvalidPortNumber(Exception): # noqa
pass


Expand Down
48 changes: 23 additions & 25 deletions jupyter_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@
from queue import Empty

import zmq.asyncio
from traitlets import Any
from traitlets import Bool
from traitlets import Instance
from traitlets import Type
from traitlets import Any, Bool, Instance, Type

from .channelsabc import ChannelABC
from .channelsabc import HBChannelABC
from jupyter_client.channels import major_protocol_version
from jupyter_client.utils import ensure_async

from .channelsabc import ChannelABC, HBChannelABC
from .clientabc import KernelClientABC
from .connect import ConnectionFileMixin
from .session import Session
from jupyter_client.channels import major_protocol_version
from jupyter_client.utils import ensure_async


# some utilities to validate message structure, these might get moved elsewhere
# if they prove to have more generic utility
Expand Down Expand Up @@ -265,7 +263,7 @@ def _output_hook_default(self, msg: t.Dict[str, t.Any]) -> None:
elif msg_type in ("display_data", "execute_result"):
sys.stdout.write(content["data"].get("text/plain", ""))
elif msg_type == "error":
print("\n".join(content["traceback"]), file=sys.stderr)
sys.stderr.write("\n".join(content["traceback"]))

def _output_hook_kernel(
self,
Expand Down Expand Up @@ -621,14 +619,14 @@ def execute(

# Create class for content/msg creation. Related to, but possibly
# not in Session.
content = dict(
code=code,
silent=silent,
store_history=store_history,
user_expressions=user_expressions,
allow_stdin=allow_stdin,
stop_on_error=stop_on_error,
)
content = {
"code": code,
"silent": silent,
"store_history": store_history,
"user_expressions": user_expressions,
"allow_stdin": allow_stdin,
"stop_on_error": stop_on_error,
}
msg = self.session.msg("execute_request", content)
self.shell_channel.send(msg)
return msg["header"]["msg_id"]
Expand All @@ -651,7 +649,7 @@ def complete(self, code: str, cursor_pos: t.Optional[int] = None) -> str:
"""
if cursor_pos is None:
cursor_pos = len(code)
content = dict(code=code, cursor_pos=cursor_pos)
content = {"code": code, "cursor_pos": cursor_pos}
msg = self.session.msg("complete_request", content)
self.shell_channel.send(msg)
return msg["header"]["msg_id"]
Expand All @@ -678,11 +676,11 @@ def inspect(self, code: str, cursor_pos: t.Optional[int] = None, detail_level: i
"""
if cursor_pos is None:
cursor_pos = len(code)
content = dict(
code=code,
cursor_pos=cursor_pos,
detail_level=detail_level,
)
content = {
"code": code,
"cursor_pos": cursor_pos,
"detail_level": detail_level,
}
msg = self.session.msg("inspect_request", content)
self.shell_channel.send(msg)
return msg["header"]["msg_id"]
Expand Down Expand Up @@ -754,7 +752,7 @@ def comm_info(self, target_name: t.Optional[str] = None) -> str:
if target_name is None:
content = {}
else:
content = dict(target_name=target_name)
content = {"target_name": target_name}
msg = self.session.msg("comm_info_request", content)
self.shell_channel.send(msg)
return msg["header"]["msg_id"]
Expand Down Expand Up @@ -790,7 +788,7 @@ def input(self, string: str) -> None:
-------
The ID of the message sent.
"""
content = dict(value=string)
content = {"value": string}
msg = self.session.msg("input_reply", content)
self.stdin_channel.send(msg)

Expand Down
1 change: 1 addition & 0 deletions jupyter_client/clientabc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# -----------------------------------------------------------------------------
import abc


# -----------------------------------------------------------------------------
# Main kernel client class
# -----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit ff33adf

Please sign in to comment.