Skip to content

Commit dcaeb56

Browse files
authored
Add spell check and ensure docstrings (#1226)
* add spelling and docstring enforcement * lint
1 parent 668a391 commit dcaeb56

File tree

32 files changed

+216
-78
lines changed

32 files changed

+216
-78
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
ignore_links: "http://my-gateway-server.com:8888"
7777

7878
build_docs:
79-
runs-on: ubuntu-latest
79+
runs-on: windows-latest
8080
steps:
8181
- name: Checkout
8282
uses: actions/checkout@v3

.pre-commit-config.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
66
rev: v4.4.0
77
hooks:
8-
- id: end-of-file-fixer
98
- id: check-case-conflict
9+
- id: check-ast
10+
- id: check-docstring-first
1011
- id: check-executables-have-shebangs
11-
- id: requirements-txt-fixer
1212
- id: check-added-large-files
1313
- id: check-case-conflict
14+
- id: check-merge-conflict
15+
- id: check-json
1416
- id: check-toml
1517
- id: check-yaml
1618
exclude: etc/kubernetes/.*.yaml
17-
- id: debug-statements
18-
- id: forbid-new-submodules
19+
- id: end-of-file-fixer
1920
- id: trailing-whitespace
2021

2122
- repo: https://github.com/python-jsonschema/check-jsonschema

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ lint: ## Check code style
7171
black --check --diff --color .
7272
mdformat --check *.md
7373
pipx run 'validate-pyproject[all]' pyproject.toml
74+
pipx run interrogate -v .
7475

7576
run-dev: test-install-wheel ## Make a server in jupyter_websocket mode
7677
python enterprise_gateway

docs/doc-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ sphinx_book_theme
88
sphinxcontrib-mermaid
99
sphinxcontrib-openapi
1010
sphinxcontrib_github_alt
11+
sphinxcontrib_spelling
1112
sphinxemoji
1213
tornado

docs/source/conf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
"sphinxemoji.sphinxemoji",
3737
]
3838

39+
try:
40+
import enchant # noqa
41+
42+
extensions += ["sphinxcontrib.spelling"]
43+
except ImportError:
44+
pass
45+
3946
myst_enable_extensions = ["html_image"]
4047
myst_heading_anchors = 4 # Needs to be 4 or higher
4148

enterprise_gateway/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
"""Lazy-loading entrypoint for the enterprise gateway package."""
12
# Copyright (c) Jupyter Development Team.
23
# Distributed under the terms of the Modified BSD License.
34
from ._version import __version__ # noqa
45

5-
"""Lazy-loading entrypoint for the enterprise gateway package."""
6-
76

87
def launch_instance(*args, **kwargs):
98
from enterprise_gateway.enterprisegatewayapp import launch_instance

enterprise_gateway/base/handlers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
"""Tornado handlers for the base of the API."""
12
# Copyright (c) Jupyter Development Team.
23
# Distributed under the terms of the Modified BSD License.
3-
"""Tornado handlers for the base of the API."""
4+
45

56
import json
67
from typing import List
@@ -20,6 +21,7 @@ class APIVersionHandler(TokenAuthorizationMixin, CORSMixin, JSONErrorsMixin, API
2021
"""
2122

2223
def get(self):
24+
"""Get the API version."""
2325
# not authenticated, so give as few info as possible
2426
# to be backwards compatibile, use only 'version' for the jupyter_server version
2527
# and be more specific for gateway_version
@@ -41,6 +43,7 @@ class NotFoundHandler(JSONErrorsMixin, web.RequestHandler):
4143
"""
4244

4345
def prepare(self):
46+
"""Prepare the response."""
4447
raise web.HTTPError(404)
4548

4649

enterprise_gateway/client/gateway_client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""An Enterprise Gateway client."""
12
import logging
23
import os
34
import queue as queue
@@ -29,12 +30,14 @@ class GatewayClient:
2930
KERNEL_LAUNCH_TIMEOUT = os.getenv("KERNEL_LAUNCH_TIMEOUT", "40")
3031

3132
def __init__(self, host=DEFAULT_GATEWAY_HOST):
33+
"""Initialize the client."""
3234
self.http_api_endpoint = f"http://{host}/api/kernels"
3335
self.ws_api_endpoint = f"ws://{host}/api/kernels"
3436
self.log = logging.getLogger("GatewayClient")
3537
self.log.setLevel(log_level)
3638

3739
def start_kernel(self, kernelspec_name, username=DEFAULT_USERNAME, timeout=REQUEST_TIMEOUT):
40+
"""Start a kernel."""
3841
self.log.info(f"Starting a {kernelspec_name} kernel ....")
3942

4043
json_data = {
@@ -66,6 +69,7 @@ def start_kernel(self, kernelspec_name, username=DEFAULT_USERNAME, timeout=REQUE
6669
)
6770

6871
def shutdown_kernel(self, kernel):
72+
"""Shut down a kernel."""
6973
self.log.info(f"Shutting down kernel : {kernel.kernel_id} ....")
7074

7175
if not kernel:
@@ -83,6 +87,7 @@ def shutdown_kernel(self, kernel):
8387

8488

8589
class KernelClient:
90+
"""A kernel client class."""
8691

8792
DEAD_MSG_ID = "deadbeefdeadbeefdeadbeefdeadbeef"
8893
POST_IDLE_TIMEOUT = 0.5
@@ -91,6 +96,7 @@ class KernelClient:
9196
def __init__(
9297
self, http_api_endpoint, ws_api_endpoint, kernel_id, timeout=REQUEST_TIMEOUT, logger=None
9398
):
99+
"""Initialize the client."""
94100
self.shutting_down = False
95101
self.restarting = False
96102
self.http_api_endpoint = http_api_endpoint
@@ -113,6 +119,7 @@ def __init__(
113119
self.interrupt_thread = None
114120

115121
def shutdown(self):
122+
"""Shut down the client."""
116123
# Terminate thread, close socket and clear queues.
117124
self.shutting_down = True
118125

@@ -204,6 +211,7 @@ def execute(self, code, timeout=REQUEST_TIMEOUT):
204211
return "".join(response)
205212

206213
def interrupt(self):
214+
"""Interrupt the kernel."""
207215
url = "{}/{}".format(self.kernel_http_api_endpoint, "interrupt")
208216
response = requests.post(url)
209217
if response.status_code == 204:
@@ -217,6 +225,7 @@ def interrupt(self):
217225
)
218226

219227
def restart(self, timeout=REQUEST_TIMEOUT):
228+
"""Restart the kernel."""
220229
self.restarting = True
221230
self.kernel_socket.close()
222231
self.kernel_socket = None
@@ -238,6 +247,7 @@ def restart(self, timeout=REQUEST_TIMEOUT):
238247
)
239248

240249
def get_state(self):
250+
"""Get the state of the client."""
241251
url = f"{self.kernel_http_api_endpoint}"
242252
response = requests.get(url)
243253
if response.status_code == 200:
@@ -252,14 +262,17 @@ def get_state(self):
252262
)
253263

254264
def start_interrupt_thread(self, wait_time=DEFAULT_INTERRUPT_WAIT):
265+
"""Start the interrupt thread."""
255266
self.interrupt_thread = Thread(target=self.perform_interrupt, args=(wait_time,))
256267
self.interrupt_thread.start()
257268

258269
def perform_interrupt(self, wait_time):
270+
"""Perform an interrupt on the client."""
259271
time.sleep(wait_time) # Allow parent to start executing cell to interrupt
260272
self.interrupt()
261273

262274
def terminate_interrupt_thread(self):
275+
"""Terminate the interrupt thread."""
263276
if self.interrupt_thread:
264277
self.interrupt_thread.join()
265278
self.interrupt_thread = None

0 commit comments

Comments
 (0)