Skip to content

Commit ff33adf

Browse files
authored
Adopt ruff and reduce pre-commit usage (#895)
* 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
1 parent b135ada commit ff33adf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+531
-602
lines changed

.github/dependabot.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
version: 2
22
updates:
3-
# Set update schedule for GitHub Actions
43
- package-ecosystem: "github-actions"
54
directory: "/"
65
schedule:
7-
# Check for updates to GitHub Actions every weekday
6+
interval: "weekly"
7+
- package-ecosystem: "pip"
8+
directory: "/"
9+
schedule:
810
interval: "weekly"

.github/workflows/main.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ defaults:
1616

1717

1818
jobs:
19-
pre_commit:
20-
runs-on: ubuntu-latest
21-
steps:
22-
- uses: actions/checkout@v3
23-
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
24-
- uses: jupyterlab/maintainer-tools/.github/actions/pre-commit@v1
25-
2619
check_release:
2720
runs-on: ubuntu-latest
2821
steps:
@@ -84,6 +77,19 @@ jobs:
8477
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
8578
- run: hatch run docs:build
8679

80+
lint:
81+
name: Test Lint
82+
runs-on: ubuntu-latest
83+
steps:
84+
- uses: actions/checkout@v3
85+
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
86+
- name: Run Linters
87+
run: |
88+
hatch run typing:test
89+
hatch run lint:style
90+
pipx run 'validate-pyproject[all]' pyproject.toml
91+
pipx run doc8 --max-line-length=200 --ignore-path=docs/source/other/full-config.rst
92+
8793
test_minimum_verisons:
8894
name: Test Minimum Versions
8995
runs-on: ubuntu-latest
@@ -135,9 +141,9 @@ jobs:
135141
needs:
136142
- test
137143
- docs
144+
- lint
138145
- check_links
139146
- test_minimum_verisons
140-
- pre_commit
141147
- test_prereleases
142148
- test_sdist
143149
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 13 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
ci:
2+
autoupdate_schedule: monthly
3+
14
repos:
25
- repo: https://github.com/pre-commit/pre-commit-hooks
36
rev: v4.4.0
@@ -15,71 +18,23 @@ repos:
1518
- id: check-builtin-literals
1619
- id: trailing-whitespace
1720

18-
- repo: https://github.com/asottile/reorder_python_imports
19-
rev: v3.9.0
20-
hooks:
21-
- id: reorder-python-imports
22-
23-
- repo: https://github.com/psf/black
24-
rev: 22.10.0
25-
hooks:
26-
- id: black
27-
args: ["--line-length", "100"]
28-
29-
- repo: https://github.com/abravalheri/validate-pyproject
30-
rev: v0.10.1
21+
- repo: https://github.com/python-jsonschema/check-jsonschema
22+
rev: 0.19.2
3123
hooks:
32-
- id: validate-pyproject
33-
stages: [manual]
24+
- id: check-github-workflows
3425

3526
- repo: https://github.com/executablebooks/mdformat
3627
rev: 0.7.16
3728
hooks:
3829
- id: mdformat
3930

40-
- repo: https://github.com/asottile/pyupgrade
41-
rev: v3.3.0
42-
hooks:
43-
- id: pyupgrade
44-
args: [--py38-plus]
45-
46-
- repo: https://github.com/PyCQA/doc8
47-
rev: v1.0.0
48-
hooks:
49-
- id: doc8
50-
args: [--max-line-length=200]
51-
stages: [manual]
52-
53-
- repo: https://github.com/john-hen/Flake8-pyproject
54-
rev: 1.2.2
55-
hooks:
56-
- id: Flake8-pyproject
57-
alias: flake8
58-
additional_dependencies:
59-
["flake8-bugbear==22.6.22", "flake8-implicit-str-concat==0.2.0"]
60-
stages: [manual]
61-
62-
- repo: https://github.com/pre-commit/mirrors-mypy
63-
rev: v0.991
64-
hooks:
65-
- id: mypy
66-
exclude: tests
67-
args: ["--config-file", "pyproject.toml"]
68-
additional_dependencies: [pyzmq, tornado, types-paramiko, traitlets, "jupyter_core>=5.0", ipykernel]
69-
stages: [manual]
70-
71-
- repo: https://github.com/PyCQA/doc8
72-
rev: v1.0.0
31+
- repo: https://github.com/psf/black
32+
rev: 22.10.0
7333
hooks:
74-
- id: doc8
75-
args: [--max-line-length=100]
34+
- id: black
7635

77-
- repo: https://github.com/sirosen/check-jsonschema
78-
rev: 0.19.2
36+
- repo: https://github.com/charliermarsh/ruff-pre-commit
37+
rev: v0.0.165
7938
hooks:
80-
- id: check-jsonschema
81-
name: "Check GitHub Workflows"
82-
files: ^\.github/workflows/
83-
types: [yaml]
84-
args: ["--schemafile", "https://json.schemastore.org/github-workflow"]
85-
stages: [manual]
39+
- id: ruff
40+
args: ["--fix"]

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
here = os.path.dirname(__file__)
6868
version_py = os.path.join(here, os.pardir, 'jupyter_client', '_version.py')
6969
with open(version_py) as f:
70-
exec(compile(f.read(), version_py, 'exec'), version_ns)
70+
exec(compile(f.read(), version_py, 'exec'), version_ns) # noqa
7171

7272
# The short X.Y version.
7373
version = '%i.%i' % version_ns['version_info'][:2]

jupyter_client/_version.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import re
2-
from typing import List
3-
from typing import Union
2+
from typing import List, Union
43

54
__version__ = "8.0.0b1"
65

jupyter_client/adapter.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
# Distributed under the terms of the Modified BSD License.
44
import json
55
import re
6-
from typing import Any
7-
from typing import Dict
8-
from typing import List
9-
from typing import Tuple
6+
from typing import Any, Dict, List, Tuple
107

118
from jupyter_client import protocol_version_info
129

jupyter_client/asynchronous/client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44
import asyncio
55

66
import zmq.asyncio
7-
from traitlets import Instance
8-
from traitlets import Type
7+
from traitlets import Instance, Type
98

10-
from jupyter_client.channels import AsyncZMQSocketChannel
11-
from jupyter_client.channels import HBChannel
12-
from jupyter_client.client import KernelClient
13-
from jupyter_client.client import reqrep
9+
from jupyter_client.channels import AsyncZMQSocketChannel, HBChannel
10+
from jupyter_client.client import KernelClient, reqrep
1411

1512

1613
def wrapped(meth, channel):

jupyter_client/blocking/client.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
# Distributed under the terms of the Modified BSD License.
77
from traitlets import Type
88

9+
from jupyter_client.channels import HBChannel, ZMQSocketChannel
10+
from jupyter_client.client import KernelClient, reqrep
11+
912
from ..utils import run_sync
10-
from jupyter_client.channels import HBChannel
11-
from jupyter_client.channels import ZMQSocketChannel
12-
from jupyter_client.client import KernelClient
13-
from jupyter_client.client import reqrep
1413

1514

1615
def wrapped(meth, channel):

jupyter_client/channels.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
import time
77
import typing as t
88
from queue import Empty
9-
from threading import Event
10-
from threading import Thread
9+
from threading import Event, Thread
1110

1211
import zmq.asyncio
1312

14-
from .channelsabc import HBChannelABC
15-
from .session import Session
1613
from jupyter_client import protocol_version_info
1714
from jupyter_client.utils import ensure_async
1815

16+
from .channelsabc import HBChannelABC
17+
from .session import Session
18+
1919
# import ZMQError in top-level namespace, to avoid ugly attribute-error messages
2020
# during garbage collection of threads at exit
2121

@@ -26,7 +26,7 @@
2626
major_protocol_version = protocol_version_info[0]
2727

2828

29-
class InvalidPortNumber(Exception):
29+
class InvalidPortNumber(Exception): # noqa
3030
pass
3131

3232

jupyter_client/client.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@
1111
from queue import Empty
1212

1313
import zmq.asyncio
14-
from traitlets import Any
15-
from traitlets import Bool
16-
from traitlets import Instance
17-
from traitlets import Type
14+
from traitlets import Any, Bool, Instance, Type
1815

19-
from .channelsabc import ChannelABC
20-
from .channelsabc import HBChannelABC
16+
from jupyter_client.channels import major_protocol_version
17+
from jupyter_client.utils import ensure_async
18+
19+
from .channelsabc import ChannelABC, HBChannelABC
2120
from .clientabc import KernelClientABC
2221
from .connect import ConnectionFileMixin
2322
from .session import Session
24-
from jupyter_client.channels import major_protocol_version
25-
from jupyter_client.utils import ensure_async
23+
2624

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

270268
def _output_hook_kernel(
271269
self,
@@ -621,14 +619,14 @@ def execute(
621619

622620
# Create class for content/msg creation. Related to, but possibly
623621
# not in Session.
624-
content = dict(
625-
code=code,
626-
silent=silent,
627-
store_history=store_history,
628-
user_expressions=user_expressions,
629-
allow_stdin=allow_stdin,
630-
stop_on_error=stop_on_error,
631-
)
622+
content = {
623+
"code": code,
624+
"silent": silent,
625+
"store_history": store_history,
626+
"user_expressions": user_expressions,
627+
"allow_stdin": allow_stdin,
628+
"stop_on_error": stop_on_error,
629+
}
632630
msg = self.session.msg("execute_request", content)
633631
self.shell_channel.send(msg)
634632
return msg["header"]["msg_id"]
@@ -651,7 +649,7 @@ def complete(self, code: str, cursor_pos: t.Optional[int] = None) -> str:
651649
"""
652650
if cursor_pos is None:
653651
cursor_pos = len(code)
654-
content = dict(code=code, cursor_pos=cursor_pos)
652+
content = {"code": code, "cursor_pos": cursor_pos}
655653
msg = self.session.msg("complete_request", content)
656654
self.shell_channel.send(msg)
657655
return msg["header"]["msg_id"]
@@ -678,11 +676,11 @@ def inspect(self, code: str, cursor_pos: t.Optional[int] = None, detail_level: i
678676
"""
679677
if cursor_pos is None:
680678
cursor_pos = len(code)
681-
content = dict(
682-
code=code,
683-
cursor_pos=cursor_pos,
684-
detail_level=detail_level,
685-
)
679+
content = {
680+
"code": code,
681+
"cursor_pos": cursor_pos,
682+
"detail_level": detail_level,
683+
}
686684
msg = self.session.msg("inspect_request", content)
687685
self.shell_channel.send(msg)
688686
return msg["header"]["msg_id"]
@@ -754,7 +752,7 @@ def comm_info(self, target_name: t.Optional[str] = None) -> str:
754752
if target_name is None:
755753
content = {}
756754
else:
757-
content = dict(target_name=target_name)
755+
content = {"target_name": target_name}
758756
msg = self.session.msg("comm_info_request", content)
759757
self.shell_channel.send(msg)
760758
return msg["header"]["msg_id"]
@@ -790,7 +788,7 @@ def input(self, string: str) -> None:
790788
-------
791789
The ID of the message sent.
792790
"""
793-
content = dict(value=string)
791+
content = {"value": string}
794792
msg = self.session.msg("input_reply", content)
795793
self.stdin_channel.send(msg)
796794

0 commit comments

Comments
 (0)