Skip to content

Commit

Permalink
Use sp-repo-review (#1146)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Sep 14, 2023
1 parent c24b252 commit 83ab7d0
Show file tree
Hide file tree
Showing 41 changed files with 133 additions and 61 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- name: Run Linters
run: |
- name: Run Linters
run: |
hatch run typing:test
hatch run lint:style
pipx run interrogate -vv .
Expand Down
38 changes: 36 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ci:
autoupdate_schedule: monthly
autoupdate_commit_msg: "chore: update pre-commit hooks"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down Expand Up @@ -29,14 +30,47 @@ repos:
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies:
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]

- repo: https://github.com/psf/black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.2"
hooks:
- id: prettier
types_or: [yaml, html, json]

- repo: https://github.com/adamchainz/blacken-docs
rev: "1.16.0"
hooks:
- id: blacken-docs
additional_dependencies: [black==23.7.0]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.7.0
hooks:
- id: black

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.5"
hooks:
- id: codespell
args: ["-L", "sur,nd"]

- repo: https://github.com/pre-commit/pygrep-hooks
rev: "v1.10.0"
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.287
hooks:
- id: ruff
args: ["--fix"]
args: ["--fix", "--show-fixes"]

- repo: https://github.com/scientific-python/cookie
rev: "2023.08.23"
hooks:
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"]
2 changes: 1 addition & 1 deletion examples/embedding/inprocess_qtconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def init_asyncio_patch():
asyncio implementation on Windows
Pick the older SelectorEventLoopPolicy on Windows
if the known-incompatible default policy is in use.
do this as early as possible to make it a low priority and overrideable
do this as early as possible to make it a low priority and overridable
ref: https://github.com/tornadoweb/tornado/issues/2608
FIXME: if/when tornado supports the defaults in asyncio,
remove and bump tornado requirement for py38
Expand Down
2 changes: 1 addition & 1 deletion examples/embedding/inprocess_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def init_asyncio_patch():
asyncio implementation on Windows
Pick the older SelectorEventLoopPolicy on Windows
if the known-incompatible default policy is in use.
do this as early as possible to make it a low priority and overrideable
do this as early as possible to make it a low priority and overridable
ref: https://github.com/tornadoweb/tornado/issues/2608
FIXME: if/when tornado supports the defaults in asyncio,
remove and bump tornado requirement for py38
Expand Down
4 changes: 2 additions & 2 deletions ipykernel/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
raise e


# Required for backwards compatiblity
# Required for backwards compatibility
ROUTING_ID = getattr(zmq, "ROUTING_ID", None) or zmq.IDENTITY


Expand Down Expand Up @@ -644,7 +644,7 @@ async def richInspectVariables(self, message):
repr_data = {}
repr_metadata = {}
if not self.stopped_threads:
# The code did not hit a breakpoint, we use the intepreter
# The code did not hit a breakpoint, we use the interpreter
# to get the rich representation of the variable
result = get_ipython().user_expressions({var_name: var_name})[var_name]
if result.get("status", "error") == "ok":
Expand Down
10 changes: 7 additions & 3 deletions ipykernel/eventloops.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ async def close_loop():
close_loop()

elif not loop.is_closed():
loop.run_until_complete(close_loop) # type:ignore
loop.run_until_complete(close_loop) # type:ignore[arg-type]
loop.close()


Expand Down Expand Up @@ -566,8 +566,12 @@ def enable_gui(gui, kernel=None):
make_qt_app_for_kernel(gui, kernel)

loop = loop_map[gui]
if loop and kernel.eventloop is not None and kernel.eventloop is not loop:
msg = "Cannot activate multiple GUI eventloops"
if (
loop
and kernel.eventloop is not None
and kernel.eventloop is not loop # type:ignore[unreachable]
):
msg = "Cannot activate multiple GUI eventloops" # type:ignore[unreachable]
raise RuntimeError(msg)
kernel.eventloop = loop
# We set `eventloop`; the function the user chose is executed in `Kernel.enter_eventloop`, thus
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/inprocess/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class InProcessChannel:
proxy_methods: List[object] = []

def __init__(self, client=None):
"""Initialze the channel."""
"""Initialize the channel."""
super().__init__()
self.client = client
self._is_alive = False
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/inprocess/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def _dispatch_to_kernel(self, msg):
dispatch_shell = run_sync(kernel.dispatch_shell)
dispatch_shell(msg_parts)
else:
loop = asyncio.get_event_loop()
loop = asyncio.get_event_loop() # type:ignore[unreachable]
loop.run_until_complete(kernel.dispatch_shell(msg_parts))
idents, reply_msg = self.session.recv(stream, copy=False)
self.shell_channel.call_handlers_later(reply_msg)
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/inprocess/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _input_request(self, prompt, ident, parent, password=False):
# Await a response.
while self.raw_input_str is None:
frontend.stdin_channel.process_events()
return self.raw_input_str
return self.raw_input_str # type:ignore[unreachable]

# -------------------------------------------------------------------------
# Protected interface
Expand Down
8 changes: 4 additions & 4 deletions ipykernel/iostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _start_event_gc():
if self._event_pipe_gc_task is not None:
# cancel gc task to avoid pending task warnings
async def _cancel():
self._event_pipe_gc_task.cancel() # type:ignore
self._event_pipe_gc_task.cancel() # type:ignore[union-attr]

if not self._stopped:
self.io_loop.run_sync(_cancel)
Expand Down Expand Up @@ -373,7 +373,7 @@ def fileno(self):

def _watch_pipe_fd(self):
"""
We've redirected standards steams 0 and 1 into a pipe.
We've redirected standards streams 0 and 1 into a pipe.
We need to watch in a thread and redirect them to the right places.
Expand Down Expand Up @@ -424,7 +424,7 @@ def __init__(
that will swap the give file descriptor for a pipe, read from the
pipe, and insert this into the current Stream.
isatty : bool (default, False)
Indication of whether this stream has termimal capabilities (e.g. can handle colors)
Indication of whether this stream has terminal capabilities (e.g. can handle colors)
"""
if pipe is not None:
Expand Down Expand Up @@ -634,7 +634,7 @@ def write(self, string: str) -> Optional[int]: # type:ignore[override]
"""

if not isinstance(string, str):
msg = f"write() argument must be str, not {type(string)}"
msg = f"write() argument must be str, not {type(string)}" # type:ignore[unreachable]
raise TypeError(msg)

if self.echo is not None:
Expand Down
6 changes: 3 additions & 3 deletions ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
try:
from IPython.core.interactiveshell import _asyncio_runner # type:ignore[attr-defined]
except ImportError:
_asyncio_runner = None # type:ignore
_asyncio_runner = None # type:ignore[assignment]

try:
from IPython.core.completer import provisionalcompleter as _provisionalcompleter
Expand Down Expand Up @@ -328,7 +328,7 @@ def set_sigint_result():
# use add_callback for thread safety
self.io_loop.add_callback(set_sigint_result)

# set the custom sigint hander during this context
# set the custom sigint handler during this context
save_sigint = signal.signal(signal.SIGINT, handle_sigint)
try:
yield
Expand Down Expand Up @@ -377,7 +377,7 @@ async def run_cell(*args, **kwargs):
preprocessing_exc_tuple = sys.exc_info()

if (
_asyncio_runner
_asyncio_runner # type:ignore[truthy-bool]
and shell.loop_runner is _asyncio_runner
and asyncio.get_event_loop().is_running()
and should_run_async(
Expand Down
10 changes: 5 additions & 5 deletions ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,9 @@ def init_blackhole(self):
if self.no_stdout or self.no_stderr:
blackhole = open(os.devnull, "w") # noqa
if self.no_stdout:
sys.stdout = sys.__stdout__ = blackhole # type:ignore
sys.stdout = sys.__stdout__ = blackhole # type:ignore[misc]
if self.no_stderr:
sys.stderr = sys.__stderr__ = blackhole # type:ignore
sys.stderr = sys.__stderr__ = blackhole # type:ignore[misc]

def init_io(self):
"""Redirect input streams and set a display hook."""
Expand Down Expand Up @@ -634,7 +634,7 @@ def _init_asyncio_patch(self):
but it is still preferable to run the Selector in the main thread
instead of the background.
do this as early as possible to make it a low priority and overrideable
do this as early as possible to make it a low priority and overridable
ref: https://github.com/tornadoweb/tornado/issues/2608
Expand Down Expand Up @@ -670,8 +670,8 @@ def init_pdb(self):

if hasattr(debugger, "InterruptiblePdb"):
# Only available in newer IPython releases:
debugger.Pdb = debugger.InterruptiblePdb # type:ignore
pdb.Pdb = debugger.Pdb # type:ignore
debugger.Pdb = debugger.InterruptiblePdb # type:ignore[misc]
pdb.Pdb = debugger.Pdb # type:ignore[assignment,misc]
pdb.set_trace = debugger.set_trace # type:ignore[assignment]

@catch_config_error
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/parentpoller.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, interrupt_handle=None, parent_handle=None):
assert interrupt_handle or parent_handle
super().__init__()
if ctypes is None:
msg = "ParentPollerWindows requires ctypes"
msg = "ParentPollerWindows requires ctypes" # type:ignore[unreachable]
raise ImportError(msg)
self.daemon = True
self.interrupt_handle = interrupt_handle
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/trio_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ async def loc(coro):
self._cell_cancel_scope = trio.CancelScope()
with self._cell_cancel_scope:
return await coro
self._cell_cancel_scope = None
self._cell_cancel_scope = None # type:ignore[unreachable]

return trio.from_thread.run(loc, async_fn, trio_token=self._trio_token)
42 changes: 33 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ path = "ipykernel/_version.py"
features = ["docs"]
[tool.hatch.envs.docs.scripts]
build = "make -C docs html SPHINXOPTS='-W'"
api = "sphinx-apidoc -o docs/api -f -E ipykernel ipykernel/tests ipykernel/inprocess/tests ipykernel/datapub.py ipykernel/pickleutil.py ipykernel/serialize.py ipykernel/gui ipykernel/pylab"
api = "sphinx-apidoc -o docs/api -f -E ipykernel tests ipykernel/datapub.py ipykernel/pickleutil.py ipykernel/serialize.py ipykernel/gui ipykernel/pylab"

[tool.hatch.envs.test]
features = ["test"]
Expand All @@ -112,7 +112,7 @@ matrix.qt.features = [

[tool.hatch.envs.typing]
features = ["test"]
dependencies = ["mypy>=0.990"]
dependencies = ["mypy>=1.5.1"]
[tool.hatch.envs.typing.scripts]
test = "mypy --install-types --non-interactive {args:.}"

Expand All @@ -135,6 +135,7 @@ fmt = [
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_untyped_decorators = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
follow_imports = "normal"
ignore_missing_imports = true
no_implicit_optional = true
Expand All @@ -147,13 +148,34 @@ strict_optional = true
warn_unused_configs = true
warn_redundant_casts = true
warn_return_any = true
warn_unreachable = true
warn_unused_ignores = true

[[tool.mypy.overrides]]
module = "tests.*"
disable_error_code = ["ignore-without-code"]
warn_unreachable = false

[tool.pytest.ini_options]
addopts = "-raXs --durations 10 --color=yes --doctest-modules --ignore=ipykernel/pylab/backend_inline.py --ignore=ipykernel/pylab/config.py --ignore=ipykernel/gui/gtk3embed.py --ignore=ipykernel/gui/gtkembed.py --ignore=ipykernel/datapub.py --ignore=ipykernel/log.py --ignore=ipykernel/pickleutil.py --ignore=ipykernel/serialize.py --ignore=ipykernel/_eventloop_macos.py"
minversion = "6.0"
xfail_strict = true
log_cli_level = "info"
addopts = [
"-raXs", "--durations=10", "--color=yes", "--doctest-modules",
"--showlocals", "--strict-markers", "--strict-config",
"--ignore=ipykernel/pylab/backend_inline.py",
"--ignore=ipykernel/pylab/config.py",
"--ignore=ipykernel/gui/gtk3embed.py",
"--ignore=ipykernel/gui/gtkembed.py",
"--ignore=ipykernel/datapub.py",
"--ignore=ipykernel/log.py",
"--ignore=ipykernel/pickleutil.py",
"--ignore=ipykernel/serialize.py",
"--ignore=ipykernel/_eventloop_macos.py"
]
testpaths = [
"ipykernel/tests",
"ipykernel/inprocess/tests"
"tests",
"tests/inprocess"
]
asyncio_mode = "auto"
timeout = 300
Expand Down Expand Up @@ -195,14 +217,13 @@ exclude_lines = [
relative_files = true
source = ["ipykernel"]
omit = [
"ipykernel/tests/*",
"tests/*",
"ipykernel/datapub.py",
"ipykernel/debugger.py",
"ipykernel/eventloops.py",
"ipykernel/log.py",
"ipykernel/pickleutil.py",
"ipykernel/serialize.py",
"ipykernel/inprocess/tests/*",
"ipykernel/gui/*",
"ipykernel/pylab/*",
]
Expand Down Expand Up @@ -304,7 +325,7 @@ unfixable = [
# PLC1901 `stderr == ""` can be simplified to `not stderr` as an empty string is falsey
# B018 Found useless expression. Either assign it to a variable or remove it.
# S603 `subprocess` call: check for execution of untrusted input
"ipykernel/tests/*" = ["B011", "F841", "C408", "E402", "T201", "B007", "N802", "F841", "EM101",
"tests/*" = ["B011", "F841", "C408", "E402", "T201", "B007", "N802", "F841", "EM101",
"EM102", "EM103", "PLR2004", "PLW0603", "PLW2901", "PLC1901", "B018", "S603"]

[tool.interrogate]
Expand All @@ -315,8 +336,11 @@ ignore-property-decorators=true
ignore-nested-functions=true
ignore-nested-classes=true
fail-under=95
exclude = ["docs", "*/tests"]
exclude = ["docs", "tests"]

[tool.check-wheel-contents]
toplevel = ["ipykernel/", "ipykernel_launcher.py"]
ignore = ["W002"]

[tool.repo-review]
ignore = ["PY007", "PP308", "GH102", "PC140", "MY101"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from ipykernel.inprocess.blocking import BlockingInProcessKernelClient
from ipykernel.inprocess.ipkernel import InProcessKernel
from ipykernel.inprocess.manager import InProcessKernelManager
from ipykernel.tests.utils import assemble_output

from ..utils import assemble_output

orig_msg = Session.msg

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 83ab7d0

Please sign in to comment.