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

Add more pre-commit hooks and update flake8 #218

Merged
merged 4 commits into from
Apr 12, 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
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ name: CI

on:
push:
branches: '*'
pull_request:
branches: '*'

jobs:

Expand Down
58 changes: 45 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,66 @@
ci:
autoupdate_schedule: monthly
autofix_prs: true
skip: [check-jsonschema]

repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
# - id: check-json

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
- id: end-of-file-fixer
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: requirements-txt-fixer
- id: check-added-large-files
- id: check-case-conflict
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: forbid-new-submodules
- id: check-builtin-literals
- id: trailing-whitespace

- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
hooks:
- id: pyupgrade
args: [--py36-plus]
args: [--py37-plus]

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

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

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

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies:
[
"flake8-bugbear==20.1.4",
"flake8-logging-format==0.6.0",
"flake8-implicit-str-concat==0.2.0",
]

- repo: https://github.com/sirosen/check-jsonschema
rev: 0.14.2
hooks:
- id: flake8
- id: check-jsonschema
name: "Check GitHub Workflows"
files: ^\.github/workflows/
types: [yaml]
args: ["--schemafile", "https://json.schemastore.org/github-workflow"]
4 changes: 2 additions & 2 deletions docs/requirements-doc.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Sphinx>=1.7
sphinx-book-theme
mock
moto
myst-parser
Sphinx>=1.7
sphinx-book-theme
12 changes: 6 additions & 6 deletions nbclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ async def _async_cleanup_kernel(self) -> None:
finally:
# Remove any state left over even if we failed to stop the kernel
await ensure_async(self.km.cleanup_resources())
if getattr(self, "kc") and self.kc is not None:
if getattr(self, "kc", None) and self.kc is not None:
await ensure_async(self.kc.stop_channels()) # type:ignore
self.kc = None
self.km = None
Expand Down Expand Up @@ -596,7 +596,7 @@ def on_signal():
try:
loop.add_signal_handler(signal.SIGINT, on_signal)
loop.add_signal_handler(signal.SIGTERM, on_signal)
except (NotImplementedError, RuntimeError):
except RuntimeError:
# NotImplementedError: Windows does not support signals.
# RuntimeError: Raised when add_signal_handler is called outside the main thread
pass
Expand All @@ -617,7 +617,7 @@ def on_signal():
try:
loop.remove_signal_handler(signal.SIGINT)
loop.remove_signal_handler(signal.SIGTERM)
except (NotImplementedError, RuntimeError):
except RuntimeError:
pass

async def async_execute(self, reset_kc: bool = False, **kwargs: t.Any) -> NotebookNode:
Expand Down Expand Up @@ -701,7 +701,7 @@ def _update_display_id(self, display_id: str, msg: t.Dict) -> None:
try:
out = output_from_msg(msg)
except ValueError:
self.log.error("unhandled iopub msg: " + msg['msg_type'])
self.log.error(f"unhandled iopub msg: {msg['msg_type']}")
return

for cell_idx, output_indices in self._display_id_map[display_id].items():
Expand Down Expand Up @@ -1049,7 +1049,7 @@ def output(
try:
out = output_from_msg(msg)
except ValueError:
self.log.error("unhandled iopub msg: " + msg_type)
self.log.error(f"unhandled iopub msg: {msg_type}")
return None

if self.clear_before_next_output:
Expand Down Expand Up @@ -1091,7 +1091,7 @@ def clear_output(self, outs: t.List, msg: t.Dict, cell_index: int) -> None:

def clear_display_id_mapping(self, cell_index: int) -> None:

for display_id, cell_map in self._display_id_map.items():
for _, cell_map in self._display_id_map.items():
if cell_index in cell_map:
cell_map[cell_index] = []

Expand Down
18 changes: 9 additions & 9 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
ipython<8.0.0
black
check-manifest
flake8
ipykernel
ipython<8.0.0
ipywidgets<8.0.0
mypy
pip>=18.1
pre-commit
pytest>=4.1
pytest-asyncio
pytest-cov>=2.6.1
check-manifest
flake8
mypy
xmltodict
black
pip>=18.1
setuptools>=60.0
testpath
wheel>=0.31.0
setuptools>=38.6.0
twine>=1.11.0
xmltodict
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
traitlets>=5.0.0
jupyter_client>=6.1.5
nbformat>=5.0
nest_asyncio
traitlets>=5.0.0
23 changes: 18 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@ ignore =
.circleci*
docs/changelog.md

[flake8]
ignore = E203,E731,F811,W503
max-complexity=23
max-line-length=100

[metadata]
name = nbclient
version = attr: nbclient._version.__version__
license_file = LICENSE

[flake8]
ignore = E501, W503, E402
builtins = c, get_config
exclude =
.cache,
.github,
docs,
setup.py
enable-extensions = G
extend-ignore =
G001, G002, G004, G200, G201, G202,
# black adds spaces around ':'
E203,
per-file-ignores =
# B011: Do not call assert False since python -O removes these calls
# F841 local variable 'foo' is assigned to but never used
nbclient/tests/*: B011, F841