From 4446de7be28005fe86694eb88b451a327fcb89bb Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 4 Nov 2023 20:53:52 -0500 Subject: [PATCH] clean up lint handling --- .github/workflows/tests.yml | 2 +- .pre-commit-config.yaml | 9 +++++++++ nbformat/json_compat.py | 6 +++--- nbformat/sign.py | 2 +- nbformat/validator.py | 2 +- pyproject.toml | 33 ++++++++++----------------------- 6 files changed, 25 insertions(+), 29 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f886cf0..491bbb7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 54233bb..2e5a66b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: diff --git a/nbformat/json_compat.py b/nbformat/json_compat.py index 70c0cc4..581d0fd 100644 --- a/nbformat/json_compat.py +++ b/nbformat/json_compat.py @@ -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 @@ -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 @@ -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)] diff --git a/nbformat/sign.py b/nbformat/sign.py index c7ab5fd..fd7d4b2 100644 --- a/nbformat/sign.py +++ b/nbformat/sign.py @@ -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] diff --git a/nbformat/validator.py b/nbformat/validator.py index 861fb59..dadcb06 100644 --- a/nbformat/validator.py +++ b/nbformat/validator.py @@ -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. diff --git a/pyproject.toml b/pyproject.toml index 28e1938..8c997fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ @@ -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] @@ -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 @@ -214,7 +201,7 @@ fail-under=100 ignore = ["W002"] [tool.repo-review] -ignore = ["PY007", "PP308", "GH102", "PC140"] +ignore = ["PY007", "GH102"] [tool.codespell] skip = "*.ipynb"