diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 232248d09..62d332128 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -83,7 +83,7 @@ jobs: - name: Run Linters run: | hatch run typing:test - hatch run lint:style + hatch run lint:build pipx run interrogate -v . pipx run doc8 --max-line-length=200 --ignore-path=docs/source/other/full-config.rst diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 12f2648fd..9a08d6e47 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.27.0 + rev: 0.27.1 hooks: - id: check-github-workflows @@ -50,6 +50,29 @@ repos: - id: codespell args: ["-L", "sur,nd"] + - repo: https://github.com/pre-commit/mirrors-mypy + rev: "v1.6.1" + hooks: + - id: mypy + files: "^nbconvert" + stages: [manual] + args: ["--install-types", "--non-interactive"] + additional_dependencies: + [ + "traitlets>=5.13", + "jupyter_core>=5.3", + "jinja2", + "nbformat", + "markupsafe", + "mistune", + "nbclient", + "defusedxml", + "ipython", + "packaging", + "pandocfilters", + "jupyterlab_pygments", + ] + - repo: https://github.com/pre-commit/pygrep-hooks rev: "v1.10.0" hooks: @@ -58,7 +81,7 @@ repos: - id: rst-inline-touching-normal - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.3 + rev: v0.1.4 hooks: - id: ruff args: ["--fix", "--show-fixes"] diff --git a/nbconvert/exporters/exporter.py b/nbconvert/exporters/exporter.py index ac126ee89..cd122d61b 100644 --- a/nbconvert/exporters/exporter.py +++ b/nbconvert/exporters/exporter.py @@ -78,13 +78,11 @@ class Exporter(LoggingConfigurable): export_from_notebook: str = None # type:ignore[assignment] # Configurability, allows the user to easily add filters and preprocessors. - preprocessors: List[str] = List( + preprocessors: List[t.Any] = List( help="""List of preprocessors, by name or namespace, to enable.""" - ).tag( # type:ignore[assignment] - config=True - ) + ).tag(config=True) - _preprocessors: List[str] = List() + _preprocessors: List[t.Any] = List() default_preprocessors: List[t.Any] = List( [ @@ -351,7 +349,7 @@ def _preprocess(self, nb, resources): # Run each preprocessor on the notebook. Carry the output along # to each preprocessor for preprocessor in self._preprocessors: - nbc, resc = preprocessor(nbc, resc) # type:ignore[operator] + nbc, resc = preprocessor(nbc, resc) if not self.optimistic_validation: self._validate_preprocessor(nbc, preprocessor) diff --git a/nbconvert/exporters/pdf.py b/nbconvert/exporters/pdf.py index e83495473..de5dd0e41 100644 --- a/nbconvert/exporters/pdf.py +++ b/nbconvert/exporters/pdf.py @@ -75,7 +75,7 @@ class PDFExporter(LatexExporter): output_mimetype = "application/pdf" - _captured_output: List[str] = List() + _captured_output = List(Unicode()) @default("file_extension") def _file_extension_default(self): diff --git a/nbconvert/exporters/templateexporter.py b/nbconvert/exporters/templateexporter.py index 9c65642ce..5bed5fdd0 100644 --- a/nbconvert/exporters/templateexporter.py +++ b/nbconvert/exporters/templateexporter.py @@ -255,8 +255,8 @@ def _raw_template_changed(self, change): self._invalidate_template_cache() template_paths = List(["."]).tag(config=True, affects_environment=True) - extra_template_basedirs: List[str] = List().tag(config=True, affects_environment=True) # type:ignore[assignment] - extra_template_paths: List[str] = List([]).tag(config=True, affects_environment=True) # type:ignore[assignment] + extra_template_basedirs = List(Unicode()).tag(config=True, affects_environment=True) + extra_template_paths = List(Unicode()).tag(config=True, affects_environment=True) @default("extra_template_basedirs") def _default_extra_template_basedirs(self): @@ -327,8 +327,8 @@ def _template_extension_default(self): environment.""" ).tag(config=True, affects_environment=True) - raw_mimetypes: List[str] = List( # type:ignore[assignment] - help="""formats of raw cells to be included in this Exporter's output.""" + raw_mimetypes = List( + Unicode(), help="""formats of raw cells to be included in this Exporter's output.""" ).tag(config=True) @default("raw_mimetypes") diff --git a/nbconvert/nbconvertapp.py b/nbconvert/nbconvertapp.py index 2766e1bf9..78a0724ea 100755 --- a/nbconvert/nbconvertapp.py +++ b/nbconvert/nbconvertapp.py @@ -336,8 +336,8 @@ def _postprocessor_class_changed(self, change): ``Exporter`` class""", ).tag(config=True) - notebooks: List[str] = List( # type:ignore[assignment] - [], + notebooks = List( + Unicode(), help="""List of notebooks to convert. Wildcards are supported. Filenames passed positionally will be added to the list. diff --git a/nbconvert/preprocessors/regexremove.py b/nbconvert/preprocessors/regexremove.py index eb5dd5128..d531dcae8 100644 --- a/nbconvert/preprocessors/regexremove.py +++ b/nbconvert/preprocessors/regexremove.py @@ -39,7 +39,7 @@ class RegexRemovePreprocessor(Preprocessor): documentation in python. """ - patterns: List[str] = List(Unicode(), default_value=[]).tag(config=True) # type:ignore[misc] + patterns = List(Unicode()).tag(config=True) def check_conditions(self, cell): """ diff --git a/nbconvert/writers/base.py b/nbconvert/writers/base.py index a751f3f93..4a6bd3275 100644 --- a/nbconvert/writers/base.py +++ b/nbconvert/writers/base.py @@ -6,7 +6,7 @@ # Distributed under the terms of the Modified BSD License. from __future__ import annotations -from traitlets import List +from traitlets import List, Unicode from nbconvert.utils.base import NbConvertBase @@ -15,8 +15,8 @@ class WriterBase(NbConvertBase): """Consumes output from nbconvert export...() methods and writes to a useful location.""" - files: List[str] = List( # type:ignore[assignment] - [], + files = List( + Unicode(), help=""" List of the files that the notebook references. Files will be included with written output.""", diff --git a/pyproject.toml b/pyproject.toml index e656fa14d..718205bf4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -111,37 +111,24 @@ dependencies = ["coverage[toml]", "pytest-cov"] test = "python -m pytest -vv --cov nbconvert --cov-branch --cov-report term-missing:skip-covered {args}" nowarn = "test -W default {args}" -[tool.hatch.envs.typing] -features = ["test"] -dependencies = ["mypy~=1.6", "traitlets>=5.13.0", "jupyter_core>=5.3.2"] -[tool.hatch.envs.typing.scripts] -test = "mypy --install-types --non-interactive {args}" - [tool.hatch.envs.lint] -dependencies = [ - "mdformat>0.7", - "mdformat-gfm>=0.3.5", - "ruff==0.1.3" -] detached = true +dependencies = ["pre-commit"] [tool.hatch.envs.lint.scripts] -style = [ - "ruff {args:.}", - "ruff format {args:.}", - "mdformat --check {args:docs *.md}" -] -fmt = [ - "ruff --fix {args:.}", - "ruff format {args:.}", - "mdformat {args:docs *.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", "--ignore=tests/files/jupyter_nbconvert_config.py", "--ignore=tests/files/override.py", @@ -255,7 +242,7 @@ fail-under=100 exclude = ["tests", "docs"] [tool.repo-review] -ignore = ["PY007", "PP308", "GH102", "PC140"] +ignore = ["PY007", "GH102"] [tool.codespell]