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

Clean up lint handling #384

Merged
merged 1 commit into from
Nov 5, 2023
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: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Run Linters
run: |
hatch run typing:test
hatch run lint:style
hatch run lint:build
pipx run interrogate -v nbformat
pipx run doc8 --max-line-length=200

Expand Down
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ repos:
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.6.1"
hooks:
- id: mypy
files: "^nbformat"
stages: [manual]
additional_dependencies:
["jsonschema>=2.6", "traitlets>=5.13", "jupyter_core>5.4"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
hooks:
Expand Down
6 changes: 3 additions & 3 deletions nbformat/json_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import os

import fastjsonschema # type:ignore[import-untyped]
import fastjsonschema
import jsonschema
from fastjsonschema import JsonSchemaException as _JsonSchemaException
from jsonschema import Draft4Validator as _JsonSchemaValidator
Expand Down Expand Up @@ -63,7 +63,7 @@ def __init__(self, schema):
def validate(self, data):
"""Validate incoming data."""
try:
self._validator(data) # type:ignore[operator]
self._validator(data)
except _JsonSchemaException as error:
raise ValidationError(str(error), schema_path=error.path) from error

Expand All @@ -75,7 +75,7 @@ def iter_errors(self, data, schema=None):
errors = []
validate_func = self._validator
try:
validate_func(data) # type:ignore[operator]
validate_func(data)
except _JsonSchemaException as error:
errors = [ValidationError(str(error), schema_path=error.path)]

Expand Down
2 changes: 1 addition & 1 deletion nbformat/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def convert_datetime(val):
sqlite3.register_converter("datetime", convert_datetime)
except ImportError:
try:
from pysqlite2 import dbapi2 as sqlite3 # type:ignore[no-redef, import-not-found]
from pysqlite2 import dbapi2 as sqlite3 # type:ignore[no-redef]
except ImportError:
sqlite3 = None # type:ignore[assignment]

Expand Down
2 changes: 1 addition & 1 deletion nbformat/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def _truncate_obj(obj):
return obj


class NotebookValidationError(ValidationError):
class NotebookValidationError(ValidationError): # type:ignore[misc]
"""Schema ValidationError with truncated representation

to avoid massive verbose tracebacks.
Expand Down
33 changes: 10 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,33 +83,24 @@ dependencies = ["coverage", "pytest-cov"]
test = "python -m pytest -vv --cov nbformat --cov-branch --cov-report term-missing:skip-covered {args}"
nowarn = "test -W default {args}"

[tool.hatch.envs.typing]
features = ["test"]
dependencies = ["mypy~=1.6", "jupyter_core>=5.4", "traitlets>=5.11.1"]
[tool.hatch.envs.typing.scripts]
test = "mypy --install-types --non-interactive {args}"

[tool.hatch.envs.lint]
dependencies = ["mdformat>0.7", "ruff==0.1.3"]
detached = true
dependencies = ["pre-commit"]
[tool.hatch.envs.lint.scripts]
style = [
"ruff {args:.}",
"ruff format {args:.}",
"mdformat --check {args:*.md}"
]
fmt = [
"ruff --fix {args:.}",
"ruff format {args:.}",
"mdformat {args:*.md}"
]
build = "pre-commit run --all-files ruff"

[tool.hatch.envs.typing]
dependencies = [ "pre-commit"]
detached = true
[tool.hatch.envs.typing.scripts]
test = "pre-commit run --all-files --hook-stage manual mypy"

[tool.pytest.ini_options]
minversion = "6.0"
xfail_strict = true
log_cli_level = "info"
addopts = [
"-raXs", "--durations=10", "--color=yes", "--doctest-modules",
"-ra", "--durations=10", "--color=yes", "--doctest-modules",
"--showlocals", "--strict-markers", "--strict-config"
]
testpaths = [
Expand All @@ -119,8 +110,6 @@ filterwarnings = [
"error",
"ignore:Using or importing the ABCs from 'collections':DeprecationWarning:jsonschema",
"module:Jupyter is migrating its paths to use standard platformdirs:DeprecationWarning",
# ignore pytest warnings.
"ignore:::_pytest",
]

[tool.coverage.report]
Expand All @@ -146,8 +135,6 @@ enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
disable_error_code = ["no-untyped-def", "no-untyped-call"]
warn_unreachable = true



[tool.ruff]
target-version = "py38"
line-length = 100
Expand Down Expand Up @@ -214,7 +201,7 @@ fail-under=100
ignore = ["W002"]

[tool.repo-review]
ignore = ["PY007", "PP308", "GH102", "PC140"]
ignore = ["PY007", "GH102"]

[tool.codespell]
skip = "*.ipynb"
Loading