Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt ruff and address lint #267

Merged
merged 2 commits into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
version: 2
updates:
# Set update schedule for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every weekday
interval: "weekly"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
13 changes: 9 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ defaults:
shell: bash -eux {0}

jobs:
pre_commit:
name: pre-commit
test_lint:
name: Test Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- uses: jupyterlab/maintainer-tools/.github/actions/pre-commit@v1
- name: Run Linters
run: |
hatch run typing:test
hatch run lint:style
pipx run 'validate-pyproject[all]' pyproject.toml
pipx run doc8 --max-line-length=200

test_docs:
name: Test Docs
Expand Down Expand Up @@ -122,7 +127,7 @@ jobs:
if: always()
needs:
- build
- pre_commit
- test_lint
- test_docs
- test_minimum_versions
- test_prereleases
Expand Down
67 changes: 13 additions & 54 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
ci:
autoupdate_schedule: monthly
autofix_prs: true
autoupdate_schedule: monthly

repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand All @@ -20,64 +18,25 @@ repos:
- id: check-builtin-literals
- id: trailing-whitespace

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.0
hooks:
- id: pyupgrade
args: [--py37-plus]

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
files: \.py$
args: [--profile=black]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy
additional_dependencies: [jupyter_client, jupyter_core>=5.1, nbformat, nbconvert]

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.10.1
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.19.2
hooks:
- id: validate-pyproject
stages: [manual]
- id: check-github-workflows

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
hooks:
- id: mdformat
additional_dependencies:
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.0
hooks:
- id: pyupgrade
args: [--py37-plus]

- repo: https://github.com/PyCQA/doc8
rev: v1.0.0
hooks:
- id: doc8
args: [--max-line-length=200]


- repo: https://github.com/john-hen/Flake8-pyproject
rev: 1.2.2
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: Flake8-pyproject
alias: flake8
additional_dependencies:
["flake8-bugbear==22.6.22", "flake8-implicit-str-concat==0.2.0"]
stages: [manual]
- id: black

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.19.2
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.165
hooks:
- id: check-github-workflows
- id: ruff
args: ["--fix"]
15 changes: 7 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

# General information about the project.
project = 'nbclient'
copyright = '2020, Project Jupyter'
copyright = '2020, Project Jupyter' # noqa
author = 'Project Jupyter'

# The version info for the project you're documenting, acts as replacement for
Expand Down Expand Up @@ -179,14 +179,13 @@


def setup(app):
HERE = os.path.abspath(os.path.dirname(__file__))
dest = os.path.join(HERE, 'changelog.md')
shutil.copy(os.path.join(HERE, '..', 'CHANGELOG.md'), dest)
here = os.path.abspath(os.path.dirname(__file__))
dest = os.path.join(here, 'changelog.md')
shutil.copy(os.path.join(here, '..', 'CHANGELOG.md'), dest)

autogen_config = os.path.join(HERE, "autogen_config.py")
autogen_config = os.path.join(here, "autogen_config.py")
prev_dir = os.getcwd()
os.chdir(HERE)
os.chdir(here)
with open(autogen_config) as f:
exec(compile(f.read(), autogen_config, "exec"), {})
print('Updated cli docs')
exec(compile(f.read(), autogen_config, "exec"), {}) # noqa
os.chdir(prev_dir)
3 changes: 1 addition & 2 deletions nbclient/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import subprocess
import sys

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


Expand Down
5 changes: 2 additions & 3 deletions nbclient/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

from .client import NotebookClient

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

nbclient_flags = {
nbclient_flags: dict = {
'allow-errors': (
{
'NbClientApp': {
Expand Down Expand Up @@ -106,7 +106,6 @@ def initialize(self, argv=None):

# If there are none, throw an error
if not self.notebooks:
print(f"{self.name}: error: expected path to notebook")
sys.exit(-1)

# Loop and run them one by one
Expand Down
17 changes: 3 additions & 14 deletions nbclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,7 @@
from jupyter_client.client import KernelClient
from nbformat import NotebookNode
from nbformat.v4 import output_from_msg
from traitlets import (
Any,
Bool,
Callable,
Dict,
Enum,
Integer,
List,
Type,
Unicode,
default,
)
from traitlets import Any, Bool, Callable, Dict, Enum, Integer, List, Type, Unicode, default
from traitlets.config.configurable import LoggingConfigurable

from .exceptions import (
Expand Down Expand Up @@ -784,7 +773,7 @@ async def _async_poll_for_reply(
task_poll_kernel_alive.cancel()
raise CellTimeoutError.error_from_timeout_and_cell(
"Timeout waiting for IOPub output", self.iopub_timeout, cell
)
) from None
else:
self.log.warning("Timeout waiting for IOPub output")
task_poll_kernel_alive.cancel()
Expand Down Expand Up @@ -1003,7 +992,7 @@ async def async_execute_cell(
except asyncio.CancelledError:
# can only be cancelled by task_poll_kernel_alive when the kernel is dead
task_poll_output_msg.cancel()
raise DeadKernelError("Kernel died")
raise DeadKernelError("Kernel died") from None
except Exception as e:
# Best effort to cancel request if it hasn't been resolved
try:
Expand Down
2 changes: 1 addition & 1 deletion nbclient/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from nbformat import NotebookNode


class CellControlSignal(Exception):
class CellControlSignal(Exception): # noqa
"""
A custom exception used to indicate that the exception is used for cell
control actions (not the best model, but it's needed to cover existing
Expand Down
5 changes: 3 additions & 2 deletions nbclient/output_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _publish_msg(
data: Optional[Dict] = None,
metadata: Optional[Dict] = None,
buffers: Optional[List] = None,
**keys: Any
**keys: Any,
) -> None:
"""Helper for sending a comm message on IOPub"""
data = {} if data is None else data
Expand Down Expand Up @@ -105,7 +105,8 @@ def set_state(self, state: Dict) -> None:
def handle_msg(self, msg: Dict) -> None:
content = msg['content']
comm_id = content['comm_id']
assert comm_id == self.comm_id
if comm_id != self.comm_id:
raise AssertionError('Mismatched comm id')
data = content['data']
if 'state' in data:
self.set_state(data['state'])
Loading