Skip to content

Commit

Permalink
Add spelling and docstring enforcement (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Dec 23, 2022
1 parent 6666e17 commit dfd340f
Show file tree
Hide file tree
Showing 21 changed files with 77 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ 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:
runs-on: ubuntu-latest
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
Expand Down
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,7 +36,7 @@ repos:
- id: black

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.165
rev: v0.0.189
hooks:
- id: ruff
args: ["--fix"]
1 change: 1 addition & 0 deletions jupyterlab_server/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""CLI entry point for jupyterlab server."""
import sys

from jupyterlab_server.app import main
Expand Down
2 changes: 2 additions & 0 deletions jupyterlab_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ def _deprecated_trait(self, change):
setattr(self, new_attr, change.new)

def initialize_templates(self):
"""Initialize templates."""
self.static_paths = [self.static_dir]
self.template_paths = [self.templates_dir]

def initialize_handlers(self):
"""Initialize handlers."""
add_handlers(self.handlers, self)


Expand Down
3 changes: 3 additions & 0 deletions jupyterlab_server/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,11 @@ def get(self, mode=None, workspace=None, tree=None):


class NotFoundHandler(LabHandler):
"""A handler for page not found."""

@lru_cache() # noqa
def get_page_config(self):
"""Get the page config."""
page_config = super().get_page_config()
page_config["notFoundUrl"] = self.request.path
return page_config
Expand Down
5 changes: 5 additions & 0 deletions jupyterlab_server/licenses_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class MyApp(JupyterApp, LabConfig):


class LicensesApp(JupyterApp, LabConfig):
"""A license management app."""

version = __version__

description = """
Expand Down Expand Up @@ -71,15 +73,18 @@ class LicensesApp(JupyterApp, LabConfig):
}

def initialize(self, *args, **kwargs):
"""Initialize the app."""
super().initialize(*args, **kwargs)
self.init_licenses_manager()

def init_licenses_manager(self):
"""Initialize the license manager."""
self.licenses_manager = LicensesManager(
parent=self,
)

def start(self):
"""Start the app."""
report = self.licenses_manager.report(
report_format=self.report_format,
full_text=self.full_text,
Expand Down
1 change: 1 addition & 0 deletions jupyterlab_server/licenses_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ class LicensesHandler(APIHandler):
"""A handler for serving licenses used by the application"""

def initialize(self, manager: LicensesManager) -> None:
"""Initialize the handler."""
super().initialize()
self.manager = manager

Expand Down
2 changes: 2 additions & 0 deletions jupyterlab_server/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
else:

def list2cmdline(cmd_list):
"""Shim for list2cmdline on posix."""
import shlex

return " ".join(map(shlex.quote, cmd_list))
Expand Down Expand Up @@ -179,6 +180,7 @@ def _cleanup(cls):
proc.terminate()

def get_log(self):
"""Get our logger."""
if hasattr(self, "logger") and self.logger:
return self.logger
# fallback logger
Expand Down
1 change: 1 addition & 0 deletions jupyterlab_server/process_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def initialize_settings(self):
IOLoop.current().add_callback(self._run_command)

def initialize_handlers(self):
"""Initialize the handlers."""
add_handlers(self.handlers, self)

def _run_command(self):
Expand Down
7 changes: 6 additions & 1 deletion jupyterlab_server/pytest_plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""pytest fixtures."""
import json
import os
import os.path as osp
Expand All @@ -12,6 +13,7 @@


def mkdir(tmp_path, *parts):
"""Util for making a directory."""
path = tmp_path.joinpath(*parts)
if not path.exists():
path.mkdir(parents=True)
Expand All @@ -37,8 +39,10 @@ def make_labserver_extension_app(
workspaces_dir,
labextensions_dir,
):
def _make_labserver_extension_app(**kwargs):
"""Return a factory function for a labserver extension app."""

def _make_labserver_extension_app(**kwargs):
"""Factory function for lab server extension apps."""
return LabServerApp(
static_dir=str(jp_root_dir),
templates_dir=str(jp_template_dir),
Expand Down Expand Up @@ -127,6 +131,7 @@ def _make_labserver_extension_app(**kwargs):

@pytest.fixture
def labserverapp(jp_serverapp, make_labserver_extension_app):
"""A lab server app."""
app = make_labserver_extension_app()
app._link_jupyter_server_extension(jp_serverapp)
app.initialize()
Expand Down
1 change: 1 addition & 0 deletions jupyterlab_server/server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Server api."""
from jupyter_server import _tz as tz # noqa
from jupyter_server.base.handlers import (
APIHandler,
Expand Down
3 changes: 3 additions & 0 deletions jupyterlab_server/settings_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@


class SettingsHandler(ExtensionHandlerMixin, ExtensionHandlerJinjaMixin, SchemaHandler):
"""A settings API handler."""

def initialize(
self, name, app_settings_dir, schemas_dir, settings_dir, labextensions_path, **kwargs
):
"""Initialize the handler."""
SchemaHandler.initialize(
self, app_settings_dir, schemas_dir, settings_dir, labextensions_path
)
Expand Down
1 change: 1 addition & 0 deletions jupyterlab_server/settings_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ class SchemaHandler(APIHandler):
"""Base handler for handler requiring access to settings."""

def initialize(self, app_settings_dir, schemas_dir, settings_dir, labextensions_path, **kwargs):
"""Initialize the handler."""
super().initialize(**kwargs)
self.overrides, error = _get_overrides(app_settings_dir)
self.app_settings_dir = app_settings_dir
Expand Down
1 change: 1 addition & 0 deletions jupyterlab_server/spec.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""OpenAPI spec utils."""
import os
from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions jupyterlab_server/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Testing utils."""
import json
import os
import sys
Expand Down
2 changes: 1 addition & 1 deletion jupyterlab_server/themes_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def initialize(
labextensions_path=None,
**kwargs,
):

"""Initialize the handler."""
# Get all of the available theme paths in order
labextensions_path = labextensions_path or []
ext_paths = []
Expand Down
1 change: 1 addition & 0 deletions jupyterlab_server/translation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ class TranslationBundle:
"""

def __init__(self, domain: str, locale: str):
"""Initialize the bundle."""
self._domain = domain
self._locale = locale

Expand Down
7 changes: 4 additions & 3 deletions jupyterlab_server/translations_handler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

"""
Translation handler.
"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

import json
import traceback
Expand All @@ -16,6 +15,8 @@


class TranslationsHandler(SchemaHandler):
"""Translation handler."""

@gen.coroutine
@tornado.web.authenticated
def get(self, locale=""):
Expand Down
13 changes: 12 additions & 1 deletion jupyterlab_server/workspaces_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@


class WorkspaceListApp(JupyterApp, LabConfig):
"""An app to list workspaces."""

version = __version__
description = """
Print all the workspaces available
Expand Down Expand Up @@ -54,10 +56,12 @@ class WorkspaceListApp(JupyterApp, LabConfig):
)

def initialize(self, *args, **kwargs):
"""Initialize the app."""
super().initialize(*args, **kwargs)
self.manager = WorkspacesManager(self.workspaces_dir)

def start(self):
"""Start the app."""
workspaces = self.manager.list_workspaces()
if self.jsonlines:
for workspace in workspaces:
Expand All @@ -70,6 +74,8 @@ def start(self):


class WorkspaceExportApp(JupyterApp, LabConfig):
"""A workspace export app."""

version = __version__
description = """
Export a JupyterLab workspace
Expand All @@ -81,10 +87,12 @@ class WorkspaceExportApp(JupyterApp, LabConfig):
"""

def initialize(self, *args, **kwargs):
"""Initialize the app."""
super().initialize(*args, **kwargs)
self.manager = WorkspacesManager(self.workspaces_dir)

def start(self):
"""Start the app."""
if len(self.extra_args) > 1: # pragma: no cover
warnings.warn("Too many arguments were provided for workspace export.")
self.exit(1)
Expand All @@ -98,6 +106,8 @@ def start(self):


class WorkspaceImportApp(JupyterApp, LabConfig):
"""A workspace import app."""

version = __version__
description = """
Import a JupyterLab workspace
Expand All @@ -119,11 +129,12 @@ class WorkspaceImportApp(JupyterApp, LabConfig):
aliases = {"name": "WorkspaceImportApp.workspace_name"}

def initialize(self, *args, **kwargs):
"""Initialize the app."""
super().initialize(*args, **kwargs)
self.manager = WorkspacesManager(self.workspaces_dir)

def start(self):

"""Start the app."""
if len(self.extra_args) != 1: # pragma: no cover
self.log.info("One argument is required for workspace import.")
self.exit(1)
Expand Down
3 changes: 3 additions & 0 deletions jupyterlab_server/workspaces_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ def save(self, space_name: str, raw: str) -> Path:


class WorkspacesHandler(ExtensionHandlerMixin, ExtensionHandlerJinjaMixin, APIHandler):
"""A workspaces API handler."""

def initialize(self, name, manager: WorkspacesManager, **kwargs) -> None: # type:ignore
"""Initialize the handler."""
super().initialize(name)
self.manager = manager

Expand Down
29 changes: 20 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ test = [
# openapi_core 0.15.0 alpha is not working
"openapi_core~=0.14.2",
"openapi-spec-validator<0.6",
"sphinxcontrib_spelling",
"requests_mock",
"pytest>=7.0",
"pytest-console-scripts",
Expand All @@ -81,13 +82,6 @@ test = [
"ruamel.yaml",
"strict-rfc3339"
]
lint = [
"black[jupyter]>=22.6.0",
"mdformat>0.7",
"mdformat-gfm>=0.3.5",
"ruff>=0.0.156"
]
typing = ["mypy>=0.990"]

[tool.hatch.version]
path = "jupyterlab_server/_version.py"
Expand All @@ -112,12 +106,19 @@ test = "python -m pytest -vv --cov jupyterlab_server --cov-branch --cov-report t
nowarn = "test -W default {args}"

[tool.hatch.envs.typing]
features = ["typing", "test"]
features = ["test"]
dependencies = ["mypy>=0.990"]
[tool.hatch.envs.typing.scripts]
test = "mypy --install-types --non-interactive {args:jupyterlab_server tests}"

[tool.hatch.envs.lint]
features = ["lint"]
dependencies = [
"black[jupyter]==22.6.0",
"mdformat>0.7",
"mdformat-gfm>=0.3.5",
"ruff==0.0.189"
]
detatched = true
[tool.hatch.envs.lint.scripts]
style = [
"ruff {args:.}",
Expand Down Expand Up @@ -215,3 +216,13 @@ ignore = [
"tests/*" = ["S101", "A001", "F841"]
# F401 `foo` imported but unused
"jupyterlab_server/server.py" = ["F401"]

[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", "docs"]

0 comments on commit dfd340f

Please sign in to comment.