Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add formatting and lint config #392

Merged
merged 3 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Initial pre-commit reformat
92edb7756e411f7e8295013b5da6a4255e89ac75
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
updates:
# GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
groups:
actions:
patterns:
- "*"
# Python
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Tests

on:
workflow_dispatch:
push:
pull_request:
branches:
Expand Down
69 changes: 68 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,77 @@
ci:
autoupdate_schedule: monthly
autoupdate_commit_msg: "chore: update pre-commit hooks"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-case-conflict
- id: check-ast
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-json
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.3
hooks:
- id: check-github-workflows

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies:
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v4.0.0-alpha.8"
hooks:
- id: prettier
types_or: [yaml, html, json]

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.6"
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/pre-commit/mirrors-mypy
rev: "v1.8.0"
hooks:
- id: mypy
files: kernel_gateway
stages: [manual]
additional_dependencies: []

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.9
hooks:
- id: ruff
types_or: [python, jupyter]
args: ["--fix", "--show-fixes"]
exclude: ^kernel_gateway/tests/resources/
- id: ruff-format
types_or: [python, jupyter]
exclude: ^kernel_gateway/tests/resources/

- repo: https://github.com/scientific-python/cookie
rev: "2023.12.21"
hooks:
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"]
17 changes: 17 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 2
build:
os: ubuntu-22.04
tools:
python: "3.9"
sphinx:
configuration: docs/source/conf.py
python:
install:
# install itself with pip install .
- method: pip
path: .
extra_requirements:
- docs
formats:
- epub
- htmlzip
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
- Add support for specifying notebook-http APIs using full Swagger specs
- Add option to serve static web assets from Tornado in notebook-http mode
- Add command line aliases for common options (e.g., `--ip`)
- Fix Tornado 4.4 compatbility: sending an empty body string with a 204 response
- Fix Tornado 4.4 compatibility: sending an empty body string with a 204 response

## 1.0.0 (2016-07-15)

Expand Down
19 changes: 13 additions & 6 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

import os
import logging
import pytest
import os
from binascii import hexlify
from traitlets.config import Config
from kernel_gateway.gatewayapp import KernelGatewayApp

# isort: off
# This must come before any Jupyter imports.
os.environ["JUPYTER_PLATFORM_DIRS"] = "1"
# isort: on

import pytest # noqa: E402
from traitlets.config import Config # noqa: E402

from kernel_gateway.gatewayapp import KernelGatewayApp # noqa: E402

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

Expand Down Expand Up @@ -92,13 +99,13 @@ def jp_server_cleanup(jp_asyncio_loop):
try:
jp_asyncio_loop.run_until_complete(app.async_shutdown())
except (RuntimeError, SystemExit) as e:
print("ignoring cleanup error", e)
print("ignoring cleanup error", e) # noqa: T201
if hasattr(app, "kernel_manager"):
app.kernel_manager.context.destroy()
KernelGatewayApp.clear_instance()


@pytest.fixture
@pytest.fixture()
def jp_auth_header(jp_serverapp):
"""Configures an authorization header using the token from the serverapp fixture."""
return {"Authorization": f"token {jp_serverapp.identity_provider.token}"}
5 changes: 2 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# This file is execfile()d with the current directory set to its
# containing dir.
Expand Down Expand Up @@ -60,7 +59,7 @@
#
_version_py = "../../kernel_gateway/_version.py"
version_ns = {}
exec(compile(open(_version_py).read(), _version_py, "exec"), version_ns)
exec(compile(open(_version_py).read(), _version_py, "exec"), version_ns) # noqa: S102
# The short X.Y version.
version = "%i.%i" % version_ns["version_info"][:2]
# The full version, including alpha/beta/rc tags.
Expand Down Expand Up @@ -337,7 +336,7 @@
# The format is a list of tuples containing the path and title.
# epub_pre_files = []

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

Expand Down
2 changes: 1 addition & 1 deletion docs/source/summary-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ See `git log` for a more detailed summary of changes.
- Add support for specifying notebook-http APIs using full Swagger specs
- Add option to serve static web assets from Tornado in notebook-http mode
- Add command line aliases for common options (e.g., `--ip`)
- Fix Tornado 4.4 compatbility: sending an empty body string with a 204 response
- Fix Tornado 4.4 compatibility: sending an empty body string with a 204 response

## 1.0

Expand Down
5 changes: 3 additions & 2 deletions etc/api_examples/setting_response_metadata.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@
},
"outputs": [],
"source": [
"import hashlib\n",
"import json\n",
"from dicttoxml import dicttoxml\n",
"import hashlib"
"\n",
"from dicttoxml import dicttoxml"
]
},
{
Expand Down
5 changes: 2 additions & 3 deletions kernel_gateway/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
"""Entrypoint for the kernel gateway package."""
from .gatewayapp import launch_instance

from ._version import version_info, __version__
from ._version import __version__, version_info # noqa: F401
from .gatewayapp import launch_instance # noqa: F401
1 change: 0 additions & 1 deletion kernel_gateway/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
"""CLI entrypoint for the kernel gateway package."""
from __future__ import absolute_import

if __name__ == "__main__":
import kernel_gateway.gatewayapp as app
Expand Down
5 changes: 2 additions & 3 deletions kernel_gateway/auth/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
This defines the _authentication_ layer of Jupyter Server,
to be used in combination with Authorizer for _authorization_.
"""
from traitlets import default
from tornado import web

from jupyter_server.auth.identity import IdentityProvider, User
from jupyter_server.base.handlers import JupyterHandler
from tornado import web
from traitlets import default


class GatewayIdentityProvider(IdentityProvider):
Expand Down
7 changes: 3 additions & 4 deletions kernel_gateway/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# Distributed under the terms of the Modified BSD License.
"""Tornado handlers for the base of the API."""

from tornado import web
import jupyter_server.base.handlers as server_handlers
from ..mixins import TokenAuthorizationMixin, CORSMixin, JSONErrorsMixin
from tornado import web

from ..mixins import CORSMixin, JSONErrorsMixin, TokenAuthorizationMixin


class APIVersionHandler(
Expand All @@ -14,8 +15,6 @@ class APIVersionHandler(
JSON errors.
"""

pass


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