Skip to content

Commit 652ce3b

Browse files
authored
Merge branch 'main' into pre-commit-ci-update-config
2 parents 371c460 + 6567bcb commit 652ce3b

Some content is hidden

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

43 files changed

+357
-170
lines changed

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Initial pre-commit reformat
2+
92edb7756e411f7e8295013b5da6a4255e89ac75

.github/dependabot.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: 2
2+
updates:
3+
# GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
groups:
9+
actions:
10+
patterns:
11+
- "*"
12+
# Python
13+
- package-ecosystem: "pip"
14+
directory: "/"
15+
schedule:
16+
interval: "weekly"

.github/workflows/tests.yml

100755100644
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Tests
22

33
on:
4+
workflow_dispatch:
45
push:
56
pull_request:
67
branches:

.pre-commit-config.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,77 @@
1+
ci:
2+
autoupdate_schedule: monthly
3+
autoupdate_commit_msg: "chore: update pre-commit hooks"
4+
15
repos:
26
- repo: https://github.com/pre-commit/pre-commit-hooks
37
rev: v4.5.0
48
hooks:
9+
- id: check-case-conflict
10+
- id: check-ast
11+
- id: check-docstring-first
12+
- id: check-executables-have-shebangs
13+
- id: check-added-large-files
14+
- id: check-case-conflict
15+
- id: check-merge-conflict
16+
- id: check-json
17+
- id: check-toml
18+
- id: check-yaml
19+
- id: debug-statements
520
- id: end-of-file-fixer
21+
- id: trailing-whitespace
622

723
- repo: https://github.com/python-jsonschema/check-jsonschema
824
rev: 0.27.3
925
hooks:
1026
- id: check-github-workflows
27+
28+
- repo: https://github.com/executablebooks/mdformat
29+
rev: 0.7.17
30+
hooks:
31+
- id: mdformat
32+
additional_dependencies:
33+
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]
34+
35+
- repo: https://github.com/pre-commit/mirrors-prettier
36+
rev: "v4.0.0-alpha.8"
37+
hooks:
38+
- id: prettier
39+
types_or: [yaml, html, json]
40+
41+
- repo: https://github.com/codespell-project/codespell
42+
rev: "v2.2.6"
43+
hooks:
44+
- id: codespell
45+
args: ["-L", "sur,nd"]
46+
47+
- repo: https://github.com/pre-commit/pygrep-hooks
48+
rev: "v1.10.0"
49+
hooks:
50+
- id: rst-backticks
51+
- id: rst-directive-colons
52+
- id: rst-inline-touching-normal
53+
54+
- repo: https://github.com/pre-commit/mirrors-mypy
55+
rev: "v1.8.0"
56+
hooks:
57+
- id: mypy
58+
files: kernel_gateway
59+
stages: [manual]
60+
additional_dependencies: []
61+
62+
- repo: https://github.com/astral-sh/ruff-pre-commit
63+
rev: v0.1.9
64+
hooks:
65+
- id: ruff
66+
types_or: [python, jupyter]
67+
args: ["--fix", "--show-fixes"]
68+
exclude: ^kernel_gateway/tests/resources/
69+
- id: ruff-format
70+
types_or: [python, jupyter]
71+
exclude: ^kernel_gateway/tests/resources/
72+
73+
- repo: https://github.com/scientific-python/cookie
74+
rev: "2023.12.21"
75+
hooks:
76+
- id: sp-repo-review
77+
additional_dependencies: ["repo-review[cli]"]

.readthedocs.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: 2
2+
build:
3+
os: ubuntu-22.04
4+
tools:
5+
python: "3.9"
6+
sphinx:
7+
configuration: docs/source/conf.py
8+
python:
9+
install:
10+
# install itself with pip install .
11+
- method: pip
12+
path: .
13+
extra_requirements:
14+
- docs
15+
formats:
16+
- epub
17+
- htmlzip

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
- Add support for specifying notebook-http APIs using full Swagger specs
118118
- Add option to serve static web assets from Tornado in notebook-http mode
119119
- Add command line aliases for common options (e.g., `--ip`)
120-
- Fix Tornado 4.4 compatbility: sending an empty body string with a 204 response
120+
- Fix Tornado 4.4 compatibility: sending an empty body string with a 204 response
121121

122122
## 1.0.0 (2016-07-15)
123123

conftest.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33

4-
import os
54
import logging
6-
import pytest
5+
import os
76
from binascii import hexlify
8-
from traitlets.config import Config
9-
from kernel_gateway.gatewayapp import KernelGatewayApp
7+
8+
# isort: off
9+
# This must come before any Jupyter imports.
10+
os.environ["JUPYTER_PLATFORM_DIRS"] = "1"
11+
# isort: on
12+
13+
import pytest # noqa: E402
14+
from traitlets.config import Config # noqa: E402
15+
16+
from kernel_gateway.gatewayapp import KernelGatewayApp # noqa: E402
1017

1118
pytest_plugins = ["pytest_jupyter.jupyter_core", "pytest_jupyter.jupyter_server"]
1219

@@ -92,13 +99,13 @@ def jp_server_cleanup(jp_asyncio_loop):
9299
try:
93100
jp_asyncio_loop.run_until_complete(app.async_shutdown())
94101
except (RuntimeError, SystemExit) as e:
95-
print("ignoring cleanup error", e)
102+
print("ignoring cleanup error", e) # noqa: T201
96103
if hasattr(app, "kernel_manager"):
97104
app.kernel_manager.context.destroy()
98105
KernelGatewayApp.clear_instance()
99106

100107

101-
@pytest.fixture
108+
@pytest.fixture()
102109
def jp_auth_header(jp_serverapp):
103110
"""Configures an authorization header using the token from the serverapp fixture."""
104111
return {"Authorization": f"token {jp_serverapp.identity_provider.token}"}

docs/source/conf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# This file is execfile()d with the current directory set to its
43
# containing dir.
@@ -60,7 +59,7 @@
6059
#
6160
_version_py = "../../kernel_gateway/_version.py"
6261
version_ns = {}
63-
exec(compile(open(_version_py).read(), _version_py, "exec"), version_ns)
62+
exec(compile(open(_version_py).read(), _version_py, "exec"), version_ns) # noqa: S102
6463
# The short X.Y version.
6564
version = "%i.%i" % version_ns["version_info"][:2]
6665
# The full version, including alpha/beta/rc tags.
@@ -337,7 +336,7 @@
337336
# The format is a list of tuples containing the path and title.
338337
# epub_pre_files = []
339338

340-
# HTML files shat should be inserted after the pages created by sphinx.
339+
# HTML files that should be inserted after the pages created by sphinx.
341340
# The format is a list of tuples containing the path and title.
342341
# epub_post_files = []
343342

docs/source/summary-changes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ See `git log` for a more detailed summary of changes.
9797
- Add support for specifying notebook-http APIs using full Swagger specs
9898
- Add option to serve static web assets from Tornado in notebook-http mode
9999
- Add command line aliases for common options (e.g., `--ip`)
100-
- Fix Tornado 4.4 compatbility: sending an empty body string with a 204 response
100+
- Fix Tornado 4.4 compatibility: sending an empty body string with a 204 response
101101

102102
## 1.0
103103

etc/api_examples/setting_response_metadata.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@
4646
},
4747
"outputs": [],
4848
"source": [
49+
"import hashlib\n",
4950
"import json\n",
50-
"from dicttoxml import dicttoxml\n",
51-
"import hashlib"
51+
"\n",
52+
"from dicttoxml import dicttoxml"
5253
]
5354
},
5455
{

kernel_gateway/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33
"""Entrypoint for the kernel gateway package."""
4-
from .gatewayapp import launch_instance
5-
6-
from ._version import version_info, __version__
4+
from ._version import __version__, version_info # noqa: F401
5+
from .gatewayapp import launch_instance # noqa: F401

kernel_gateway/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33
"""CLI entrypoint for the kernel gateway package."""
4-
from __future__ import absolute_import
54

65
if __name__ == "__main__":
76
import kernel_gateway.gatewayapp as app

kernel_gateway/auth/identity.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
This defines the _authentication_ layer of Jupyter Server,
66
to be used in combination with Authorizer for _authorization_.
77
"""
8-
from traitlets import default
9-
from tornado import web
10-
118
from jupyter_server.auth.identity import IdentityProvider, User
129
from jupyter_server.base.handlers import JupyterHandler
10+
from tornado import web
11+
from traitlets import default
1312

1413

1514
class GatewayIdentityProvider(IdentityProvider):

kernel_gateway/base/handlers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
# Distributed under the terms of the Modified BSD License.
33
"""Tornado handlers for the base of the API."""
44

5-
from tornado import web
65
import jupyter_server.base.handlers as server_handlers
7-
from ..mixins import TokenAuthorizationMixin, CORSMixin, JSONErrorsMixin
6+
from tornado import web
7+
8+
from ..mixins import CORSMixin, JSONErrorsMixin, TokenAuthorizationMixin
89

910

1011
class APIVersionHandler(
@@ -14,8 +15,6 @@ class APIVersionHandler(
1415
JSON errors.
1516
"""
1617

17-
pass
18-
1918

2019
class NotFoundHandler(JSONErrorsMixin, web.RequestHandler):
2120
"""Catches all requests and responds with 404 JSON messages.

kernel_gateway/gatewayapp.py

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,40 @@
44

55
import asyncio
66
import errno
7-
import importlib
8-
import logging
97
import hashlib
108
import hmac
9+
import importlib
10+
import logging
1111
import os
12-
import sys
13-
import signal
1412
import select
15-
import socket
13+
import signal
1614
import ssl
15+
import sys
1716
import threading
1817
from base64 import encodebytes
19-
20-
import nbformat
21-
from jupyter_server.services.kernels.kernelmanager import MappingKernelManager
22-
2318
from urllib.parse import urlparse
24-
from traitlets import Unicode, Integer, Bytes, default, observe, Type, Instance, List, CBool
2519

26-
from jupyter_core.application import JupyterApp, base_aliases
20+
import nbformat
2721
from jupyter_client.kernelspec import KernelSpecManager
28-
29-
from tornado import httpserver
30-
from tornado import web, ioloop
31-
from tornado.log import enable_pretty_logging, LogFormatter
32-
22+
from jupyter_core.application import JupyterApp, base_aliases
3323
from jupyter_core.paths import secure_write
24+
from jupyter_server.auth.authorizer import AllowAllAuthorizer, Authorizer
3425
from jupyter_server.serverapp import random_ports
35-
from ._version import __version__
36-
from .services.sessions.sessionmanager import SessionManager
37-
from .services.kernels.manager import SeedingMappingKernelManager
26+
from jupyter_server.services.kernels.connection.base import BaseKernelWebsocketConnection
27+
from jupyter_server.services.kernels.connection.channels import ZMQChannelsWebsocketConnection
28+
from jupyter_server.services.kernels.kernelmanager import MappingKernelManager
29+
from tornado import httpserver, ioloop, web
30+
from tornado.log import LogFormatter, enable_pretty_logging
31+
from traitlets import Bytes, CBool, Instance, Integer, List, Type, Unicode, default, observe
3832

33+
from ._version import __version__
3934
from .auth.identity import GatewayIdentityProvider
35+
from .jupyter_websocket import JupyterWebsocketPersonality
4036

4137
# Only present for generating help documentation
4238
from .notebook_http import NotebookHTTPPersonality
43-
from .jupyter_websocket import JupyterWebsocketPersonality
44-
45-
from jupyter_server.auth.authorizer import AllowAllAuthorizer, Authorizer
46-
from jupyter_server.services.kernels.connection.base import BaseKernelWebsocketConnection
47-
from jupyter_server.services.kernels.connection.channels import ZMQChannelsWebsocketConnection
48-
39+
from .services.kernels.manager import SeedingMappingKernelManager
40+
from .services.sessions.sessionmanager import SessionManager
4941

5042
# Add additional command line aliases
5143
aliases = dict(base_aliases)
@@ -135,7 +127,7 @@ def base_url_default(self):
135127
return os.getenv(self.base_url_env, self.base_url_default_value)
136128

137129
# Token authorization
138-
auth_token_env = "KG_AUTH_TOKEN"
130+
auth_token_env = "KG_AUTH_TOKEN" # noqa: S105
139131
auth_token = Unicode(
140132
config=True, help="Authorization token required for all requests (KG_AUTH_TOKEN env var)"
141133
)
@@ -196,7 +188,7 @@ def expose_headers_default(self):
196188
trust_xheaders = CBool(
197189
False,
198190
config=True,
199-
help="Use x-* header values for overriding the remote-ip, useful when application is behing a proxy. (KG_TRUST_XHEADERS env var)",
191+
help="Use x-* header values for overriding the remote-ip, useful when application is behind a proxy. (KG_TRUST_XHEADERS env var)",
200192
)
201193

202194
@default("trust_xheaders")
@@ -303,7 +295,7 @@ def api_changed(self, event):
303295
self._load_api_module(event["new"])
304296
except ImportError:
305297
# re-raise with more sensible message to help the user
306-
raise ImportError("API module {} not found".format(event["new"]))
298+
raise ImportError("API module {} not found".format(event["new"])) from None
307299

308300
certfile_env = "KG_CERTFILE"
309301
certfile = Unicode(
@@ -506,7 +498,7 @@ def _load_notebook(self, uri):
506498
# Remote file
507499
import requests
508500

509-
resp = requests.get(uri)
501+
resp = requests.get(uri, timeout=200)
510502
resp.raise_for_status()
511503
notebook = nbformat.reads(resp.text, 4)
512504

@@ -594,7 +586,7 @@ def init_configurables(self):
594586
raise RuntimeError(msg)
595587

596588
api_module = self._load_api_module(self.api)
597-
func = getattr(api_module, "create_personality")
589+
func = api_module.create_personality
598590
self.personality = func(parent=self, log=self.log)
599591

600592
self.io_loop.call_later(
@@ -701,7 +693,7 @@ def init_http_server(self):
701693
for port in random_ports(self.port, self.port_retries + 1):
702694
try:
703695
self.http_server.listen(port, self.ip)
704-
except socket.error as e:
696+
except OSError as e:
705697
if e.errno == errno.EADDRINUSE:
706698
self.log.info("The port %i is already in use, trying another port." % port)
707699
continue
@@ -764,7 +756,7 @@ def _confirm_exit(self):
764756
return
765757
yes = "y"
766758
no = "n"
767-
sys.stdout.write("Shutdown this Jupyter server (%s/[%s])? " % (yes, no))
759+
sys.stdout.write("Shutdown this Jupyter server (%s/[%s])? " % (yes, no)) # noqa: UP031
768760
sys.stdout.flush()
769761
r, w, x = select.select([sys.stdin], [], [], 5)
770762
if r:

0 commit comments

Comments
 (0)