Skip to content

Commit

Permalink
Adopt sp-repo-review (#295)
Browse files Browse the repository at this point in the history
* adopt sp-repo-review

* adopt sp-repo-review

* address typing

* fix tests

* restore tests location

* fix report

* fix tests

* fix tests

* set timeout

* windows fix

* try again

* update typings
  • Loading branch information
blink1073 authored Oct 5, 2023
1 parent 6a30722 commit c3609ea
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 170 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches: ["main"]
pull_request:
workflow_dispatch:
schedule:
- cron: "0 8 * * *"

Expand All @@ -18,8 +19,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- name: Run Linters
run: |
- name: Run Linters
run: |
hatch run typing:test
hatch run lint:style
pipx run interrogate -v .
Expand All @@ -36,11 +37,12 @@ jobs:
build:
name: Build, test and code coverage
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [ '3.8', '3.9', '3.10', "3.11" ]
python-version: ["3.8", "3.9", "3.10", "3.11"]
exclude:
- os: windows-latest
python-version: 3.8
Expand Down Expand Up @@ -113,9 +115,9 @@ jobs:
check_links:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- uses: jupyterlab/maintainer-tools/.github/actions/check-links@v1
- uses: actions/checkout@v4
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- uses: jupyterlab/maintainer-tools/.github/actions/check-links@v1

check_release:
runs-on: ubuntu-latest
Expand Down
39 changes: 36 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ci:
autoupdate_schedule: monthly
autoupdate_commit_msg: "chore: update pre-commit hooks"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -15,6 +16,7 @@ repos:
- id: check-json
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace

Expand All @@ -30,13 +32,44 @@ repos:
additional_dependencies:
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]

- repo: https://github.com/psf/black
rev: 23.9.1
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.2"
hooks:
- id: prettier
types_or: [yaml, html, json]

- repo: https://github.com/adamchainz/blacken-docs
rev: "1.16.0"
hooks:
- id: blacken-docs
additional_dependencies: [black==23.7.0]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.7.0
hooks:
- id: black

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.5"
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/astral-sh/ruff-pre-commit
rev: v0.0.292
hooks:
- id: ruff
args: ["--fix"]
args: ["--fix", "--show-fixes"]

- repo: https://github.com/scientific-python/cookie
rev: "2023.08.23"
hooks:
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"]
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ python:
build:
os: ubuntu-22.04
tools:
python: "3.11"
python: "3.11"
2 changes: 1 addition & 1 deletion docs/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ there are no execution errors. But, what if there are errors?
Execution until first error
~~~~~~~~~~~~~~~~~~~~~~~~~~~
An error during the notebook execution, by default, will stop the execution
and raise a `CellExecutionError`. Conveniently, the source cell causing
and raise a ``CellExecutionError``. Conveniently, the source cell causing
the error and the original error name and message are also printed.
After an error, we can still save the notebook as before::

Expand Down
17 changes: 3 additions & 14 deletions nbclient/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
import sys
from ._version import __version__, version_info
from .client import NotebookClient, execute

from ._version import __version__, version_info # noqa # noqa
from .client import NotebookClient, execute # noqa: F401


def _cleanup() -> None:
pass


# patch subprocess on Windows for python<3.7
# see https://bugs.python.org/issue37380
# the fix for python3.7: https://github.com/python/cpython/pull/15706/files
if sys.platform == 'win32':
pass
__all__ = ["__version__", "version_info", "NotebookClient", "execute"]
30 changes: 18 additions & 12 deletions nbclient/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""nbclient cli."""
from __future__ import annotations

import logging
import pathlib
import sys
import typing
from textwrap import dedent

import nbformat
Expand All @@ -13,13 +16,15 @@

from .client import NotebookClient

nbclient_aliases: dict = {
# mypy: disable-error-code="no-untyped-call"

nbclient_aliases: dict[str, str] = {
'timeout': 'NbClientApp.timeout',
'startup_timeout': 'NbClientApp.startup_timeout',
'kernel_name': 'NbClientApp.kernel_name',
}

nbclient_flags: dict = {
nbclient_flags: dict[str, typing.Any] = {
'allow-errors': (
{
'NbClientApp': {
Expand All @@ -43,7 +48,7 @@ class NbClientApp(JupyterApp):

description = "An application used to execute notebook files (*.ipynb)"
notebooks = List([], help="Path of notebooks to convert").tag(config=True)
timeout: int = Integer(
timeout = Integer(
None,
allow_none=True,
help=dedent(
Expand All @@ -54,7 +59,7 @@ class NbClientApp(JupyterApp):
"""
),
).tag(config=True)
startup_timeout: int = Integer(
startup_timeout = Integer(
60,
help=dedent(
"""
Expand All @@ -64,7 +69,7 @@ class NbClientApp(JupyterApp):
"""
),
).tag(config=True)
allow_errors: bool = Bool(
allow_errors = Bool(
False,
help=dedent(
"""
Expand All @@ -76,15 +81,15 @@ class NbClientApp(JupyterApp):
"""
),
).tag(config=True)
skip_cells_with_tag: str = Unicode(
skip_cells_with_tag = Unicode(
'skip-execution',
help=dedent(
"""
Name of the cell tag to use to denote a cell that should be skipped.
"""
),
).tag(config=True)
kernel_name: str = Unicode(
kernel_name = Unicode(
'',
help=dedent(
"""
Expand All @@ -95,11 +100,11 @@ class NbClientApp(JupyterApp):
).tag(config=True)

@default('log_level')
def _log_level_default(self):
def _log_level_default(self) -> int:
return logging.INFO

@catch_config_error
def initialize(self, argv=None):
def initialize(self, argv: list[str] | None = None) -> None:
"""Initialize the app."""
super().initialize(argv)

Expand All @@ -111,9 +116,10 @@ def initialize(self, argv=None):
sys.exit(-1)

# Loop and run them one by one
[self.run_notebook(path) for path in self.notebooks]
for path in self.notebooks:
self.run_notebook(path)

def get_notebooks(self):
def get_notebooks(self) -> list[str]:
"""Get the notebooks for the app."""
# If notebooks were provided from the command line, use those
if self.extra_args:
Expand All @@ -125,7 +131,7 @@ def get_notebooks(self):
# Return what we got.
return notebooks

def run_notebook(self, notebook_path):
def run_notebook(self, notebook_path: str) -> None:
"""Run a notebook by path."""
# Log it
self.log.info(f"Executing {notebook_path}")
Expand Down
Loading

0 comments on commit c3609ea

Please sign in to comment.