From 840b4256dad05706081c15916a9999c5444a9789 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 23 Dec 2022 14:55:19 -0600 Subject: [PATCH] Add spelling and docstring enforcement (#6669) * add spelling and docstring enforcement * remove markdown format * restore local hooks * add docs change * spelling --- .github/workflows/build.yml | 5 ++++- .pre-commit-config.yaml | 12 ++++++------ docs/source/conf.py | 7 +++++++ notebook/__main__.py | 1 + notebook/_version.py | 1 + notebook/app.py | 27 ++++++++++++++++++++++++--- pyproject.toml | 15 +++++++++++++-- 7 files changed, 56 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 07c1b3a53..481311754 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -69,6 +69,9 @@ jobs: - uses: actions/checkout@v3 - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - run: | + sudo apt-get update + sudo apt install enchant-2 # for spelling + # pandoc is not up to date in the ubuntu repos, so we install directly wget https://github.com/jgm/pandoc/releases/download/2.14.2/pandoc-2.14.2-1-amd64.deb && sudo dpkg -i pandoc-2.14.2-1-amd64.deb - run: hatch run docs:build @@ -169,7 +172,7 @@ jobs: run: | hatch run typing:test hatch run lint:style - pipx run 'validate-pyproject[all]' pyproject.toml + pipx run interrogate -v . pipx run doc8 --max-line-length=200 docs/source *.md npm install -g yarn yarn diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8bf411439..0bc10788c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,17 +5,17 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: - - id: end-of-file-fixer - id: check-case-conflict + - id: check-ast + - id: check-docstring-first - id: check-executables-have-shebangs - - id: requirements-txt-fixer - 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: forbid-new-submodules - - id: check-builtin-literals + - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/python-jsonschema/check-jsonschema @@ -29,7 +29,7 @@ repos: - id: black - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.185 + rev: v0.0.189 hooks: - id: ruff args: ["--fix"] diff --git a/docs/source/conf.py b/docs/source/conf.py index 4f43f37eb..14920e747 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -72,6 +72,13 @@ extensions = [ "myst_parser", ] +try: + import enchant # type:ignore # noqa + + extensions += ["sphinxcontrib.spelling"] +except ImportError: + pass + myst_enable_extensions = ["html_image"] myst_update_mathjax = False diff --git a/notebook/__main__.py b/notebook/__main__.py index 32d750c36..952b18ddf 100644 --- a/notebook/__main__.py +++ b/notebook/__main__.py @@ -1,3 +1,4 @@ +"""CLI entry point for notebook.""" import sys from notebook.app import main diff --git a/notebook/_version.py b/notebook/_version.py index 6b26e9a5a..dadb905bb 100644 --- a/notebook/_version.py +++ b/notebook/_version.py @@ -1,3 +1,4 @@ +"""Version info for notebook.""" # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. import re diff --git a/notebook/app.py b/notebook/app.py index 1d6f45d7a..cc9774c98 100644 --- a/notebook/app.py +++ b/notebook/app.py @@ -1,3 +1,4 @@ +"""Jupyter notebook application.""" import os from os.path import join as pjoin @@ -29,7 +30,10 @@ version = __version__ class NotebookBaseHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler): + """The base notebook API handler.""" + def get_page_config(self): # noqa:C901 + """Get the page config.""" config = LabConfig() app = self.extensionapp base_url = self.settings.get("base_url") @@ -112,12 +116,17 @@ class NotebookBaseHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, Jup class RedirectHandler(NotebookBaseHandler): + """A redirect handler.""" + @web.authenticated def get(self): + """Get the redirect url.""" return self.redirect(self.base_url + "tree") class TreeHandler(NotebookBaseHandler): + """A tree page handler.""" + @web.authenticated async def get(self, path=None): """ @@ -156,29 +165,41 @@ class TreeHandler(NotebookBaseHandler): class ConsoleHandler(NotebookBaseHandler): + """A console page handler.""" + @web.authenticated def get(self, path=None): + """Get the console page.""" tpl = self.render_template("consoles.html", page_config=self.get_page_config()) return self.write(tpl) class TerminalHandler(NotebookBaseHandler): + """A terminal page handler.""" + @web.authenticated def get(self, path=None): + """Get the terminal page.""" tpl = self.render_template("terminals.html", page_config=self.get_page_config()) return self.write(tpl) class FileHandler(NotebookBaseHandler): + """A file page handler.""" + @web.authenticated def get(self, path=None): + """Get the file page.""" tpl = self.render_template("edit.html", page_config=self.get_page_config()) return self.write(tpl) class NotebookHandler(NotebookBaseHandler): + """A notebook page handler.""" + @web.authenticated def get(self, path=None): + """Get the notebook page.""" tpl = self.render_template("notebooks.html", page_config=self.get_page_config()) return self.write(tpl) @@ -187,6 +208,8 @@ aliases = dict(base_aliases) class JupyterNotebookApp(NotebookConfigShimMixin, LabServerApp): + """The notebook server extension app.""" + name = "notebook" app_name = "Jupyter Notebook" description = "Jupyter Notebook - A web-based notebook environment for interactive computing" @@ -246,6 +269,7 @@ class JupyterNotebookApp(NotebookConfigShimMixin, LabServerApp): return get_workspaces_dir() def initialize_handlers(self): + """Initialize handlers.""" self.handlers.append( ( rf"/{self.file_url_prefix}/((?!.*\.ipynb($|\?)).*)", @@ -261,9 +285,6 @@ class JupyterNotebookApp(NotebookConfigShimMixin, LabServerApp): self.handlers.append(("/terminals/(.*)", TerminalHandler)) super().initialize_handlers() - def initialize_settings(self): - super().initialize_settings() - def initialize(self, argv=None): """Subclass because the ExtensionApp.initialize() method does not take arguments""" super().initialize() diff --git a/pyproject.toml b/pyproject.toml index 4223c5bf8..b8d9e972d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,6 +69,7 @@ docs = [ "pydata-sphinx-theme", "sphinx>=1.3.6", "sphinxcontrib_github_alt", + "sphinxcontrib_spelling" ] dev = [ "pre-commit", @@ -138,10 +139,10 @@ test = "mypy --install-types --non-interactive {args:notebook tests}" [tool.hatch.envs.lint] dependencies = [ - "black[jupyter]>=22.6.0", + "black[jupyter]==22.10.0", "mdformat>0.7", "mdformat-gfm>=0.3.5", - "ruff>=0.0.156" + "ruff==0.0.189" ] detached = true [tool.hatch.envs.lint.scripts] @@ -263,3 +264,13 @@ ignore = [ # S101 Use of `assert` detected # F841 Local variable `foo` is assigned to but never used "tests/*" = ["S101", "F841"] + +[tool.interrogate] +ignore-init-module=true +ignore-private=true +ignore-semiprivate=true +ignore-property-decorators=true +ignore-nested-functions=true +ignore-nested-classes=true +fail-under=100 +exclude = ["tests", "ui-tests", "docs", "node_modules", "setup.py"]