Skip to content

Commit 5cce2af

Browse files
authored
Clean up docs build and typing (#1168)
Fixes #1125
1 parent 3d516b3 commit 5cce2af

File tree

13 files changed

+74
-119
lines changed

13 files changed

+74
-119
lines changed

docs/Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,11 @@ clean:
5353
rm -rf $(BUILDDIR)/*
5454
rm -rf source/config.rst
5555

56-
html: source/config.rst
56+
html:
5757
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
5858
@echo
5959
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
6060

61-
source/config.rst:
62-
python3 autogen_config.py
63-
@echo "Created docs for config options"
64-
6561
dirhtml:
6662
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
6763
@echo

docs/autogen_config.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

docs/source/conf.py

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,56 +11,14 @@
1111
#
1212
# All configuration values have a default; values that are commented out
1313
# serve to show the default.
14-
import logging
1514
import os
1615
import os.path as osp
1716
import shutil
1817
import sys
19-
from importlib.metadata import version
20-
21-
from packaging.version import parse as parse_version
2218

2319
HERE = osp.abspath(osp.dirname(__file__))
24-
25-
26-
# If extensions (or modules to document with autodoc) are in another directory,
27-
# add these directories to sys.path here. If the directory is relative to the
28-
# documentation root, use os.path.abspath to make it absolute, like shown here.
29-
30-
# DEBUG for RTD
31-
log = logging.getLogger(__name__)
32-
info = log.info
33-
info("DEBUG:: sys.path")
34-
info("================")
35-
for item in sys.path:
36-
info(item)
37-
38-
# add repo root to sys.path
39-
# here = root/docs/source
40-
here = os.path.abspath(os.path.dirname(__file__))
41-
repo_root = os.path.dirname(os.path.dirname(here))
42-
sys.path.insert(0, repo_root)
43-
44-
info("repo_root")
45-
info("=====================")
46-
info(repo_root)
47-
48-
# DEBUG for post insert on RTD
49-
info("DEBUG:: Post insert to sys.path")
50-
info("===============================")
51-
for item in sys.path:
52-
info(item)
53-
54-
# Check if docs are being built by ReadTheDocs
55-
# If so, generate a config.rst file and populate it with documentation about
56-
# configuration options
57-
58-
if os.environ.get("READTHEDOCS", ""):
59-
60-
# Readthedocs doesn't run our Makefile, so we do this to force it to generate
61-
# the config docs.
62-
with open("../autogen_config.py") as f:
63-
exec(compile(f.read(), "../autogen_config.py", "exec"), {}) # noqa
20+
sys.path.insert(0, osp.join(HERE, "..", ""))
21+
from jupyter_server._version import version_info
6422

6523
# -- General configuration ------------------------------------------------
6624

@@ -119,10 +77,8 @@
11977
# |version| and |release|, also used in various other places throughout the
12078
# built documents.
12179
#
122-
__version__ = version("jupyter_server")
12380
# The short X.Y version.
124-
version_parsed = parse_version(__version__)
125-
version = f"{version_parsed.major}.{version_parsed.minor}" # type:ignore
81+
version = f"{version_info[0]}.{version_info[1]}"
12682

12783
# The language for content autogenerated by Sphinx. Refer to documentation
12884
# for a list of supported languages.
@@ -382,7 +338,48 @@
382338
# import before any doc is built, so _ is guaranteed to be injected
383339
import jupyter_server.transutils # noqa: F401
384340

341+
CONFIG_HEADER = """\
342+
.. _other-full-config:
343+
344+
345+
Config file and command line options
346+
====================================
347+
348+
The Jupyter Server can be run with a variety of command line arguments.
349+
A list of available options can be found below in the :ref:`options section
350+
<options>`.
351+
352+
Defaults for these options can also be set by creating a file named
353+
``jupyter_server_config.py`` in your Jupyter folder. The Jupyter
354+
folder is in your home directory, ``~/.jupyter``.
355+
356+
To create a ``jupyter_server_config.py`` file, with all the defaults
357+
commented out, you can use the following command line::
358+
359+
$ jupyter server --generate-config
360+
361+
362+
.. _options:
363+
364+
Options
365+
-------
366+
367+
This list of options can be generated by running the following and hitting
368+
enter::
369+
370+
$ jupyter server --help-all
371+
372+
"""
373+
385374

386375
def setup(app):
387376
dest = osp.join(HERE, "other", "changelog.md")
388377
shutil.copy(osp.join(HERE, "..", "..", "CHANGELOG.md"), dest)
378+
379+
# Generate full-config docs.
380+
from jupyter_server.serverapp import ServerApp
381+
382+
destination = os.path.join(HERE, "other/full-config.rst")
383+
with open(destination, "w") as f:
384+
f.write(CONFIG_HEADER)
385+
f.write(ServerApp().document_config_options())

examples/identity/system_password/jupyter_server_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pwd
33
from getpass import getuser
44

5-
from pamela import PAMError, authenticate
5+
from pamela import PAMError, authenticate # type:ignore
66

77
from jupyter_server.auth.identity import IdentityProvider, User
88

jupyter_server/gateway/managers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from time import monotonic
1212
from typing import Any, Dict, Optional
1313

14-
import websocket
14+
import websocket # type:ignore
1515
from jupyter_client.asynchronous.client import AsyncKernelClient
1616
from jupyter_client.clientabc import KernelClientABC
1717
from jupyter_client.kernelspec import KernelSpecManager

jupyter_server/services/events/handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ def open(self):
5555
"""Routes events that are emitted by Jupyter Server's
5656
EventBus to a WebSocket client in the browser.
5757
"""
58-
self.event_logger.add_listener(listener=self.event_listener)
58+
self.event_logger.add_listener(listener=self.event_listener) # type:ignore[arg-type]
5959

6060
def on_close(self):
6161
"""Handle a socket close."""
62-
self.event_logger.remove_listener(listener=self.event_listener)
62+
self.event_logger.remove_listener(listener=self.event_listener) # type:ignore[arg-type]
6363

6464

6565
def validate_model(data: Dict[str, Any]) -> None:

jupyter_server/services/sessions/sessionmanager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import sqlite3
1515
except ImportError:
1616
# fallback on pysqlite2 if Python was build without sqlite
17-
from pysqlite2 import dbapi2 as sqlite3 # type:ignore[no-redef]
17+
from pysqlite2 import dbapi2 as sqlite3 # type:ignore
1818

1919
from dataclasses import dataclass, fields
2020

jupyter_server/terminal/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import warnings
33

44
# Shims
5-
from jupyter_server_terminals import api_handlers, initialize # noqa
5+
from jupyter_server_terminals import api_handlers # noqa
66
from jupyter_server_terminals.handlers import TermSocket # noqa
77
from jupyter_server_terminals.terminalmanager import TerminalManager # noqa
88

@@ -11,3 +11,7 @@
1111
DeprecationWarning,
1212
stacklevel=2,
1313
)
14+
15+
16+
def initialize(webapp, root_dir, connection_url, settings):
17+
"""Included for backward compat, but no-op."""
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
"""Terminal API handlers."""
2-
from jupyter_server_terminals import TerminalAPIHandler, TerminalHandler, TerminalRootHandler
2+
from jupyter_server_terminals.api_handlers import (
3+
TerminalAPIHandler,
4+
TerminalHandler,
5+
TerminalRootHandler,
6+
)

jupyter_server/terminal/terminalmanager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
"""
55
# Copyright (c) Jupyter Development Team.
66
# Distributed under the terms of the Modified BSD License.
7-
from jupyter_server_terminals import TerminalManager # noqa
7+
from jupyter_server_terminals.terminalmanager import TerminalManager # noqa

jupyter_server/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
)
2121
from urllib.request import pathname2url # noqa: F401
2222

23-
from _frozen_importlib_external import _NamespacePath
23+
from _frozen_importlib_external import _NamespacePath # type:ignore
2424
from jupyter_core.utils import ensure_async
2525
from packaging.version import Version
2626
from tornado.httpclient import AsyncHTTPClient, HTTPClient, HTTPRequest

pyproject.toml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ filterwarnings = [
229229
"ignore:run_pre_save_hook is deprecated:DeprecationWarning",
230230
"always:unclosed <socket.socket:ResourceWarning",
231231
"module:Jupyter is migrating its paths to use standard platformdirs:DeprecationWarning",
232-
"ignore:jupyter_server.base.zmqhandlers module is deprecated in Jupyter Server 2.0:DeprecationWarning"
232+
"ignore:jupyter_server.base.zmqhandlers module is deprecated in Jupyter Server 2.0:DeprecationWarning",
233+
"ignore:zmq.eventloop.ioloop is deprecated in pyzmq 17:DeprecationWarning",
233234
]
234235

235236
[tool.coverage.report]
@@ -268,18 +269,6 @@ warn_redundant_casts = true
268269
explicit_package_bases = true
269270
namespace_packages = true
270271

271-
[[tool.mypy.overrides]]
272-
module = [
273-
"pamela",
274-
"pysqlite2",
275-
"jupyter_events.*",
276-
"jupyter_server_terminals.*",
277-
"_frozen_importlib_external",
278-
"send2trash",
279-
"websocket"
280-
]
281-
ignore_missing_imports = true
282-
283272
[tool.interrogate]
284273
ignore-init-module=true
285274
ignore-private=true

tests/test_terminal.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import shlex
55
import shutil
66
import sys
7+
import warnings
78

89
import pytest
910
from tornado.httpclient import HTTPClientError
@@ -291,3 +292,12 @@ def test_shell_command_override(
291292
)
292293
else:
293294
assert app.web_app.settings["terminal_manager"].shell_command == expected_shell
295+
296+
297+
def test_importing_shims():
298+
with warnings.catch_warnings():
299+
warnings.simplefilter("ignore")
300+
from jupyter_server.terminal import initialize # noqa
301+
from jupyter_server.terminal.api_handlers import TerminalRootHandler # noqa
302+
from jupyter_server.terminal.handlers import TermSocket # noqa
303+
from jupyter_server.terminal.terminalmanager import TerminalManager # noqa

0 commit comments

Comments
 (0)