Skip to content

Commit 6567bcb

Browse files
authored
Add formatting and lint config (#392)
* Add formatting and lint config * update rtd config * address deprecation warnings
1 parent 92edb77 commit 6567bcb

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

+358
-171
lines changed

.git-blame-ignore-revs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Initial pre-commit reformat
2+
92edb7756e411f7e8295013b5da6a4255e89ac75

.github/dependabot.yml

+16
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
+1
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

+68-1
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
3-
rev: v4.4.0
7+
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

+17
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

+1-1
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

+13-6
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

+2-3
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

+1-1
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

+3-2
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

+2-3
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

-1
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

+2-3
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

+3-4
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.

0 commit comments

Comments
 (0)