From b94664d7452dfa3f7c2db6644cc7bdd1c3711144 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 19 Sep 2023 12:08:04 -0500 Subject: [PATCH] Adopt sp-repo-review (#2040) --- .github/ISSUE_TEMPLATE/feature_request.md | 2 +- .github/workflows/tests.yml | 10 +-- .gitignore | 2 +- .pre-commit-config.yaml | 37 +++++++- .prettierignore | 2 +- .readthedocs.yaml | 2 +- CHANGELOG.md | 10 ++- RELEASE.md | 2 +- docs/autogen_config.py | 4 +- docs/source/api/exporters.rst | 4 +- docs/source/api/filters.rst | 2 +- docs/source/architecture.rst | 2 - docs/source/customizing.rst | 8 +- docs/source/dejavu.rst | 2 +- docs/source/execute_api.rst | 4 +- docs/source/external_exporters.rst | 23 ++--- docs/source/highlighting.rst | 1 + docs/source/removing_cells.rst | 14 ++-- nbconvert/__init__.py | 53 +++++++++++- nbconvert/conftest.py | 4 +- nbconvert/exporters/__init__.py | 26 +++++- nbconvert/exporters/base.py | 2 +- nbconvert/exporters/exporter.py | 20 ++--- nbconvert/exporters/html.py | 8 +- nbconvert/exporters/pdf.py | 2 +- nbconvert/exporters/qt_screenshot.py | 16 ++-- nbconvert/exporters/qtpdf.py | 2 +- nbconvert/exporters/script.py | 2 +- nbconvert/exporters/templateexporter.py | 42 +++++----- nbconvert/exporters/webpdf.py | 2 +- nbconvert/filters/__init__.py | 79 ++++++++++++++++-- nbconvert/filters/ansi.py | 2 +- nbconvert/filters/citation.py | 6 +- nbconvert/filters/filter_links.py | 2 +- nbconvert/filters/highlight.py | 3 +- nbconvert/filters/markdown_mistune.py | 8 +- nbconvert/filters/pandoc.py | 4 +- nbconvert/filters/strings.py | 2 +- nbconvert/nbconvertapp.py | 20 +++-- nbconvert/postprocessors/__init__.py | 4 +- nbconvert/postprocessors/serve.py | 7 +- nbconvert/preprocessors/__init__.py | 19 ++++- nbconvert/preprocessors/base.py | 1 - nbconvert/preprocessors/csshtmlheader.py | 4 +- nbconvert/preprocessors/execute.py | 14 ++-- nbconvert/preprocessors/sanitize.py | 4 +- nbconvert/preprocessors/tagremove.py | 13 +-- nbconvert/utils/_contextlib_chdir.py | 2 +- nbconvert/utils/io.py | 3 +- nbconvert/utils/pandoc.py | 10 +-- nbconvert/writers/files.py | 16 ++-- pyproject.toml | 56 ++++++------- {nbconvert/tests => tests}/README.md | 0 .../exporters/tests => tests}/__init__.py | 0 {nbconvert/tests => tests}/base.py | 8 +- .../eptest-0.1.dist-info/entry_points.txt | 0 .../exporter_entrypoint/eptest.py | 0 .../tests => tests/exporters}/__init__.py | 0 .../tests => tests/exporters}/base.py | 2 +- .../tests => tests/exporters}/cheese.py | 2 +- .../exporters}/files/attachment.ipynb | 0 .../exporters}/files/lablike.html.j2 | 0 .../exporters}/files/notebook2.ipynb | 0 .../exporters}/files/notebook3.ipynb | 0 .../exporters}/files/notebook_inject.ipynb | 0 .../exporters}/files/pngmetadata.ipynb | 0 .../exporters}/files/prompt_numbers.ipynb | 0 .../exporters}/files/rawtest.ipynb | 0 .../tests => tests/exporters}/files/svg.ipynb | 0 .../exporters}/test_asciidoc.py | 5 +- .../tests => tests/exporters}/test_export.py | 20 +++-- .../exporters}/test_exporter.py | 6 +- .../tests => tests/exporters}/test_html.py | 3 +- .../tests => tests/exporters}/test_latex.py | 7 +- .../exporters}/test_markdown.py | 3 +- .../exporters}/test_notebook.py | 4 +- .../tests => tests/exporters}/test_pdf.py | 7 +- .../tests => tests/exporters}/test_python.py | 3 +- .../tests => tests/exporters}/test_qtpdf.py | 5 +- .../tests => tests/exporters}/test_qtpng.py | 7 +- .../tests => tests/exporters}/test_rst.py | 5 +- .../tests => tests/exporters}/test_script.py | 10 +-- .../tests => tests/exporters}/test_slides.py | 5 +- .../exporters}/test_templateexporter.py | 15 ++-- .../tests => tests/exporters}/test_webpdf.py | 5 +- {nbconvert/tests => tests}/fake_exporters.py | 0 .../files/Unexecuted_widget.ipynb | 0 .../files/Unexecuted_widget_2.ipynb | 0 .../tests => tests}/files/Widget_List.ipynb | 0 .../files/containerized_deployments.jpeg | Bin {nbconvert/tests => tests}/files/hello.py | 0 .../files/jupyter_nbconvert_config.py | 0 .../files/latex-linked-image.ipynb | 0 .../files/markdown_display_priority.ipynb | 0 .../tests => tests}/files/notebook1.ipynb | 0 .../tests => tests}/files/notebook2.ipynb | 0 .../files/notebook3_with_errors.ipynb | 0 .../files/notebook4_jpeg.ipynb | 0 .../files/notebook5_embed_images.ipynb | 0 .../tests => tests}/files/notebook_jl.ipynb | 0 .../tests => tests}/files/notebook_tags.ipynb | 0 {nbconvert/tests => tests}/files/override.py | 0 .../tests => tests}/files/testimage.png | Bin .../tests => tests/filters}/__init__.py | 0 .../tests => tests/filters}/test_ansi.py | 4 +- .../tests => tests/filters}/test_citation.py | 2 +- .../filters}/test_datatypefilter.py | 4 +- .../tests => tests/filters}/test_highlight.py | 4 +- .../tests => tests/filters}/test_latex.py | 4 +- .../tests => tests/filters}/test_markdown.py | 8 +- .../tests => tests/filters}/test_metadata.py | 0 .../tests => tests/filters}/test_pandoc.py | 6 +- .../tests => tests/filters}/test_strings.py | 4 +- .../postprocessors}/__init__.py | 0 .../postprocessors}/test_serve.py | 4 +- .../tests => tests/preprocessors}/__init__.py | 0 .../tests => tests/preprocessors}/base.py | 4 +- .../preprocessors}/fake_kernelmanager.py | 0 .../preprocessors}/files/HelloWorld.ipynb | 0 .../preprocessors}/files/MixedMarkdown.ipynb | 0 .../preprocessors}/test_clearmetadata.py | 5 +- .../preprocessors}/test_clearoutput.py | 3 +- .../preprocessors}/test_coalescestreams.py | 3 +- .../preprocessors}/test_csshtmlheader.py | 3 +- .../preprocessors}/test_execute.py | 2 +- .../preprocessors}/test_extractattachments.py | 3 +- .../preprocessors}/test_extractoutput.py | 3 +- .../preprocessors}/test_highlightmagics.py | 3 +- .../preprocessors}/test_latex.py | 3 +- .../preprocessors}/test_regexremove.py | 3 +- .../preprocessors}/test_sanitize.py | 3 +- .../preprocessors}/test_svg2pdf.py | 5 +- .../preprocessors}/test_tagremove.py | 4 +- .../tests => tests}/test_nbconvertapp.py | 10 +-- .../tests/utils.py => tests/testutils.py | 0 .../utils/tests => tests/utils}/__init__.py | 0 .../utils/tests => tests/utils}/test_io.py | 2 +- .../tests => tests/utils}/test_pandoc.py | 9 +- .../tests => tests/utils}/test_version.py | 4 +- .../tests => tests/writers}/__init__.py | 0 .../tests => tests/writers}/test_debug.py | 4 +- .../tests => tests/writers}/test_files.py | 8 +- .../tests => tests/writers}/test_stdout.py | 4 +- 143 files changed, 534 insertions(+), 305 deletions(-) rename {nbconvert/tests => tests}/README.md (100%) rename {nbconvert/exporters/tests => tests}/__init__.py (100%) rename {nbconvert/tests => tests}/base.py (97%) rename {nbconvert/tests => tests}/exporter_entrypoint/eptest-0.1.dist-info/entry_points.txt (100%) rename {nbconvert/tests => tests}/exporter_entrypoint/eptest.py (100%) rename {nbconvert/filters/tests => tests/exporters}/__init__.py (100%) rename {nbconvert/exporters/tests => tests/exporters}/base.py (97%) rename {nbconvert/exporters/tests => tests/exporters}/cheese.py (96%) rename {nbconvert/exporters/tests => tests/exporters}/files/attachment.ipynb (100%) rename {nbconvert/exporters/tests => tests/exporters}/files/lablike.html.j2 (100%) rename {nbconvert/exporters/tests => tests/exporters}/files/notebook2.ipynb (100%) rename {nbconvert/exporters/tests => tests/exporters}/files/notebook3.ipynb (100%) rename {nbconvert/exporters/tests => tests/exporters}/files/notebook_inject.ipynb (100%) rename {nbconvert/exporters/tests => tests/exporters}/files/pngmetadata.ipynb (100%) rename {nbconvert/exporters/tests => tests/exporters}/files/prompt_numbers.ipynb (100%) rename {nbconvert/exporters/tests => tests/exporters}/files/rawtest.ipynb (100%) rename {nbconvert/exporters/tests => tests/exporters}/files/svg.ipynb (100%) rename {nbconvert/exporters/tests => tests/exporters}/test_asciidoc.py (95%) rename {nbconvert/exporters/tests => tests/exporters}/test_export.py (87%) rename {nbconvert/exporters/tests => tests/exporters}/test_exporter.py (96%) rename {nbconvert/exporters/tests => tests/exporters}/test_html.py (99%) rename {nbconvert/exporters/tests => tests/exporters}/test_latex.py (97%) rename {nbconvert/exporters/tests => tests/exporters}/test_markdown.py (95%) rename {nbconvert/exporters/tests => tests/exporters}/test_notebook.py (92%) rename {nbconvert/exporters/tests => tests/exporters}/test_pdf.py (94%) rename {nbconvert/exporters/tests => tests/exporters}/test_python.py (93%) rename {nbconvert/exporters/tests => tests/exporters}/test_qtpdf.py (84%) rename {nbconvert/exporters/tests => tests/exporters}/test_qtpng.py (83%) rename {nbconvert/exporters/tests => tests/exporters}/test_rst.py (95%) rename {nbconvert/exporters/tests => tests/exporters}/test_script.py (89%) rename {nbconvert/exporters/tests => tests/exporters}/test_slides.py (96%) rename {nbconvert/exporters/tests => tests/exporters}/test_templateexporter.py (98%) rename {nbconvert/exporters/tests => tests/exporters}/test_webpdf.py (94%) rename {nbconvert/tests => tests}/fake_exporters.py (100%) rename {nbconvert/tests => tests}/files/Unexecuted_widget.ipynb (100%) rename {nbconvert/tests => tests}/files/Unexecuted_widget_2.ipynb (100%) rename {nbconvert/tests => tests}/files/Widget_List.ipynb (100%) rename {nbconvert/tests => tests}/files/containerized_deployments.jpeg (100%) rename {nbconvert/tests => tests}/files/hello.py (100%) rename {nbconvert/tests => tests}/files/jupyter_nbconvert_config.py (100%) rename {nbconvert/tests => tests}/files/latex-linked-image.ipynb (100%) rename {nbconvert/tests => tests}/files/markdown_display_priority.ipynb (100%) rename {nbconvert/tests => tests}/files/notebook1.ipynb (100%) rename {nbconvert/tests => tests}/files/notebook2.ipynb (100%) rename {nbconvert/tests => tests}/files/notebook3_with_errors.ipynb (100%) rename {nbconvert/tests => tests}/files/notebook4_jpeg.ipynb (100%) rename {nbconvert/tests => tests}/files/notebook5_embed_images.ipynb (100%) rename {nbconvert/tests => tests}/files/notebook_jl.ipynb (100%) rename {nbconvert/tests => tests}/files/notebook_tags.ipynb (100%) rename {nbconvert/tests => tests}/files/override.py (100%) rename {nbconvert/tests => tests}/files/testimage.png (100%) rename {nbconvert/postprocessors/tests => tests/filters}/__init__.py (100%) rename {nbconvert/filters/tests => tests/filters}/test_ansi.py (97%) rename {nbconvert/filters/tests => tests/filters}/test_citation.py (98%) rename {nbconvert/filters/tests => tests/filters}/test_datatypefilter.py (93%) rename {nbconvert/filters/tests => tests/filters}/test_highlight.py (96%) rename {nbconvert/filters/tests => tests/filters}/test_latex.py (95%) rename {nbconvert/filters/tests => tests/filters}/test_markdown.py (97%) rename {nbconvert/filters/tests => tests/filters}/test_metadata.py (100%) rename {nbconvert/filters/tests => tests/filters}/test_pandoc.py (92%) rename {nbconvert/filters/tests => tests/filters}/test_strings.py (99%) rename {nbconvert/preprocessors/tests => tests/postprocessors}/__init__.py (100%) rename {nbconvert/postprocessors/tests => tests/postprocessors}/test_serve.py (84%) rename {nbconvert/tests => tests/preprocessors}/__init__.py (100%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/base.py (96%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/fake_kernelmanager.py (100%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/files/HelloWorld.ipynb (100%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/files/MixedMarkdown.ipynb (100%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/test_clearmetadata.py (97%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/test_clearoutput.py (96%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/test_coalescestreams.py (97%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/test_csshtmlheader.py (95%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/test_execute.py (98%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/test_extractattachments.py (97%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/test_extractoutput.py (97%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/test_highlightmagics.py (95%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/test_latex.py (96%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/test_regexremove.py (97%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/test_sanitize.py (99%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/test_svg2pdf.py (96%) rename {nbconvert/preprocessors/tests => tests/preprocessors}/test_tagremove.py (95%) rename {nbconvert/tests => tests}/test_nbconvertapp.py (98%) rename nbconvert/tests/utils.py => tests/testutils.py (100%) rename {nbconvert/utils/tests => tests/utils}/__init__.py (100%) rename {nbconvert/utils/tests => tests/utils}/test_io.py (95%) rename {nbconvert/utils/tests => tests/utils}/test_pandoc.py (94%) rename {nbconvert/utils/tests => tests/utils}/test_version.py (78%) rename {nbconvert/writers/tests => tests/writers}/__init__.py (100%) rename {nbconvert/writers/tests => tests/writers}/test_debug.py (94%) rename {nbconvert/writers/tests => tests/writers}/test_files.py (98%) rename {nbconvert/writers/tests => tests/writers}/test_stdout.py (93%) diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index d67a63abc..34fb53921 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -6,4 +6,4 @@ ______________________________________________________________________ - + diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 82358c35e..232248d09 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -29,6 +29,7 @@ jobs: python-version: "3.9" - os: "ubuntu-20.04" python-version: "3.10" + - os: "ubuntu-20.04" fail-fast: false steps: - uses: actions/checkout@v4 @@ -79,8 +80,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - - name: Run Linters - run: | + - name: Run Linters + run: | hatch run typing:test hatch run lint:style pipx run interrogate -v . @@ -106,7 +107,7 @@ jobs: - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - uses: jupyterlab/maintainer-tools/.github/actions/check-links@v1 with: - ignore_links: 'https://ipywidgets.readthedocs.io/en/latest/examples/Output' + ignore_links: "https://ipywidgets.readthedocs.io/en/latest/examples/Output" test_minimum_versions: name: Test Minimum Versions @@ -118,7 +119,6 @@ jobs: uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 with: dependency_type: minimum - only_create_file: 1 - name: Install dependencies run: | sudo apt-get update @@ -140,7 +140,7 @@ jobs: - uses: actions/checkout@v4 - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 with: - dependency_type: pre + dependency_type: pre - name: Run the tests run: | export NBFORMAT_VALIDATOR=jsonschema diff --git a/.gitignore b/.gitignore index 2a5b02edb..30157c5b5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ docs/source/interactive/magics-generated.txt docs/gh-pages docs/source/CHANGELOG.md nbconvert/resources/style.min.css -nbconvert/tests/files/*.html +tests/files/*.html *.py[co] __pycache__ *.egg-info diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fa8418ec4..fa47c7e22 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,6 @@ ci: autoupdate_schedule: monthly + autoupdate_commit_msg: "chore: update pre-commit hooks" repos: - repo: https://github.com/pre-commit/pre-commit-hooks @@ -15,6 +16,7 @@ repos: - id: check-json - id: check-toml - id: check-yaml + - id: debug-statements - id: end-of-file-fixer - id: trailing-whitespace @@ -30,13 +32,44 @@ repos: additional_dependencies: [mdformat-gfm, mdformat-frontmatter, mdformat-footnote] - - repo: https://github.com/psf/black + - repo: https://github.com/pre-commit/mirrors-prettier + rev: "v3.0.2" + hooks: + - id: prettier + types_or: [yaml, html, json] + + - repo: https://github.com/adamchainz/blacken-docs + rev: "1.16.0" + hooks: + - id: blacken-docs + additional_dependencies: [black==23.7.0] + + - repo: https://github.com/psf/black-pre-commit-mirror rev: 23.7.0 hooks: - id: black + - repo: https://github.com/codespell-project/codespell + rev: "v2.2.5" + hooks: + - id: codespell + args: ["-L", "sur,nd"] + + - repo: https://github.com/pre-commit/pygrep-hooks + rev: "v1.10.0" + hooks: + - id: rst-backticks + - id: rst-directive-colons + - id: rst-inline-touching-normal + - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.0.287 hooks: - id: ruff - args: ["--fix"] + args: ["--fix", "--show-fixes"] + + - repo: https://github.com/scientific-python/cookie + rev: "2023.08.23" + hooks: + - id: sp-repo-review + additional_dependencies: ["repo-review[cli]"] diff --git a/.prettierignore b/.prettierignore index 3bcf38294..36adcc2c9 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1 +1 @@ -nbconvert/tests/files/*.html +tests/files/*.html diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 7e5512c55..dea153277 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -20,4 +20,4 @@ python: build: os: ubuntu-22.04 tools: - python: "3.11" + python: "3.11" diff --git a/CHANGELOG.md b/CHANGELOG.md index ce265ba7b..b7f791f3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -438,7 +438,7 @@ [#1761](https://github.com/jupyter/nbconvert/pull/1761) - WebPDFExporter: Emulate media print by @martinRenou in [#1791](https://github.com/jupyter/nbconvert/pull/1791) -- Fix fonts overriden by user stylesheet by inheriting styles by +- Fix fonts overridden by user stylesheet by inheriting styles by @dakoop in [#1793](https://github.com/jupyter/nbconvert/pull/1793) - Fix lab template output alignment by @dakoop in [#1795](https://github.com/jupyter/nbconvert/pull/1795) @@ -628,7 +628,7 @@ The following 31 authors contributed 81 commits. ## 6.0.7 -Primarly a release addressing template extensions issues reported since +Primarily a release addressing template extensions issues reported since 6.0 launched. ### Comprehensive notes @@ -1182,7 +1182,7 @@ Thanks to the following 11 authors who contributed 57 commits. #### Fixing Problems - Mathjax.tpl fix for rendering Latex in html [#932](https://github.com/jupyter/nbconvert/pull/932) -- Backwards compatbility for empty kernel names +- Backwards compatibility for empty kernel names [#927](https://github.com/jupyter/nbconvert/pull/927) [#924](https://github.com/jupyter/nbconvert/pull/924) #### Testing, Docs, and Builds @@ -1282,6 +1282,8 @@ class AttrExporter(TemplateExporter): raw template {%- endblock in_prompt -%} """ + + exporter_attr = AttrExporter() output_attr, _ = exporter_attr.from_notebook_node(nb) assert "raw template" in output_attr @@ -1623,7 +1625,7 @@ Many thanks to the following individuals who contributed to this release - doc improvements [#489](https://github.com/jupyter/nbconvert/pull/489) [#500](https://github.com/jupyter/nbconvert/pull/500) [#493](https://github.com/jupyter/nbconvert/pull/493) [#506](https://github.com/jupyter/nbconvert/pull/506) - newly customizable: output prompt [#500](https://github.com/jupyter/nbconvert/pull/500) -- more python2/3 compatibile unicode handling [#502](https://github.com/jupyter/nbconvert/pull/502) +- more python2/3 compatible unicode handling [#502](https://github.com/jupyter/nbconvert/pull/502) ## 5.0 diff --git a/RELEASE.md b/RELEASE.md index 16328a9be..b21e34a12 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -6,7 +6,7 @@ The recommended way to make a release is to use [`jupyter_releaser`](https://git - Run the ["Step 1: Prep Release"](https://github.com/jupyter/nbconvert/actions/workflows/prep-release.yml) workflow with the appropriate inputs. - You can usually use the following values for the workflow: - - branch : 'main' when releasing fro teh main branch + - branch : 'main' when releasing from the main branch - "Post Version Specifier" empty unless you do a beta or rc release - keep `since_last_stable` unchecked - "Use PRs with activity since this date or git reference" diff --git a/docs/autogen_config.py b/docs/autogen_config.py index d8d2bfcbf..506211452 100644 --- a/docs/autogen_config.py +++ b/docs/autogen_config.py @@ -27,7 +27,7 @@ .. code-block:: python - c.TemplateExporter.exclude_input_prompt = False # The default + c.TemplateExporter.exclude_input_prompt = False # The default c.PDFExporter.exclude_input_prompt = True input prompts will not appear when converting to PDF, but they will appear when @@ -41,7 +41,7 @@ to be loaded regardless of the value of their ``enabled`` attribute. When using Nbconvert from the command line, a number of aliases and flags are -defined as shortcuts to configuration options for convience. +defined as shortcuts to configuration options for convenience. """ diff --git a/docs/source/api/exporters.rst b/docs/source/api/exporters.rst index 585d8c7c1..af922b6e0 100644 --- a/docs/source/api/exporters.rst +++ b/docs/source/api/exporters.rst @@ -46,10 +46,10 @@ Exporter base classes Specialized exporter classes ---------------------------- -The `NotebookExporter` inherits directly from +The ``NotebookExporter`` inherits directly from ``Exporter``, while the other exporters listed here inherit either directly or indirectly from -`TemplateExporter`. +``TemplateExporter``. .. autoclass:: NotebookExporter diff --git a/docs/source/api/filters.rst b/docs/source/api/filters.rst index c9d128121..7d244f11d 100644 --- a/docs/source/api/filters.rst +++ b/docs/source/api/filters.rst @@ -6,7 +6,7 @@ Filters Filters are for use with the ``nbconvert.exporters.templateexporter.TemplateExporter`` exporter. They provide a way for you transform notebook contents to a particular format depending on the template you are using. For example, when converting to HTML, you would want to -use the `ansi2html()` function to convert ANSI colors (from +use the ``ansi2html()`` function to convert ANSI colors (from e.g. a terminal traceback) to HTML colors. .. seealso:: diff --git a/docs/source/architecture.rst b/docs/source/architecture.rst index 90b6909d5..d72671abf 100644 --- a/docs/source/architecture.rst +++ b/docs/source/architecture.rst @@ -185,8 +185,6 @@ A *Postprocessor* is something that runs after everything is exported and writte The only postprocessor in nbconvert at this point is the ``nbconvert.postprocessors.serve.ServePostProcessor``, which is used for serving `reveal.js`_ HTML slideshows. -.. links: - .. _jinja: https://jinja.palletsprojects.com/en/3.0.x/ .. _More on Jinja Filters: https://jinja.palletsprojects.com/en/3.0.x/templates/#filters .. _reveal.js: http://lab.hakim.se/reveal-js diff --git a/docs/source/customizing.rst b/docs/source/customizing.rst index e7caca039..6a4081ad9 100644 --- a/docs/source/customizing.rst +++ b/docs/source/customizing.rst @@ -102,12 +102,12 @@ template, exports text/html, and enables two preprocessors called "100-pygments" Inheritance ~~~~~~~~~~~ -Nbconvert walks up the inheritance structure determined by ``conf.json`` and produces an agregated +Nbconvert walks up the inheritance structure determined by ``conf.json`` and produces an aggregated configuration, merging the dictionaries of registered preprocessors. The lexical ordering of the preprocessors by name determines the order in which they will be run. Besides the ``conf.json`` file, nbconvert templates most typically include jinja templates files, -although any other resource from the base template can be overriden in the derived template. +although any other resource from the base template can be overridden in the derived template. For example, inspecting the content of the ``classic`` template located in ``share/jupyter/nbconvert/templates/classic``, we find the following content: @@ -133,13 +133,13 @@ for HTML exporters) as well as CSS and a base template file in ``base.html.j2``. Inheritance in Jinja ~~~~~~~~~~~~~~~~~~~~ -In nbconvert, jinja templates can inherrit from any other jinja template available in its current directory +In nbconvert, jinja templates can inherit from any other jinja template available in its current directory or base template directory by name. Jinja templates of other directories can be addressed by their relative path from the Jupyter data directory. For example, in the reveal template, ``index.html.j2`` extends ``base.html.j2`` which is in the same directory, and ``base.html.j2`` extends ``lab/base.html.j2``. This approach allows using content that is available in other templates -or may be overriden in the current template. +or may be overridden in the current template. A practical example ~~~~~~~~~~~~~~~~~~~ diff --git a/docs/source/dejavu.rst b/docs/source/dejavu.rst index b409be3a5..73107db2b 100644 --- a/docs/source/dejavu.rst +++ b/docs/source/dejavu.rst @@ -12,7 +12,7 @@ Dejavu works exactly the same as nbconvert and you can use all command line opti jupyter dejavu notebook.ipynb -In case you want to show code in adition to its output use the flag ``--show-input``. +In case you want to show code in addition to its output use the flag ``--show-input``. Configuring the Notebook for slides presentations diff --git a/docs/source/execute_api.rst b/docs/source/execute_api.rst index f3617add5..63a8fe9c0 100644 --- a/docs/source/execute_api.rst +++ b/docs/source/execute_api.rst @@ -35,7 +35,7 @@ Example Let's start with a complete quick example, leaving detailed explanations to the following sections. -**Import**: First we import nbconvert and the `ExecutePreprocessor` +**Import**: First we import nbconvert and the ``ExecutePreprocessor`` class:: import nbformat @@ -78,7 +78,7 @@ in the file ``executed_notebook.ipynb``. Execution arguments (traitlets) ------------------------------- -The arguments passed to `ExecutePreprocessor` are configuration options +The arguments passed to ``ExecutePreprocessor`` are configuration options called `traitlets `_. There are many cool things about traitlets. For example, they enforce the input type, and they can be accessed/modified as diff --git a/docs/source/external_exporters.rst b/docs/source/external_exporters.rst index cd18a6ca0..49328564a 100644 --- a/docs/source/external_exporters.rst +++ b/docs/source/external_exporters.rst @@ -44,11 +44,11 @@ example, your package may contain two custom exporters, named "simple" and .. sourcecode:: python setup( - ... - entry_points = { - 'nbconvert.exporters': [ - 'simple = mymodule:SimpleExporter', - 'detail = mymodule:DetailExporter', + # ... + entry_points={ + "nbconvert.exporters": [ + "simple = mymodule:SimpleExporter", + "detail = mymodule:DetailExporter", ], } ) @@ -167,9 +167,10 @@ We are going to write an exporter that: from traitlets.config import Config from nbconvert.exporters.html import HTMLExporter - #----------------------------------------------------------------------------- + # ----------------------------------------------------------------------------- # Classes - #----------------------------------------------------------------------------- + # ----------------------------------------------------------------------------- + class MyExporter(HTMLExporter): """ @@ -185,7 +186,7 @@ We are going to write an exporter that: """ The new file extension is ``.test_ext`` """ - return '.test_ext' + return ".test_ext" @property def template_paths(self): @@ -195,13 +196,15 @@ We are going to write an exporter that: Note: nbconvert 6.0 changed ``template_path`` to ``template_paths`` """ - return super().template_paths+[os.path.join(os.path.dirname(__file__), "templates")] + return super().template_paths + [ + os.path.join(os.path.dirname(__file__), "templates") + ] def _template_file_default(self): """ We want to use the new template we ship with our library. """ - return 'test_template' # full + return "test_template" # full And the template file, that inherits from the html ``full`` template and prepend/append text to each markdown cell (see Jinja2 docs for template syntax):: diff --git a/docs/source/highlighting.rst b/docs/source/highlighting.rst index 704a58858..d9b60fc0c 100644 --- a/docs/source/highlighting.rst +++ b/docs/source/highlighting.rst @@ -33,6 +33,7 @@ from a terminal or .. code-block:: python from pygments.styles import get_all_styles + print(list(get_all_styles())) from python. diff --git a/docs/source/removing_cells.rst b/docs/source/removing_cells.rst index 56eda8775..ba3ffa8db 100644 --- a/docs/source/removing_cells.rst +++ b/docs/source/removing_cells.rst @@ -15,7 +15,7 @@ Removing pieces of cells using cell tags The most straightforward way to control which pieces of cells are removed is to use **cell tags**. These are single-string snippets of metadata that are stored in each cells "tag" field. The -`TagRemovePreprocessor` can be used +``TagRemovePreprocessor`` can be used to remove inputs, outputs, or entire cells. For example, here is a configuration that uses a different tag for @@ -36,22 +36,22 @@ we demonstrate using the nbconvert Python API. # words remove_cell to remove cells. You can also modify the code to use # a different tag word c.TagRemovePreprocessor.remove_cell_tags = ("remove_cell",) - c.TagRemovePreprocessor.remove_all_outputs_tags = ('remove_output',) - c.TagRemovePreprocessor.remove_input_tags = ('remove_input',) + c.TagRemovePreprocessor.remove_all_outputs_tags = ("remove_output",) + c.TagRemovePreprocessor.remove_input_tags = ("remove_input",) c.TagRemovePreprocessor.enabled = True # Configure and run out exporter c.HTMLExporter.preprocessors = ["nbconvert.preprocessors.TagRemovePreprocessor"] exporter = HTMLExporter(config=c) - exporter.register_preprocessor(TagRemovePreprocessor(config=c),True) + exporter.register_preprocessor(TagRemovePreprocessor(config=c), True) # Configure and run our exporter - returns a tuple - first element with html, # second with notebook metadata output = HTMLExporter(config=c).from_filename("your-notebook-file-path.ipynb") # Write to output html file - with open("your-output-file-name.html", "w") as f: + with open("your-output-file-name.html", "w") as f: f.write(output[0]) This additional example demonstrates using the CLI to remove cells with a certain cell tag @@ -64,9 +64,9 @@ Removing cells using Regular Expressions on cell content -------------------------------------------------------- Sometimes you'd rather remove cells based on their _content_ rather -than their tags. In this case, you can use the `RegexRemovePreprocessor`. +than their tags. In this case, you can use the ``RegexRemovePreprocessor``. -You initalize this preprocessor with a single ``patterns`` configuration, which +You initialize this preprocessor with a single ``patterns`` configuration, which is a list of strings. For each cell, this preprocessor checks whether the cell contents match any of the strings provided in ``patterns``. If the contents match any of the patterns, the cell is removed from the notebook. diff --git a/nbconvert/__init__.py b/nbconvert/__init__.py index 6ba38686b..bd860d30b 100644 --- a/nbconvert/__init__.py +++ b/nbconvert/__init__.py @@ -4,7 +4,58 @@ try: from . import filters, postprocessors, preprocessors, writers - from .exporters import * + from .exporters import ( + ASCIIDocExporter, + Exporter, + ExporterNameError, + FilenameExtension, + HTMLExporter, + LatexExporter, + MarkdownExporter, + NotebookExporter, + PDFExporter, + PythonExporter, + QtPDFExporter, + QtPNGExporter, + RSTExporter, + ScriptExporter, + SlidesExporter, + TemplateExporter, + WebPDFExporter, + export, + get_export_names, + get_exporter, + ) except ModuleNotFoundError: # We hit this condition when the package is not yet fully installed. pass + + +__all__ = [ + "__version__", + "version_info", + "filters", + "postprocessors", + "preprocessors", + "writers", + "ASCIIDocExporter", + "ExporterNameError", + "export", + "get_export_names", + "get_exporter", + "Exporter", + "FilenameExtension", + "HTMLExporter", + "LatexExporter", + "MarkdownExporter", + "NotebookExporter", + "PDFExporter", + "PythonExporter", + "QtPDFExporter", + "QtPNGExporter", + "RSTExporter", + "ScriptExporter", + "SlidesExporter", + "TemplateExporter", + "WebPDFExporter", +] diff --git a/nbconvert/conftest.py b/nbconvert/conftest.py index 0d6ac5fb0..23711e844 100644 --- a/nbconvert/conftest.py +++ b/nbconvert/conftest.py @@ -3,4 +3,6 @@ import os if os.name == "nt": - asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type:ignore + asyncio.set_event_loop_policy( + asyncio.WindowsSelectorEventLoopPolicy() # type:ignore[attr-defined] + ) diff --git a/nbconvert/exporters/__init__.py b/nbconvert/exporters/__init__.py index 9aa58d346..7a29d1300 100644 --- a/nbconvert/exporters/__init__.py +++ b/nbconvert/exporters/__init__.py @@ -1,5 +1,5 @@ from .asciidoc import ASCIIDocExporter -from .base import ExporterNameError, export, get_export_names, get_exporter +from .base import ExporterDisabledError, ExporterNameError, export, get_export_names, get_exporter from .exporter import Exporter, FilenameExtension from .html import HTMLExporter from .latex import LatexExporter @@ -14,3 +14,27 @@ from .slides import SlidesExporter from .templateexporter import TemplateExporter from .webpdf import WebPDFExporter + +__all__ = [ + "ASCIIDocExporter", + "ExporterNameError", + "ExporterDisabledError", + "export", + "get_export_names", + "get_exporter", + "Exporter", + "FilenameExtension", + "HTMLExporter", + "LatexExporter", + "MarkdownExporter", + "NotebookExporter", + "PDFExporter", + "PythonExporter", + "QtPDFExporter", + "QtPNGExporter", + "RSTExporter", + "ScriptExporter", + "SlidesExporter", + "TemplateExporter", + "WebPDFExporter", +] diff --git a/nbconvert/exporters/base.py b/nbconvert/exporters/base.py index a0a08cd50..62fc444be 100644 --- a/nbconvert/exporters/base.py +++ b/nbconvert/exporters/base.py @@ -7,7 +7,7 @@ import sys if sys.version_info < (3, 10): - from importlib_metadata import entry_points + from importlib_metadata import entry_points # type:ignore[import] else: from importlib.metadata import entry_points from nbformat import NotebookNode diff --git a/nbconvert/exporters/exporter.py b/nbconvert/exporters/exporter.py index ce299e0a6..5b7793176 100644 --- a/nbconvert/exporters/exporter.py +++ b/nbconvert/exporters/exporter.py @@ -4,7 +4,7 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. - +from __future__ import annotations import collections import copy @@ -21,7 +21,7 @@ from traitlets.utils.importstring import import_item -class ResourcesDict(collections.defaultdict): +class ResourcesDict(collections.defaultdict): # type:ignore[type-arg] """A default dict for resources.""" def __missing__(self, key): @@ -29,7 +29,7 @@ def __missing__(self, key): return "" -class FilenameExtension(Unicode): +class FilenameExtension(Unicode): # type:ignore[type-arg] """A trait for filename extensions.""" default_value = "" @@ -75,7 +75,7 @@ class Exporter(LoggingConfigurable): # Should this converter be accessible from the notebook front-end? # If so, should be a friendly name to display (and possibly translated). - export_from_notebook: str = None # type:ignore + export_from_notebook: str = None # type:ignore[assignment] # Configurability, allows the user to easily add filters and preprocessors. preprocessors = List(help="""List of preprocessors, by name or namespace, to enable.""").tag( @@ -128,8 +128,8 @@ def default_config(self): return Config() def from_notebook_node( - self, nb: NotebookNode, resources: t.Optional[t.Any] = None, **kw: t.Any - ) -> t.Tuple[NotebookNode, t.Dict]: + self, nb: NotebookNode, resources: t.Any | None = None, **kw: t.Any + ) -> tuple[NotebookNode, dict[str, t.Any]]: """ Convert a notebook from a notebook node instance. @@ -161,8 +161,8 @@ def from_notebook_node( return nb_copy, resources def from_filename( - self, filename: str, resources: t.Optional[dict] = None, **kw: t.Any - ) -> t.Tuple[NotebookNode, t.Dict]: + self, filename: str, resources: dict[str, t.Any] | None = None, **kw: t.Any + ) -> tuple[NotebookNode, dict[str, t.Any]]: """ Convert a notebook from a notebook file. @@ -201,8 +201,8 @@ def from_filename( return self.from_file(f, resources=resources, **kw) def from_file( - self, file_stream: t.Any, resources: t.Optional[dict] = None, **kw: t.Any - ) -> t.Tuple[NotebookNode, dict]: + self, file_stream: t.Any, resources: dict[str, t.Any] | None = None, **kw: t.Any + ) -> tuple[NotebookNode, dict[str, t.Any]]: """ Convert a notebook from a notebook file. diff --git a/nbconvert/exporters/html.py b/nbconvert/exporters/html.py index c5d5c985a..5f3ff8a00 100644 --- a/nbconvert/exporters/html.py +++ b/nbconvert/exporters/html.py @@ -18,7 +18,7 @@ from traitlets.config import Config if tuple(int(x) for x in jinja2.__version__.split(".")[:3]) < (3, 0, 0): - from jinja2 import contextfilter # type:ignore + from jinja2 import contextfilter # type:ignore[attr-defined] else: from jinja2 import pass_context as contextfilter @@ -241,9 +241,9 @@ def default_filters(self): yield from super().default_filters() yield ("markdown2html", self.markdown2html) - def from_notebook_node( # type:ignore - self, nb: NotebookNode, resources: Optional[Dict] = None, **kw: Any - ) -> Tuple[str, Dict]: + def from_notebook_node( # type:ignore[explicit-override, override] + self, nb: NotebookNode, resources: Optional[Dict[str, Any]] = None, **kw: Any + ) -> Tuple[str, Dict[str, Any]]: """Convert from notebook node.""" langinfo = nb.metadata.get("language_info", {}) lexer = langinfo.get("pygments_lexer", langinfo.get("name", None)) diff --git a/nbconvert/exporters/pdf.py b/nbconvert/exporters/pdf.py index dcc05fc7d..7e15a9b47 100644 --- a/nbconvert/exporters/pdf.py +++ b/nbconvert/exporters/pdf.py @@ -126,7 +126,7 @@ def run_command( # noqa shell = sys.platform == "win32" if shell: - command = subprocess.list2cmdline(command) # type:ignore + command = subprocess.list2cmdline(command) # type:ignore[assignment] env = os.environ.copy() prepend_to_env_search_path("TEXINPUTS", self.texinputs, env) prepend_to_env_search_path("BIBINPUTS", self.texinputs, env) diff --git a/nbconvert/exporters/qt_screenshot.py b/nbconvert/exporters/qt_screenshot.py index cc07837dc..739d97994 100644 --- a/nbconvert/exporters/qt_screenshot.py +++ b/nbconvert/exporters/qt_screenshot.py @@ -2,10 +2,10 @@ import os try: - from PyQt5 import QtCore # type:ignore - from PyQt5.QtGui import QPageLayout, QPageSize # type:ignore - from PyQt5.QtWebEngineWidgets import QWebEngineSettings, QWebEngineView # type:ignore - from PyQt5.QtWidgets import QApplication # type:ignore + from PyQt5 import QtCore # type:ignore[import] + from PyQt5.QtGui import QPageLayout, QPageSize # type:ignore[import] + from PyQt5.QtWebEngineWidgets import QWebEngineSettings, QWebEngineView # type:ignore[import] + from PyQt5.QtWidgets import QApplication # type:ignore[import] QT_INSTALLED = True except ModuleNotFoundError: @@ -17,7 +17,7 @@ if not QApplication.instance(): APP = QApplication([]) - class QtScreenshot(QWebEngineView): + class QtScreenshot(QWebEngineView): # type:ignore[misc] """A qt screenshot exporter.""" def __init__(self): @@ -40,7 +40,7 @@ def capture(self, url, output_file, paginate): def cleanup(*args): """Cleanup the app.""" - self.app.quit() # type:ignore + self.app.quit() # type:ignore[union-attr] self.get_data() self.page().pdfPrintingFinished.connect(cleanup) @@ -50,7 +50,7 @@ def cleanup(*args): msg = f"Export file extension not supported: {output_file}" raise RuntimeError(msg) self.show() - self.app.exec() # type:ignore + self.app.exec() # type:ignore[union-attr] def on_loaded(self): """Handle app load.""" @@ -77,7 +77,7 @@ def export_pdf(self): def export_png(self): """Export to png.""" self.grab().save(self.output_file, "PNG") - self.app.quit() # type:ignore + self.app.quit() # type:ignore[union-attr] self.get_data() def get_data(self): diff --git a/nbconvert/exporters/qtpdf.py b/nbconvert/exporters/qtpdf.py index dd2652020..6cf0a21fc 100644 --- a/nbconvert/exporters/qtpdf.py +++ b/nbconvert/exporters/qtpdf.py @@ -18,7 +18,7 @@ class QtPDFExporter(QtExporter): export_from_notebook = "PDF via HTML" format = "pdf" # noqa - paginate = Bool( + paginate = Bool( # type:ignore[assignment] True, help=""" Split generated notebook into multiple pages. diff --git a/nbconvert/exporters/script.py b/nbconvert/exporters/script.py index d4552fcdd..c10d7a204 100644 --- a/nbconvert/exporters/script.py +++ b/nbconvert/exporters/script.py @@ -5,7 +5,7 @@ import sys if sys.version_info < (3, 10): - from importlib_metadata import entry_points + from importlib_metadata import entry_points # type:ignore[import] else: from importlib.metadata import entry_points from traitlets import Dict, default diff --git a/nbconvert/exporters/templateexporter.py b/nbconvert/exporters/templateexporter.py index 982b21e7b..ab69bfe61 100644 --- a/nbconvert/exporters/templateexporter.py +++ b/nbconvert/exporters/templateexporter.py @@ -4,7 +4,7 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. - +from __future__ import annotations import html import json @@ -227,7 +227,7 @@ def _template_name_validate(self, change): def _template_file_changed(self, change): new = change["new"] if new == "default": - self.template_file = self.default_template # type:ignore + self.template_file = self.default_template # type:ignore[attr-defined] return # check if template_file is a file path # rather than a name already on template_path @@ -236,7 +236,7 @@ def _template_file_changed(self, change): directory, self.template_file = os.path.split(full_path) self.extra_template_paths = [directory, *self.extra_template_paths] # While not strictly an invalid template file name, the extension hints that there isn't a template directory involved - if self.template_file.endswith(".tpl"): + if self.template_file and self.template_file.endswith(".tpl"): warnings.warn( f"5.x style template file passed '{new}'. Use --template-name for the template directory with a index..j2 file and/or --template-file to denote a different template.", DeprecationWarning, @@ -365,7 +365,7 @@ def _load_template(self): # this gives precedence to a raw_template if present with self.hold_trait_notifications(): - if self.template_file != self._raw_template_key: + if self.template_file and (self.template_file != self._raw_template_key): self._last_template_file = self.template_file if self.raw_template: self.template_file = self._raw_template_key @@ -382,21 +382,21 @@ def _load_template(self): self.log.debug(" template_paths: %s", os.pathsep.join(self.template_paths)) return self.environment.get_template(template_file) - def from_filename( # type:ignore - self, filename: str, resources: t.Optional[dict] = None, **kw: t.Any - ) -> t.Tuple[str, dict]: + def from_filename( # type:ignore[override] + self, filename: str, resources: dict[str, t.Any] | None = None, **kw: t.Any + ) -> tuple[str, dict[str, t.Any]]: """Convert a notebook from a filename.""" - return super().from_filename(filename, resources, **kw) # type:ignore + return super().from_filename(filename, resources, **kw) # type:ignore[return-value] - def from_file( # type:ignore - self, file_stream: t.Any, resources: t.Optional[dict] = None, **kw: t.Any - ) -> t.Tuple[str, dict]: + def from_file( # type:ignore[override] + self, file_stream: t.Any, resources: dict[str, t.Any] | None = None, **kw: t.Any + ) -> tuple[str, dict[str, t.Any]]: """Convert a notebook from a file.""" - return super().from_file(file_stream, resources, **kw) # type:ignore + return super().from_file(file_stream, resources, **kw) # type:ignore[return-value] - def from_notebook_node( # type:ignore - self, nb: NotebookNode, resources: t.Optional[dict] = None, **kw: t.Any - ) -> t.Tuple[str, dict]: + def from_notebook_node( # type:ignore[explicit-override, override] + self, nb: NotebookNode, resources: dict[str, t.Any] | None = None, **kw: t.Any + ) -> tuple[str, dict[str, t.Any]]: """ Convert a notebook from a notebook node instance. @@ -551,7 +551,7 @@ def _init_preprocessors(self): self.register_preprocessor(preprocessor) def _get_conf(self): - conf: dict = {} # the configuration once all conf files are merged + conf: dict[str, t.Any] = {} # the configuration once all conf files are merged for path in map(Path, self.template_paths): conf_path = path / "conf.json" if conf_path.exists(): @@ -607,11 +607,11 @@ def get_template_names(self): # noqa """Finds a list of template names where each successive template name is the base template""" template_names = [] root_dirs = self.get_prefix_root_dirs() - base_template = self.template_name - merged_conf: dict = {} # the configuration once all conf files are merged + base_template: str | None = self.template_name + merged_conf: dict[str, t.Any] = {} # the configuration once all conf files are merged while base_template is not None: template_names.append(base_template) - conf: dict = {} + conf: dict[str, t.Any] = {} found_at_least_one = False for base_dir in self.extra_template_basedirs: template_dir = os.path.join(base_dir, base_template) @@ -645,14 +645,14 @@ def get_template_names(self): # noqa ) self.template_file = compatibility_file conf = self.get_compatibility_base_template_conf(base_template) - self.template_name = conf.get("base_template") + self.template_name = t.cast(str, conf.get("base_template")) break if not found_at_least_one: paths = "\n\t".join(root_dirs) msg = f"No template sub-directory with name {base_template!r} found in the following paths:\n\t{paths}" raise ValueError(msg) merged_conf = recursive_update(dict(conf), merged_conf) - base_template = conf.get("base_template") + base_template = t.cast(t.Any, conf.get("base_template")) conf = merged_conf mimetypes = [mimetype for mimetype, enabled in conf.get("mimetypes", {}).items() if enabled] if self.output_mimetype and self.output_mimetype not in mimetypes and mimetypes: diff --git a/nbconvert/exporters/webpdf.py b/nbconvert/exporters/webpdf.py index 8f6fd2417..4f1343368 100644 --- a/nbconvert/exporters/webpdf.py +++ b/nbconvert/exporters/webpdf.py @@ -150,7 +150,7 @@ async def main(temp_file): def run_coroutine(coro): """Run an internal coroutine.""" loop = ( - asyncio.ProactorEventLoop() # type:ignore + asyncio.ProactorEventLoop() # type:ignore[attr-defined] if IS_WINDOWS else asyncio.new_event_loop() ) diff --git a/nbconvert/filters/__init__.py b/nbconvert/filters/__init__.py index eb4644a75..27bedca1e 100644 --- a/nbconvert/filters/__init__.py +++ b/nbconvert/filters/__init__.py @@ -1,11 +1,72 @@ from nbconvert.utils.text import indent -from .ansi import * -from .citation import * -from .datatypefilter import * -from .highlight import * -from .latex import * -from .markdown import * -from .metadata import * -from .pandoc import * -from .strings import * +from .ansi import ansi2html, ansi2latex, strip_ansi +from .citation import citation2latex +from .datatypefilter import DataTypeFilter +from .highlight import Highlight2HTML, Highlight2Latex +from .latex import escape_latex +from .markdown import ( + markdown2asciidoc, + markdown2html, + markdown2html_mistune, + markdown2html_pandoc, + markdown2latex, + markdown2rst, +) +from .metadata import get_metadata +from .pandoc import ConvertExplicitlyRelativePaths, convert_pandoc +from .strings import ( + add_anchor, + add_prompts, + ascii_only, + clean_html, + comment_lines, + get_lines, + html2text, + ipython2python, + path2url, + posix_path, + prevent_list_blocks, + strip_dollars, + strip_files_prefix, + strip_trailing_newline, + text_base64, + wrap_text, +) + +__all__ = [ + "indent", + "ansi2html", + "ansi2latex", + "strip_ansi", + "citation2latex", + "DataTypeFilter", + "Highlight2HTML", + "Highlight2Latex", + "escape_latex", + "markdown2html", + "markdown2html_pandoc", + "markdown2html_mistune", + "markdown2latex", + "markdown2rst", + "markdown2asciidoc", + "get_metadata", + "convert_pandoc", + "ConvertExplicitlyRelativePaths", + "wrap_text", + "html2text", + "clean_html", + "add_anchor", + "strip_dollars", + "strip_files_prefix", + "comment_lines", + "get_lines", + "ipython2python", + "posix_path", + "path2url", + "add_prompts", + "ascii_only", + "prevent_list_blocks", + "strip_trailing_newline", + "text_base64", +] diff --git a/nbconvert/filters/ansi.py b/nbconvert/filters/ansi.py index 6e82a3fa7..07319de83 100644 --- a/nbconvert/filters/ansi.py +++ b/nbconvert/filters/ansi.py @@ -203,7 +203,7 @@ def _ansi2anything(text, converter): # noqa if chunk: starttag, endtag = converter( - fg + 8 if bold and fg in range(8) else fg, # type:ignore + fg + 8 if bold and fg in range(8) else fg, # type:ignore[operator] bg, bold, underline, diff --git a/nbconvert/filters/citation.py b/nbconvert/filters/citation.py index 9ed30d50b..dde295646 100644 --- a/nbconvert/filters/citation.py +++ b/nbconvert/filters/citation.py @@ -65,7 +65,7 @@ class CitationParser(HTMLParser): # number of open tags opentags = None # list of found citations - citelist = None # type:ignore + citelist = None # type:ignore[var-annotated] # active citation tag citetag = None @@ -97,7 +97,7 @@ def handle_starttag(self, tag, attrs): if tag == self.citetag: # found an open citation tag but not the starting one - self.opentags += 1 # type:ignore + self.opentags += 1 # type:ignore[operator] def handle_endtag(self, tag): """Handle an end tag.""" @@ -106,7 +106,7 @@ def handle_endtag(self, tag): if self.opentags == 1: pos = self.get_offset() self.citelist[-1].append(pos + len(tag) + 3) - self.opentags -= 1 # type:ignore + self.opentags -= 1 # type:ignore[operator] def feed(self, data): """Handle a feed.""" diff --git a/nbconvert/filters/filter_links.py b/nbconvert/filters/filter_links.py index a1ce09f06..1c655fc72 100644 --- a/nbconvert/filters/filter_links.py +++ b/nbconvert/filters/filter_links.py @@ -4,7 +4,7 @@ """ import re -from pandocfilters import RawInline, applyJSONFilters, stringify # type:ignore +from pandocfilters import RawInline, applyJSONFilters, stringify # type:ignore[import] def resolve_references(source): diff --git a/nbconvert/filters/highlight.py b/nbconvert/filters/highlight.py index 2a5fc7798..8b440a414 100644 --- a/nbconvert/filters/highlight.py +++ b/nbconvert/filters/highlight.py @@ -13,8 +13,7 @@ from html import escape from warnings import warn -from traitlets import observe -from traitlets.config import Dict +from traitlets import Dict, observe from nbconvert.utils.base import NbConvertBase diff --git a/nbconvert/filters/markdown_mistune.py b/nbconvert/filters/markdown_mistune.py index 5ad2142cf..a1b70b336 100644 --- a/nbconvert/filters/markdown_mistune.py +++ b/nbconvert/filters/markdown_mistune.py @@ -22,7 +22,7 @@ from nbconvert.filters.strings import add_anchor try: # for Mistune >= 3.0 - from mistune import ( + from mistune import ( # type:ignore[attr-defined] BlockParser, BlockState, HTMLRenderer, @@ -202,7 +202,7 @@ class MathBlockParser(BlockParser): # type: ignore[no-redef] AXT_HEADING = re.compile(r" {0,3}(#{1,6})(?!#+)(?: *\n+|([^\n]*?)(?:\n+|\s+?#+\s*\n+))") # Multiline math must be searched before other rules - RULE_NAMES = ("multiline_math", *BlockParser.RULE_NAMES) # type: ignore + RULE_NAMES = ("multiline_math", *BlockParser.RULE_NAMES) # type: ignore[attr-defined] def parse_multiline_math(self, m: Match[str], state: Any) -> Dict[str, str]: """Pass token through mutiline math.""" @@ -234,7 +234,7 @@ class MathInlineParser(InlineParser): # type: ignore[no-redef] "inline_math_tex", "inline_math_latex", "latex_environment", - *InlineParser.RULE_NAMES, # type: ignore + *InlineParser.RULE_NAMES, # type: ignore[attr-defined] ) def parse_block_math_tex(self, m: Match[str], state: Any) -> Tuple[str, str]: @@ -476,7 +476,7 @@ def __init__( if MISTUNE_V3: inline = MathInlineParser(hard_wrap=False) else: - inline = MathInlineParser(renderer, hard_wrap=False) # type: ignore + inline = MathInlineParser(renderer, hard_wrap=False) # type: ignore[arg-type,misc] if plugins is None: plugins = (import_plugin(p) for p in self.DEFAULT_PLUGINS) diff --git a/nbconvert/filters/pandoc.py b/nbconvert/filters/pandoc.py index 165e98ba0..ec84888fd 100644 --- a/nbconvert/filters/pandoc.py +++ b/nbconvert/filters/pandoc.py @@ -4,11 +4,13 @@ """ import os -from pandocfilters import Image, applyJSONFilters # type:ignore +from pandocfilters import Image, applyJSONFilters # type:ignore[import] from nbconvert.utils.base import NbConvertBase from nbconvert.utils.pandoc import pandoc +__all__ = ["ConvertExplicitlyRelativePaths", "convert_pandoc"] + def convert_pandoc(source, from_format, to_format, extra_args=None): """Convert between any two formats using pandoc. diff --git a/nbconvert/filters/strings.py b/nbconvert/filters/strings.py index c84de083a..c4165c1d0 100644 --- a/nbconvert/filters/strings.py +++ b/nbconvert/filters/strings.py @@ -18,7 +18,7 @@ import bleach # defusedxml does safe(r) parsing of untrusted XML data -from defusedxml import ElementTree # type:ignore +from defusedxml import ElementTree # type:ignore[import] from nbconvert.preprocessors.sanitize import _get_default_css_sanitizer diff --git a/nbconvert/nbconvertapp.py b/nbconvert/nbconvertapp.py index 01e608329..40600300e 100755 --- a/nbconvert/nbconvertapp.py +++ b/nbconvert/nbconvertapp.py @@ -6,13 +6,14 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. - +from __future__ import annotations import asyncio import glob import logging import os import sys +import typing as t from textwrap import dedent, fill from jupyter_core.application import JupyterApp, base_aliases, base_flags @@ -195,11 +196,11 @@ class NbConvertApp(JupyterApp): def _log_level_default(self): return logging.INFO - classes = List() # type:ignore + classes = List() # type:ignore[assignment] @default("classes") def _classes_default(self): - classes: list = [NbConvertBase] + classes: list[type[t.Any]] = [NbConvertBase] for pkg in (exporters, preprocessors, writers, postprocessors): for name in dir(pkg): cls = getattr(pkg, name) @@ -208,7 +209,7 @@ def _classes_default(self): return classes - description = Unicode( # type:ignore + description = Unicode( # type:ignore[assignment] """This application is used to convert notebook files (*.ipynb) to various other formats. @@ -327,7 +328,7 @@ def _postprocessor_class_changed(self, change): if new: self.postprocessor_factory = import_item(new) - export_format = Unicode( + export_format = Unicode( # type:ignore[call-overload] allow_none=False, help=f"""The export format to be used, either one of the built-in formats {get_export_names()} @@ -394,7 +395,7 @@ def init_notebooks(self): def init_writer(self): """Initialize the writer (which is stateless)""" self._writer_class_changed({"new": self.writer_class}) - self.writer = self.writer_factory(parent=self) + self.writer = self.writer_factory(parent=self) # type:ignore[operator] if hasattr(self.writer, "build_directory") and self.writer.build_directory != "": self.use_output_suffix = False @@ -402,7 +403,7 @@ def init_postprocessor(self): """Initialize the postprocessor (which is stateless)""" self._postprocessor_class_changed({"new": self.postprocessor_class}) if self.postprocessor_factory: - self.postprocessor = self.postprocessor_factory(parent=self) + self.postprocessor = self.postprocessor_factory(parent=self) # type:ignore[operator] def start(self): """Run start after initialization process has completed""" @@ -510,6 +511,9 @@ def write_single_notebook(self, output, resources): if self.use_output_suffix and self.output_base == "{notebook_name}": notebook_name += resources.get("output_suffix", "") + if not self.writer: + msg = "No writer object defined!" + raise ValueError(msg) write_results = self.writer.write(output, resources, notebook_name=notebook_name) return write_results @@ -602,7 +606,7 @@ def document_flag_help(self): def document_alias_help(self): """Return a string containing all of the aliases""" - aliases = "The folowing aliases are defined:\n\n" + aliases = "The following aliases are defined:\n\n" for alias, longname in self.aliases.items(): aliases += f"\t**{alias}** ({longname})\n\n" return aliases diff --git a/nbconvert/postprocessors/__init__.py b/nbconvert/postprocessors/__init__.py index 75ff9474d..5a3317712 100644 --- a/nbconvert/postprocessors/__init__.py +++ b/nbconvert/postprocessors/__init__.py @@ -4,4 +4,6 @@ try: from .serve import ServePostProcessor except ImportError: - pass + ServePostProcessor = None # type:ignore[misc,assignment] + +__all__ = ["PostProcessorBase", "ServePostProcessor"] diff --git a/nbconvert/postprocessors/serve.py b/nbconvert/postprocessors/serve.py index 59298b608..c5391aa8c 100644 --- a/nbconvert/postprocessors/serve.py +++ b/nbconvert/postprocessors/serve.py @@ -2,10 +2,11 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. - +from __future__ import annotations import os import threading +import typing as t import webbrowser from tornado import gen, httpserver, ioloop, log, web @@ -63,7 +64,7 @@ class ServePostProcessor(PostProcessorBase): def postprocess(self, input): # noqa """Serve the build directory with a webserver.""" dirname, filename = os.path.split(input) - handlers: list = [ + handlers: list[tuple[t.Any, ...]] = [ (r"/(.+)", web.StaticFileHandler, {"path": dirname}), (r"/", web.RedirectHandler, {"url": "/%s" % filename}), ] @@ -79,7 +80,7 @@ def postprocess(self, input): # noqa handlers.insert(0, (r"/(%s)/(.*)" % self.reveal_prefix, ProxyHandler)) app = web.Application( - handlers, + handlers, # type:ignore[arg-type] cdn=self.reveal_cdn, client=AsyncHTTPClient(), ) diff --git a/nbconvert/preprocessors/__init__.py b/nbconvert/preprocessors/__init__.py index a13443d92..44bfb2e55 100644 --- a/nbconvert/preprocessors/__init__.py +++ b/nbconvert/preprocessors/__init__.py @@ -1,5 +1,5 @@ # Class base Preprocessors -# Backwards compatability for imported name +# Backwards compatibility for imported name from nbclient.exceptions import CellExecutionError from .base import Preprocessor @@ -18,3 +18,20 @@ from .regexremove import RegexRemovePreprocessor from .svg2pdf import SVG2PDFPreprocessor from .tagremove import TagRemovePreprocessor + +__all__ = [ + "CellExecutionError", + "Preprocessor", + "ClearMetadataPreprocessor", + "ClearOutputPreprocessor", + "ConvertFiguresPreprocessor", + "CSSHTMLHeaderPreprocessor", + "ExecutePreprocessor", + "ExtractAttachmentsPreprocessor", + "ExtractOutputPreprocessor", + "HighlightMagicsPreprocessor", + "LatexPreprocessor", + "RegexRemovePreprocessor", + "SVG2PDFPreprocessor", + "TagRemovePreprocessor", +] diff --git a/nbconvert/preprocessors/base.py b/nbconvert/preprocessors/base.py index edfc9272a..a2c2c7407 100644 --- a/nbconvert/preprocessors/base.py +++ b/nbconvert/preprocessors/base.py @@ -87,4 +87,3 @@ def preprocess_cell(self, cell, resources, index): """ msg = "should be implemented by subclass" raise NotImplementedError(msg) - return cell, resources diff --git a/nbconvert/preprocessors/csshtmlheader.py b/nbconvert/preprocessors/csshtmlheader.py index af9c6e364..81bfa917c 100644 --- a/nbconvert/preprocessors/csshtmlheader.py +++ b/nbconvert/preprocessors/csshtmlheader.py @@ -7,14 +7,14 @@ import hashlib import os -from jupyterlab_pygments import JupyterStyle # type:ignore +from jupyterlab_pygments import JupyterStyle # type:ignore[import] from pygments.style import Style from traitlets import Type, Unicode, Union from .base import Preprocessor try: - from notebook import DEFAULT_STATIC_FILES_PATH # type:ignore + from notebook import DEFAULT_STATIC_FILES_PATH # type:ignore[import] except ImportError: DEFAULT_STATIC_FILES_PATH = None diff --git a/nbconvert/preprocessors/execute.py b/nbconvert/preprocessors/execute.py index 08ec36fa1..57728e056 100644 --- a/nbconvert/preprocessors/execute.py +++ b/nbconvert/preprocessors/execute.py @@ -1,12 +1,14 @@ """Module containing a preprocessor that executes the code cells and updates outputs""" +from __future__ import annotations + import typing as t from jupyter_client.manager import KernelManager -from nbclient import NotebookClient -from nbclient import execute as _execute +from nbclient.client import NotebookClient +from nbclient.client import execute as _execute -# Backwards compatability for imported name +# Backwards compatibility for imported name from nbclient.exceptions import CellExecutionError # noqa # Copyright (c) IPython Development Team. @@ -32,7 +34,7 @@ def executenb(*args, **kwargs): # We inherit from both classes to allow for traitlets to resolve as they did pre-6.0. # This unfortunately makes for some ugliness around initialization as NotebookClient # assumes it's a constructed class with a nb object that we have to hack around. -class ExecutePreprocessor(Preprocessor, NotebookClient): +class ExecutePreprocessor(Preprocessor, NotebookClient): # type:ignore[misc] """ Executes all the cells in a notebook """ @@ -50,8 +52,8 @@ def _check_assign_resources(self, resources): self.resources = resources def preprocess( - self, nb: NotebookNode, resources: t.Any = None, km: t.Optional[KernelManager] = None - ) -> t.Tuple[NotebookNode, dict]: + self, nb: NotebookNode, resources: t.Any = None, km: KernelManager | None = None + ) -> tuple[NotebookNode, dict[str, t.Any]]: """ Preprocess notebook executing each code cell. diff --git a/nbconvert/preprocessors/sanitize.py b/nbconvert/preprocessors/sanitize.py index 5cdfc5ebe..db7b235c0 100644 --- a/nbconvert/preprocessors/sanitize.py +++ b/nbconvert/preprocessors/sanitize.py @@ -23,7 +23,7 @@ except ImportError: try: # bleach <5 - from bleach import ALLOWED_STYLES # type:ignore + from bleach import ALLOWED_STYLES # type:ignore[attr-defined, no-redef] _USE_BLEACH_CSS_SANITIZER = False _USE_BLEACH_STYLES = True @@ -49,7 +49,7 @@ class SanitizeHTML(Preprocessor): """A preprocessor to sanitize html.""" # Bleach config. - attributes = Any( + attributes = Any( # type:ignore[call-overload] config=True, default_value=ALLOWED_ATTRIBUTES, help="Allowed HTML tag attributes", diff --git a/nbconvert/preprocessors/tagremove.py b/nbconvert/preprocessors/tagremove.py index d44cff9cc..f5b7a0713 100644 --- a/nbconvert/preprocessors/tagremove.py +++ b/nbconvert/preprocessors/tagremove.py @@ -5,6 +5,7 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. +from __future__ import annotations from traitlets import Set, Unicode @@ -32,7 +33,7 @@ class TagRemovePreprocessor(Preprocessor): removes inputs tagged with these values """ - remove_cell_tags = Set( + remove_cell_tags: set[str] = Set( # type:ignore[assignment] Unicode(), default_value=[], help=( @@ -40,7 +41,7 @@ class TagRemovePreprocessor(Preprocessor): "matches tags in ``cell.metadata.tags``." ), ).tag(config=True) - remove_all_outputs_tags = Set( + remove_all_outputs_tags: set[str] = Set( # type:ignore[assignment] Unicode(), default_value=[], help=( @@ -48,7 +49,7 @@ class TagRemovePreprocessor(Preprocessor): "matches tags in ``cell.metadata.tags``." ), ).tag(config=True) - remove_single_output_tags = Set( + remove_single_output_tags: set[str] = Set( # type:ignore[assignment] Unicode(), default_value=[], help=( @@ -56,7 +57,7 @@ class TagRemovePreprocessor(Preprocessor): "matches output *i* tags in ``cell.outputs[i].metadata.tags``." ), ).tag(config=True) - remove_input_tags = Set( + remove_input_tags: set[str] = Set( # type:ignore[assignment] Unicode(), default_value=[], help=( @@ -64,7 +65,9 @@ class TagRemovePreprocessor(Preprocessor): "matches tags in ``cell.metadata.tags``." ), ).tag(config=True) - remove_metadata_fields = Set({"collapsed", "scrolled"}).tag(config=True) + remove_metadata_fields: set[str] = Set({"collapsed", "scrolled"}).tag( + config=True + ) # type:ignore[assignment] def check_cell_conditions(self, cell, resources, index): """ diff --git a/nbconvert/utils/_contextlib_chdir.py b/nbconvert/utils/_contextlib_chdir.py index 271874575..1a0b1b17a 100644 --- a/nbconvert/utils/_contextlib_chdir.py +++ b/nbconvert/utils/_contextlib_chdir.py @@ -5,7 +5,7 @@ from contextlib import AbstractContextManager -class chdir(AbstractContextManager): # noqa +class chdir(AbstractContextManager): # type:ignore[type-arg] # noqa """Non thread-safe context manager to change the current working directory.""" def __init__(self, path): diff --git a/nbconvert/utils/io.py b/nbconvert/utils/io.py index dd402a5a9..d8f552d5a 100644 --- a/nbconvert/utils/io.py +++ b/nbconvert/utils/io.py @@ -9,6 +9,7 @@ import random import shutil import sys +from typing import Any, Dict def unicode_std_stream(stream="stdout"): @@ -51,7 +52,7 @@ def unicode_stdin_stream(): return codecs.getreader("utf-8")(stream_b) -class FormatSafeDict(dict): +class FormatSafeDict(Dict[Any, Any]): """Format a dictionary safely.""" def __missing__(self, key): diff --git a/nbconvert/utils/pandoc.py b/nbconvert/utils/pandoc.py index 8430b7450..8f43e5272 100644 --- a/nbconvert/utils/pandoc.py +++ b/nbconvert/utils/pandoc.py @@ -80,7 +80,7 @@ def get_pandoc_version(): version_pattern = re.compile(r"^\d+(\.\d+){1,}$") for tok in out_lines[0].decode("ascii", "replace").split(): if version_pattern.match(tok): - __version = tok # type:ignore + __version = tok # type:ignore[assignment] break return __version @@ -93,8 +93,8 @@ def check_pandoc_version(): PandocMissing If pandoc is unavailable. """ - if check_pandoc_version._cached is not None: # type:ignore - return check_pandoc_version._cached # type:ignore + if check_pandoc_version._cached is not None: # type:ignore[attr-defined] + return check_pandoc_version._cached # type:ignore[attr-defined] v = get_pandoc_version() if v is None: @@ -107,7 +107,7 @@ def check_pandoc_version(): ) return False ok = check_version(v, _minimal_version, max_v=_maximal_version) - check_pandoc_version._cached = ok # type:ignore + check_pandoc_version._cached = ok # type:ignore[attr-defined] if not ok: warnings.warn( "You are using an unsupported version of pandoc (%s).\n" % v @@ -120,7 +120,7 @@ def check_pandoc_version(): return ok -check_pandoc_version._cached = None # type:ignore +check_pandoc_version._cached = None # type:ignore[attr-defined] # ----------------------------------------------------------------------------- # Exception handling diff --git a/nbconvert/writers/files.py b/nbconvert/writers/files.py index 31cb10fe1..8349360a4 100644 --- a/nbconvert/writers/files.py +++ b/nbconvert/writers/files.py @@ -113,13 +113,13 @@ def write(self, output, resources, notebook_name=None, **kw): # Write the extracted attachments # if ExtractAttachmentsOutput specified a separate directory - attachs = resources.get("attachments", {}).items() - if attachs: + attachments = resources.get("attachments", {}).items() + if attachments: self.log.info( "Attachments will be in %s", os.path.join(resources.get("attachment_files_dir", ""), ""), ) - self._write_items(attachs, build_directory) + self._write_items(attachments, build_directory) # Copy referenced files to output directory if build_directory: @@ -144,15 +144,15 @@ def write(self, output, resources, notebook_name=None, **kw): # Determine where to write conversion results. dest = notebook_name + output_extension if output_extension is not None else notebook_name - dest = Path(build_directory) / dest + dest_path = Path(build_directory) / dest # Write conversion results. - self.log.info("Writing %i bytes to %s", len(output), dest) + self.log.info("Writing %i bytes to %s", len(output), dest_path) if isinstance(output, str): - with open(dest, "w", encoding="utf-8") as f: + with open(dest_path, "w", encoding="utf-8") as f: f.write(output) else: - with open(dest, "wb") as f: + with open(dest_path, "wb") as f: f.write(output) - return dest + return dest_path diff --git a/pyproject.toml b/pyproject.toml index 9d4e556bf..770f88f75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,8 +64,7 @@ test = [ "pytest-dependency", "ipykernel", "ipywidgets>=7", - "pre-commit", - "flaky" + "flaky", ] serve = ["tornado>=6.1"] docs = [ @@ -92,12 +91,6 @@ path = "nbconvert/_version.py" [tool.hatch.build.targets.sdist] artifacts = ["share/templates"] -[tool.hatch.build.targets.wheel] -exclude = [ - "nbconvert/tests/", - "nbconvert/**/tests/", -] - [tool.hatch.build.targets.wheel.shared-data] "share/templates" = "share/jupyter/nbconvert/templates" @@ -121,9 +114,9 @@ nowarn = "test -W default {args}" [tool.hatch.envs.typing] features = ["test"] -dependencies = ["mypy>=0.990"] +dependencies = ["mypy>=1.5.1", "traitlets>=5.10"] [tool.hatch.envs.typing.scripts] -test = "mypy --install-types --non-interactive {args:nbconvert}" +test = "mypy --install-types --non-interactive {args}" [tool.hatch.envs.lint] dependencies = [ @@ -146,10 +139,18 @@ fmt = [ ] [tool.pytest.ini_options] +minversion = "6.0" +xfail_strict = true +log_cli_level = "info" +addopts = [ + "-raXs", "--durations=10", "--color=yes", "--doctest-modules", + "--showlocals", "--strict-markers", "--strict-config", + "--ignore=tests/files/jupyter_nbconvert_config.py", + "--ignore=tests/files/override.py", +] markers = "network: marks tests which require network connection" -addopts = "-raXs --durations 10 --color=yes --doctest-modules --ignore=nbconvert/tests/files/override.py --ignore=nbconvert/tests/files/jupyter_nbconvert_config.py" testpaths = [ - "nbconvert/" + "tests/" ] filterwarnings = [ "error", @@ -187,20 +188,13 @@ relative_files = true source = ["nbconvert"] [tool.mypy] -check_untyped_defs = true -disallow_incomplete_defs = true -disallow_untyped_decorators = true -no_implicit_optional = true -no_implicit_reexport = false -pretty = true -show_error_context = true +files = "nbconvert" +python_version = "3.8" +strict = true show_error_codes = true -strict_equality = true -strict_optional = true -warn_unused_configs = true -warn_redundant_casts = true -warn_return_any = true -warn_unused_ignores = true +enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] +disable_error_code = ["no-untyped-def", "no-untyped-call"] +warn_unreachable = true [tool.black] line-length = 100 @@ -245,8 +239,7 @@ unfixable = [ # S101 Use of `assert` detected # TID252 Relative imports from parent modules are banned # PLR2004 Magic value used in comparison -"nbconvert/*/tests/*" = ["B011", "F841", "S101", "TID252", "PLR2004"] -"nbconvert/tests/*" = ["B011", "F841", "S101", "TID252", "PLR2004"] +"tests/*" = ["B011", "F841", "S101", "TID252", "PLR2004"] # F401 'foo' imported but unused # F403 'x' used; unable to detect undefined names "nbconvert/*/__init__.py" = ["F401", "F403"] @@ -262,4 +255,11 @@ ignore-property-decorators=true ignore-nested-functions=true ignore-nested-classes=true fail-under=100 -exclude = ["*/tests", "docs"] +exclude = ["tests", "docs"] + +[tool.repo-review] +ignore = ["PY007", "PP308", "GH102", "PC140"] + + +[tool.codespell] +skip = "*.ipynb,*.css,*.tex.j2,*iso639_1.py,*html.j2,*test_ansi.py" diff --git a/nbconvert/tests/README.md b/tests/README.md similarity index 100% rename from nbconvert/tests/README.md rename to tests/README.md diff --git a/nbconvert/exporters/tests/__init__.py b/tests/__init__.py similarity index 100% rename from nbconvert/exporters/tests/__init__.py rename to tests/__init__.py diff --git a/nbconvert/tests/base.py b/tests/base.py similarity index 97% rename from nbconvert/tests/base.py rename to tests/base.py index e92dccf5b..2a1f23cdc 100644 --- a/nbconvert/tests/base.py +++ b/tests/base.py @@ -15,9 +15,7 @@ from nbformat import v4, write -import nbconvert - -from ..utils import _contextlib_chdir +from nbconvert.utils import _contextlib_chdir class TestsBase(unittest.TestCase): @@ -136,9 +134,9 @@ def _get_files_path(self): names = self.__module__.split(".")[1:-1] names.append("files") - # Build a path using the nbconvert directory and the relative path we just + # Build a path using the tests directory and the relative path we just # found. - path = os.path.dirname(nbconvert.__file__) + path = os.path.dirname(__file__) return os.path.join(path, *names) def nbconvert(self, parameters, ignore_return_code=False, stdin=None): diff --git a/nbconvert/tests/exporter_entrypoint/eptest-0.1.dist-info/entry_points.txt b/tests/exporter_entrypoint/eptest-0.1.dist-info/entry_points.txt similarity index 100% rename from nbconvert/tests/exporter_entrypoint/eptest-0.1.dist-info/entry_points.txt rename to tests/exporter_entrypoint/eptest-0.1.dist-info/entry_points.txt diff --git a/nbconvert/tests/exporter_entrypoint/eptest.py b/tests/exporter_entrypoint/eptest.py similarity index 100% rename from nbconvert/tests/exporter_entrypoint/eptest.py rename to tests/exporter_entrypoint/eptest.py diff --git a/nbconvert/filters/tests/__init__.py b/tests/exporters/__init__.py similarity index 100% rename from nbconvert/filters/tests/__init__.py rename to tests/exporters/__init__.py diff --git a/nbconvert/exporters/tests/base.py b/tests/exporters/base.py similarity index 97% rename from nbconvert/exporters/tests/base.py rename to tests/exporters/base.py index f7da2a6ea..746eb7f6f 100644 --- a/nbconvert/exporters/tests/base.py +++ b/tests/exporters/base.py @@ -5,7 +5,7 @@ import os -from ...tests.base import TestsBase +from tests.base import TestsBase all_raw_mimetypes = { "text/x-python", diff --git a/nbconvert/exporters/tests/cheese.py b/tests/exporters/cheese.py similarity index 96% rename from nbconvert/exporters/tests/cheese.py rename to tests/exporters/cheese.py index aa27fb4a3..6467bfacb 100644 --- a/nbconvert/exporters/tests/cheese.py +++ b/tests/exporters/cheese.py @@ -13,7 +13,7 @@ # Imports # ----------------------------------------------------------------------------- -from ...preprocessors.base import Preprocessor +from nbconvert.preprocessors.base import Preprocessor # ----------------------------------------------------------------------------- # Classes diff --git a/nbconvert/exporters/tests/files/attachment.ipynb b/tests/exporters/files/attachment.ipynb similarity index 100% rename from nbconvert/exporters/tests/files/attachment.ipynb rename to tests/exporters/files/attachment.ipynb diff --git a/nbconvert/exporters/tests/files/lablike.html.j2 b/tests/exporters/files/lablike.html.j2 similarity index 100% rename from nbconvert/exporters/tests/files/lablike.html.j2 rename to tests/exporters/files/lablike.html.j2 diff --git a/nbconvert/exporters/tests/files/notebook2.ipynb b/tests/exporters/files/notebook2.ipynb similarity index 100% rename from nbconvert/exporters/tests/files/notebook2.ipynb rename to tests/exporters/files/notebook2.ipynb diff --git a/nbconvert/exporters/tests/files/notebook3.ipynb b/tests/exporters/files/notebook3.ipynb similarity index 100% rename from nbconvert/exporters/tests/files/notebook3.ipynb rename to tests/exporters/files/notebook3.ipynb diff --git a/nbconvert/exporters/tests/files/notebook_inject.ipynb b/tests/exporters/files/notebook_inject.ipynb similarity index 100% rename from nbconvert/exporters/tests/files/notebook_inject.ipynb rename to tests/exporters/files/notebook_inject.ipynb diff --git a/nbconvert/exporters/tests/files/pngmetadata.ipynb b/tests/exporters/files/pngmetadata.ipynb similarity index 100% rename from nbconvert/exporters/tests/files/pngmetadata.ipynb rename to tests/exporters/files/pngmetadata.ipynb diff --git a/nbconvert/exporters/tests/files/prompt_numbers.ipynb b/tests/exporters/files/prompt_numbers.ipynb similarity index 100% rename from nbconvert/exporters/tests/files/prompt_numbers.ipynb rename to tests/exporters/files/prompt_numbers.ipynb diff --git a/nbconvert/exporters/tests/files/rawtest.ipynb b/tests/exporters/files/rawtest.ipynb similarity index 100% rename from nbconvert/exporters/tests/files/rawtest.ipynb rename to tests/exporters/files/rawtest.ipynb diff --git a/nbconvert/exporters/tests/files/svg.ipynb b/tests/exporters/files/svg.ipynb similarity index 100% rename from nbconvert/exporters/tests/files/svg.ipynb rename to tests/exporters/files/svg.ipynb diff --git a/nbconvert/exporters/tests/test_asciidoc.py b/tests/exporters/test_asciidoc.py similarity index 95% rename from nbconvert/exporters/tests/test_asciidoc.py rename to tests/exporters/test_asciidoc.py index 1712b9a41..e2a2ae359 100644 --- a/nbconvert/exporters/tests/test_asciidoc.py +++ b/tests/exporters/test_asciidoc.py @@ -16,8 +16,9 @@ from traitlets.config import Config -from ...tests.utils import onlyif_cmds_exist -from ..asciidoc import ASCIIDocExporter +from nbconvert.exporters.asciidoc import ASCIIDocExporter +from tests.testutils import onlyif_cmds_exist + from .base import ExportersTestsBase # ----------------------------------------------------------------------------- diff --git a/nbconvert/exporters/tests/test_export.py b/tests/exporters/test_export.py similarity index 87% rename from nbconvert/exporters/tests/test_export.py rename to tests/exporters/test_export.py index ffb8ff5ca..071aa238b 100644 --- a/nbconvert/exporters/tests/test_export.py +++ b/tests/exporters/test_export.py @@ -12,11 +12,17 @@ import pytest from traitlets.config import Config -import nbconvert.tests +import tests +from nbconvert.exporters import ( + ExporterDisabledError, + ExporterNameError, + export, + get_export_names, + get_exporter, +) +from nbconvert.exporters.exporter import Exporter +from nbconvert.exporters.python import PythonExporter -from ..base import ExporterDisabledError, ExporterNameError, export, get_export_names, get_exporter -from ..exporter import Exporter -from ..python import PythonExporter from .base import ExportersTestsBase @@ -30,7 +36,7 @@ def test_export_wrong_name(self): try: exporter = get_exporter("not_a_name") export(exporter, self._get_notebook()) - except ExporterNameError as e: + except ExporterNameError: pass def test_export_disabled(self): @@ -70,7 +76,7 @@ def test_export_filestream(self): def test_export_using_exporter(self): """ - Can a notebook be exported using an instanciated exporter? + Can a notebook be exported using an instantiated exporter? """ (output, resources) = export(PythonExporter(), self._get_notebook()) assert len(output) > 0 @@ -100,7 +106,7 @@ def test_no_exporter(self): def test_get_exporter_entrypoint(): - p = os.path.join(os.path.dirname(nbconvert.tests.__file__), "exporter_entrypoint") + p = os.path.join(os.path.dirname(tests.__file__), "exporter_entrypoint") sys.path.insert(0, p) assert "entrypoint_test" in get_export_names() try: diff --git a/nbconvert/exporters/tests/test_exporter.py b/tests/exporters/test_exporter.py similarity index 96% rename from nbconvert/exporters/tests/test_exporter.py rename to tests/exporters/test_exporter.py index ce021c8be..fb5ebaaef 100644 --- a/nbconvert/exporters/tests/test_exporter.py +++ b/tests/exporters/test_exporter.py @@ -18,9 +18,9 @@ from traitlets.config import Config -from ...preprocessors.base import Preprocessor -from .. import Exporter, TemplateExporter -from ..base import get_export_names +from nbconvert.exporters import Exporter, TemplateExporter, get_export_names +from nbconvert.preprocessors.base import Preprocessor + from .base import ExportersTestsBase # ----------------------------------------------------------------------------- diff --git a/nbconvert/exporters/tests/test_html.py b/tests/exporters/test_html.py similarity index 99% rename from nbconvert/exporters/tests/test_html.py rename to tests/exporters/test_html.py index cf2c10441..19e5f9f64 100644 --- a/nbconvert/exporters/tests/test_html.py +++ b/tests/exporters/test_html.py @@ -8,7 +8,8 @@ from nbformat import v4 from traitlets.config import Config -from ..html import HTMLExporter +from nbconvert.exporters.html import HTMLExporter + from .base import ExportersTestsBase diff --git a/nbconvert/exporters/tests/test_latex.py b/tests/exporters/test_latex.py similarity index 97% rename from nbconvert/exporters/tests/test_latex.py rename to tests/exporters/test_latex.py index 843e432ff..d389f0a8f 100644 --- a/nbconvert/exporters/tests/test_latex.py +++ b/tests/exporters/test_latex.py @@ -12,8 +12,9 @@ from nbformat import v4, write from traitlets.config import Config -from ...tests.utils import onlyif_cmds_exist -from ..latex import LatexExporter +from nbconvert.exporters.latex import LatexExporter +from tests.testutils import onlyif_cmds_exist + from .base import ExportersTestsBase current_dir = os.path.dirname(__file__) @@ -157,7 +158,7 @@ def test_no_prompt_yes_input(self): @onlyif_cmds_exist("pandoc", "inkscape") def test_svg(self): """ - Can a LatexExporter export when it recieves raw binary strings form svg? + Can a LatexExporter export when it receives raw binary strings form svg? """ filename = os.path.join(current_dir, "files", "svg.ipynb") diff --git a/nbconvert/exporters/tests/test_markdown.py b/tests/exporters/test_markdown.py similarity index 95% rename from nbconvert/exporters/tests/test_markdown.py rename to tests/exporters/test_markdown.py index 8c3584806..2fc6d5e3a 100644 --- a/nbconvert/exporters/tests/test_markdown.py +++ b/tests/exporters/test_markdown.py @@ -12,7 +12,8 @@ # Imports # ----------------------------------------------------------------------------- -from ..markdown import MarkdownExporter +from nbconvert.exporters.markdown import MarkdownExporter + from .base import ExportersTestsBase # ----------------------------------------------------------------------------- diff --git a/nbconvert/exporters/tests/test_notebook.py b/tests/exporters/test_notebook.py similarity index 92% rename from nbconvert/exporters/tests/test_notebook.py rename to tests/exporters/test_notebook.py index c67395bf7..0d8dd9255 100644 --- a/nbconvert/exporters/tests/test_notebook.py +++ b/tests/exporters/test_notebook.py @@ -7,9 +7,9 @@ from nbformat import validate -from nbconvert.tests.base import assert_big_text_equal +from nbconvert.exporters.notebook import NotebookExporter +from tests.base import assert_big_text_equal -from ..notebook import NotebookExporter from .base import ExportersTestsBase diff --git a/nbconvert/exporters/tests/test_pdf.py b/tests/exporters/test_pdf.py similarity index 94% rename from nbconvert/exporters/tests/test_pdf.py rename to tests/exporters/test_pdf.py index 568fb2263..b2e93abf7 100644 --- a/nbconvert/exporters/tests/test_pdf.py +++ b/tests/exporters/test_pdf.py @@ -7,9 +7,10 @@ import shutil from tempfile import TemporaryDirectory -from ...tests.utils import onlyif_cmds_exist -from ...utils import _contextlib_chdir -from ..pdf import PDFExporter +from nbconvert.exporters.pdf import PDFExporter +from nbconvert.utils import _contextlib_chdir +from tests.testutils import onlyif_cmds_exist + from .base import ExportersTestsBase # ----------------------------------------------------------------------------- diff --git a/nbconvert/exporters/tests/test_python.py b/tests/exporters/test_python.py similarity index 93% rename from nbconvert/exporters/tests/test_python.py rename to tests/exporters/test_python.py index 285392bce..097bbb204 100644 --- a/nbconvert/exporters/tests/test_python.py +++ b/tests/exporters/test_python.py @@ -3,7 +3,8 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -from ..python import PythonExporter +from nbconvert.exporters.python import PythonExporter + from .base import ExportersTestsBase diff --git a/nbconvert/exporters/tests/test_qtpdf.py b/tests/exporters/test_qtpdf.py similarity index 84% rename from nbconvert/exporters/tests/test_qtpdf.py rename to tests/exporters/test_qtpdf.py index 598752321..4150f4c54 100644 --- a/nbconvert/exporters/tests/test_qtpdf.py +++ b/tests/exporters/test_qtpdf.py @@ -5,8 +5,9 @@ import pytest -from ..qt_screenshot import QT_INSTALLED -from ..qtpdf import QtPDFExporter +from nbconvert.exporters.qt_screenshot import QT_INSTALLED +from nbconvert.exporters.qtpdf import QtPDFExporter + from .base import ExportersTestsBase diff --git a/nbconvert/exporters/tests/test_qtpng.py b/tests/exporters/test_qtpng.py similarity index 83% rename from nbconvert/exporters/tests/test_qtpng.py rename to tests/exporters/test_qtpng.py index 267627e30..6e46a25ba 100644 --- a/nbconvert/exporters/tests/test_qtpng.py +++ b/tests/exporters/test_qtpng.py @@ -7,8 +7,9 @@ import pytest -from ..qt_screenshot import QT_INSTALLED -from ..qtpng import QtPNGExporter +from nbconvert.exporters.qt_screenshot import QT_INSTALLED +from nbconvert.exporters.qtpng import QtPNGExporter + from .base import ExportersTestsBase @@ -24,7 +25,7 @@ def test_export(self): """ if os.name == "nt": # currently not supported - with pytest.raises(RuntimeError) as exc_info: + with pytest.raises(RuntimeError): (output, resources) = QtPNGExporter().from_filename(self._get_notebook()) else: (output, resources) = QtPNGExporter().from_filename(self._get_notebook()) diff --git a/nbconvert/exporters/tests/test_rst.py b/tests/exporters/test_rst.py similarity index 95% rename from nbconvert/exporters/tests/test_rst.py rename to tests/exporters/test_rst.py index 5f53aa1b8..4a5f5c3c4 100644 --- a/nbconvert/exporters/tests/test_rst.py +++ b/tests/exporters/test_rst.py @@ -8,8 +8,9 @@ import nbformat from nbformat import v4 -from ...tests.utils import onlyif_cmds_exist -from ..rst import RSTExporter +from nbconvert.exporters.rst import RSTExporter +from tests.testutils import onlyif_cmds_exist + from .base import ExportersTestsBase diff --git a/nbconvert/exporters/tests/test_script.py b/tests/exporters/test_script.py similarity index 89% rename from nbconvert/exporters/tests/test_script.py rename to tests/exporters/test_script.py index 652e19f80..bdaeee2f1 100644 --- a/nbconvert/exporters/tests/test_script.py +++ b/tests/exporters/test_script.py @@ -8,9 +8,9 @@ from nbformat import v4 -import nbconvert +import tests +from nbconvert.exporters.script import ScriptExporter -from ..script import ScriptExporter from .base import ExportersTestsBase @@ -21,7 +21,7 @@ class TestScriptExporter(ExportersTestsBase): def test_constructor(self): """Construct ScriptExporter""" - e = self.exporter_class() # type:ignore + self.exporter_class() # type:ignore def test_export(self): """ScriptExporter can export something""" @@ -32,7 +32,7 @@ def test_export(self): def test_export_python(self): """delegate to custom exporter from language_info""" - exporter = self.exporter_class() # type:ignore + self.exporter_class() # type:ignore pynb = v4.new_notebook() (output, resources) = self.exporter_class().from_notebook_node(pynb) # type:ignore @@ -68,7 +68,7 @@ def test_script_exporter_entrypoint(): "mimetype": "text/x-dummy", } - p = os.path.join(os.path.dirname(nbconvert.tests.__file__), "exporter_entrypoint") + p = os.path.join(os.path.dirname(tests.__file__), "exporter_entrypoint") sys.path.insert(0, p) try: output, _ = ScriptExporter().from_notebook_node(nb) diff --git a/nbconvert/exporters/tests/test_slides.py b/tests/exporters/test_slides.py similarity index 96% rename from nbconvert/exporters/tests/test_slides.py rename to tests/exporters/test_slides.py index 463561656..72bfa131a 100644 --- a/nbconvert/exporters/tests/test_slides.py +++ b/tests/exporters/test_slides.py @@ -5,7 +5,8 @@ from nbformat import v4 as nbformat -from ..slides import SlidesExporter, _RevealMetadataPreprocessor +from nbconvert.exporters.slides import SlidesExporter, _RevealMetadataPreprocessor + from .base import ExportersTestsBase @@ -65,7 +66,7 @@ def test_metadata_preprocessor(self): for cell in cells: assert "slide_type" in cell.metadata - # Make sure slide end is only applied to the cells preceeding slide + # Make sure slide end is only applied to the cells preceding slide # cells. assert not cells[1].metadata.get("slide_end", False) diff --git a/nbconvert/exporters/tests/test_templateexporter.py b/tests/exporters/test_templateexporter.py similarity index 98% rename from nbconvert/exporters/tests/test_templateexporter.py rename to tests/exporters/test_templateexporter.py index 88b4e86ac..06891afe8 100644 --- a/nbconvert/exporters/tests/test_templateexporter.py +++ b/tests/exporters/test_templateexporter.py @@ -17,11 +17,12 @@ from traitlets import default from traitlets.config import Config -from ...utils import _contextlib_chdir -from ..html import HTMLExporter -from ..markdown import MarkdownExporter -from ..rst import RSTExporter -from ..templateexporter import TemplateExporter +from nbconvert.exporters.html import HTMLExporter +from nbconvert.exporters.markdown import MarkdownExporter +from nbconvert.exporters.rst import RSTExporter +from nbconvert.exporters.templateexporter import TemplateExporter +from nbconvert.utils import _contextlib_chdir + from .base import ExportersTestsBase from .cheese import CheesePreprocessor @@ -99,7 +100,7 @@ def test_preprocessor_dottedobjectname(self): Can a preprocessor be added to the preprocessors list by dotted object name? """ config = Config( - {"Exporter": {"preprocessors": ["nbconvert.exporters.tests.cheese.CheesePreprocessor"]}} + {"Exporter": {"preprocessors": ["tests.exporters.cheese.CheesePreprocessor"]}} ) exporter = self._make_exporter(config=config) (output, resources) = exporter.from_filename(self._get_notebook()) @@ -473,7 +474,7 @@ def test_raw_template_dereassignment(self): def test_fail_to_find_template_file(self): # Create exporter with invalid template file, check that it doesn't # exist in the environment, try to convert empty notebook. Failure is - # expected due to nonexistant template file. + # expected due to nonexistent template file. template = "does_not_exist.tpl" exporter = TemplateExporter(template_file=template) diff --git a/nbconvert/exporters/tests/test_webpdf.py b/tests/exporters/test_webpdf.py similarity index 94% rename from nbconvert/exporters/tests/test_webpdf.py rename to tests/exporters/test_webpdf.py index 3a0932689..4bb11d5fa 100644 --- a/nbconvert/exporters/tests/test_webpdf.py +++ b/tests/exporters/test_webpdf.py @@ -8,8 +8,9 @@ import pytest -from ..exporter import Exporter -from ..webpdf import PLAYWRIGHT_INSTALLED, WebPDFExporter +from nbconvert.exporters.exporter import Exporter +from nbconvert.exporters.webpdf import PLAYWRIGHT_INSTALLED, WebPDFExporter + from .base import ExportersTestsBase real_import = builtins.__import__ diff --git a/nbconvert/tests/fake_exporters.py b/tests/fake_exporters.py similarity index 100% rename from nbconvert/tests/fake_exporters.py rename to tests/fake_exporters.py diff --git a/nbconvert/tests/files/Unexecuted_widget.ipynb b/tests/files/Unexecuted_widget.ipynb similarity index 100% rename from nbconvert/tests/files/Unexecuted_widget.ipynb rename to tests/files/Unexecuted_widget.ipynb diff --git a/nbconvert/tests/files/Unexecuted_widget_2.ipynb b/tests/files/Unexecuted_widget_2.ipynb similarity index 100% rename from nbconvert/tests/files/Unexecuted_widget_2.ipynb rename to tests/files/Unexecuted_widget_2.ipynb diff --git a/nbconvert/tests/files/Widget_List.ipynb b/tests/files/Widget_List.ipynb similarity index 100% rename from nbconvert/tests/files/Widget_List.ipynb rename to tests/files/Widget_List.ipynb diff --git a/nbconvert/tests/files/containerized_deployments.jpeg b/tests/files/containerized_deployments.jpeg similarity index 100% rename from nbconvert/tests/files/containerized_deployments.jpeg rename to tests/files/containerized_deployments.jpeg diff --git a/nbconvert/tests/files/hello.py b/tests/files/hello.py similarity index 100% rename from nbconvert/tests/files/hello.py rename to tests/files/hello.py diff --git a/nbconvert/tests/files/jupyter_nbconvert_config.py b/tests/files/jupyter_nbconvert_config.py similarity index 100% rename from nbconvert/tests/files/jupyter_nbconvert_config.py rename to tests/files/jupyter_nbconvert_config.py diff --git a/nbconvert/tests/files/latex-linked-image.ipynb b/tests/files/latex-linked-image.ipynb similarity index 100% rename from nbconvert/tests/files/latex-linked-image.ipynb rename to tests/files/latex-linked-image.ipynb diff --git a/nbconvert/tests/files/markdown_display_priority.ipynb b/tests/files/markdown_display_priority.ipynb similarity index 100% rename from nbconvert/tests/files/markdown_display_priority.ipynb rename to tests/files/markdown_display_priority.ipynb diff --git a/nbconvert/tests/files/notebook1.ipynb b/tests/files/notebook1.ipynb similarity index 100% rename from nbconvert/tests/files/notebook1.ipynb rename to tests/files/notebook1.ipynb diff --git a/nbconvert/tests/files/notebook2.ipynb b/tests/files/notebook2.ipynb similarity index 100% rename from nbconvert/tests/files/notebook2.ipynb rename to tests/files/notebook2.ipynb diff --git a/nbconvert/tests/files/notebook3_with_errors.ipynb b/tests/files/notebook3_with_errors.ipynb similarity index 100% rename from nbconvert/tests/files/notebook3_with_errors.ipynb rename to tests/files/notebook3_with_errors.ipynb diff --git a/nbconvert/tests/files/notebook4_jpeg.ipynb b/tests/files/notebook4_jpeg.ipynb similarity index 100% rename from nbconvert/tests/files/notebook4_jpeg.ipynb rename to tests/files/notebook4_jpeg.ipynb diff --git a/nbconvert/tests/files/notebook5_embed_images.ipynb b/tests/files/notebook5_embed_images.ipynb similarity index 100% rename from nbconvert/tests/files/notebook5_embed_images.ipynb rename to tests/files/notebook5_embed_images.ipynb diff --git a/nbconvert/tests/files/notebook_jl.ipynb b/tests/files/notebook_jl.ipynb similarity index 100% rename from nbconvert/tests/files/notebook_jl.ipynb rename to tests/files/notebook_jl.ipynb diff --git a/nbconvert/tests/files/notebook_tags.ipynb b/tests/files/notebook_tags.ipynb similarity index 100% rename from nbconvert/tests/files/notebook_tags.ipynb rename to tests/files/notebook_tags.ipynb diff --git a/nbconvert/tests/files/override.py b/tests/files/override.py similarity index 100% rename from nbconvert/tests/files/override.py rename to tests/files/override.py diff --git a/nbconvert/tests/files/testimage.png b/tests/files/testimage.png similarity index 100% rename from nbconvert/tests/files/testimage.png rename to tests/files/testimage.png diff --git a/nbconvert/postprocessors/tests/__init__.py b/tests/filters/__init__.py similarity index 100% rename from nbconvert/postprocessors/tests/__init__.py rename to tests/filters/__init__.py diff --git a/nbconvert/filters/tests/test_ansi.py b/tests/filters/test_ansi.py similarity index 97% rename from nbconvert/filters/tests/test_ansi.py rename to tests/filters/test_ansi.py index 762c59431..82b2bfb6b 100644 --- a/nbconvert/filters/tests/test_ansi.py +++ b/tests/filters/test_ansi.py @@ -6,8 +6,8 @@ # Distributed under the terms of the Modified BSD License. -from ...tests.base import TestsBase -from ..ansi import ansi2html, ansi2latex, strip_ansi +from nbconvert.filters.ansi import ansi2html, ansi2latex, strip_ansi +from tests.base import TestsBase class TestAnsi(TestsBase): diff --git a/nbconvert/filters/tests/test_citation.py b/tests/filters/test_citation.py similarity index 98% rename from nbconvert/filters/tests/test_citation.py rename to tests/filters/test_citation.py index ca5529974..4e940d927 100644 --- a/nbconvert/filters/tests/test_citation.py +++ b/tests/filters/test_citation.py @@ -11,7 +11,7 @@ # ----------------------------------------------------------------------------- # Imports # ----------------------------------------------------------------------------- -from ..citation import citation2latex +from nbconvert.filters.citation import citation2latex # ----------------------------------------------------------------------------- # Tests diff --git a/nbconvert/filters/tests/test_datatypefilter.py b/tests/filters/test_datatypefilter.py similarity index 93% rename from nbconvert/filters/tests/test_datatypefilter.py rename to tests/filters/test_datatypefilter.py index cf9b2ce55..f70d717e0 100644 --- a/nbconvert/filters/tests/test_datatypefilter.py +++ b/tests/filters/test_datatypefilter.py @@ -4,8 +4,8 @@ # Distributed under the terms of the Modified BSD License. import pytest -from ...tests.base import TestsBase -from ..datatypefilter import DataTypeFilter +from nbconvert.filters.datatypefilter import DataTypeFilter +from tests.base import TestsBase class TestDataTypeFilter(TestsBase): diff --git a/nbconvert/filters/tests/test_highlight.py b/tests/filters/test_highlight.py similarity index 96% rename from nbconvert/filters/tests/test_highlight.py rename to tests/filters/test_highlight.py index 98a9a18fa..61eb65441 100644 --- a/nbconvert/filters/tests/test_highlight.py +++ b/tests/filters/test_highlight.py @@ -18,8 +18,8 @@ import pytest -from ...tests.base import TestsBase -from ..highlight import Highlight2HTML, Highlight2Latex +from nbconvert.filters.highlight import Highlight2HTML, Highlight2Latex +from tests.base import TestsBase # ----------------------------------------------------------------------------- # Class diff --git a/nbconvert/filters/tests/test_latex.py b/tests/filters/test_latex.py similarity index 95% rename from nbconvert/filters/tests/test_latex.py rename to tests/filters/test_latex.py index 451fa41a4..15bc42066 100644 --- a/nbconvert/filters/tests/test_latex.py +++ b/tests/filters/test_latex.py @@ -14,8 +14,8 @@ # Imports # ----------------------------------------------------------------------------- -from ...tests.base import TestsBase -from ..latex import escape_latex +from nbconvert.filters.latex import escape_latex +from tests.base import TestsBase # ----------------------------------------------------------------------------- # Class diff --git a/nbconvert/filters/tests/test_markdown.py b/tests/filters/test_markdown.py similarity index 97% rename from nbconvert/filters/tests/test_markdown.py rename to tests/filters/test_markdown.py index c271969eb..2fe08b0b4 100644 --- a/nbconvert/filters/tests/test_markdown.py +++ b/tests/filters/test_markdown.py @@ -10,10 +10,10 @@ from jinja2 import Environment -from ...tests.base import TestsBase -from ...tests.utils import onlyif_cmds_exist -from ..markdown import markdown2html -from ..pandoc import convert_pandoc +from nbconvert.filters.markdown import markdown2html +from nbconvert.filters.pandoc import convert_pandoc +from tests.base import TestsBase +from tests.testutils import onlyif_cmds_exist class TestMarkdown(TestsBase): diff --git a/nbconvert/filters/tests/test_metadata.py b/tests/filters/test_metadata.py similarity index 100% rename from nbconvert/filters/tests/test_metadata.py rename to tests/filters/test_metadata.py diff --git a/nbconvert/filters/tests/test_pandoc.py b/tests/filters/test_pandoc.py similarity index 92% rename from nbconvert/filters/tests/test_pandoc.py rename to tests/filters/test_pandoc.py index 21d9bb9c9..428355549 100644 --- a/nbconvert/filters/tests/test_pandoc.py +++ b/tests/filters/test_pandoc.py @@ -7,9 +7,9 @@ import json -from ...tests.base import TestsBase -from ...tests.utils import onlyif_cmds_exist -from ..pandoc import ConvertExplicitlyRelativePaths, convert_pandoc +from nbconvert.filters.pandoc import ConvertExplicitlyRelativePaths, convert_pandoc +from tests.base import TestsBase +from tests.testutils import onlyif_cmds_exist class TestPandocFilters(TestsBase): diff --git a/nbconvert/filters/tests/test_strings.py b/tests/filters/test_strings.py similarity index 99% rename from nbconvert/filters/tests/test_strings.py rename to tests/filters/test_strings.py index 0c738ab32..4195116a4 100644 --- a/nbconvert/filters/tests/test_strings.py +++ b/tests/filters/test_strings.py @@ -16,8 +16,7 @@ import os import re -from ...tests.base import TestsBase -from ..strings import ( +from nbconvert.filters.strings import ( add_anchor, add_prompts, ascii_only, @@ -31,6 +30,7 @@ strip_files_prefix, wrap_text, ) +from tests.base import TestsBase # ----------------------------------------------------------------------------- # Class diff --git a/nbconvert/preprocessors/tests/__init__.py b/tests/postprocessors/__init__.py similarity index 100% rename from nbconvert/preprocessors/tests/__init__.py rename to tests/postprocessors/__init__.py diff --git a/nbconvert/postprocessors/tests/test_serve.py b/tests/postprocessors/test_serve.py similarity index 84% rename from nbconvert/postprocessors/tests/test_serve.py rename to tests/postprocessors/test_serve.py index 54ea43c0c..f4112dd89 100644 --- a/nbconvert/postprocessors/tests/test_serve.py +++ b/tests/postprocessors/test_serve.py @@ -7,7 +7,7 @@ import pytest -from ...tests.base import TestsBase +from tests.base import TestsBase class TestServe(TestsBase): @@ -17,7 +17,7 @@ def test_constructor(self): """Can a ServePostProcessor be constructed?""" pytest.importorskip("tornado") try: - from ..serve import ServePostProcessor + from nbconvert.postprocessors.serve import ServePostProcessor except ImportError: print("Something weird is happening.\nTornado is sometimes present, sometimes not.") raise diff --git a/nbconvert/tests/__init__.py b/tests/preprocessors/__init__.py similarity index 100% rename from nbconvert/tests/__init__.py rename to tests/preprocessors/__init__.py diff --git a/nbconvert/preprocessors/tests/base.py b/tests/preprocessors/base.py similarity index 96% rename from nbconvert/preprocessors/tests/base.py rename to tests/preprocessors/base.py index ba0b63517..0839f4a41 100644 --- a/nbconvert/preprocessors/tests/base.py +++ b/tests/preprocessors/base.py @@ -7,8 +7,8 @@ from nbformat import v4 as nbformat -from ...exporters.exporter import ResourcesDict -from ...tests.base import TestsBase +from nbconvert.exporters.exporter import ResourcesDict +from tests.base import TestsBase class PreprocessorTestsBase(TestsBase): diff --git a/nbconvert/preprocessors/tests/fake_kernelmanager.py b/tests/preprocessors/fake_kernelmanager.py similarity index 100% rename from nbconvert/preprocessors/tests/fake_kernelmanager.py rename to tests/preprocessors/fake_kernelmanager.py diff --git a/nbconvert/preprocessors/tests/files/HelloWorld.ipynb b/tests/preprocessors/files/HelloWorld.ipynb similarity index 100% rename from nbconvert/preprocessors/tests/files/HelloWorld.ipynb rename to tests/preprocessors/files/HelloWorld.ipynb diff --git a/nbconvert/preprocessors/tests/files/MixedMarkdown.ipynb b/tests/preprocessors/files/MixedMarkdown.ipynb similarity index 100% rename from nbconvert/preprocessors/tests/files/MixedMarkdown.ipynb rename to tests/preprocessors/files/MixedMarkdown.ipynb diff --git a/nbconvert/preprocessors/tests/test_clearmetadata.py b/tests/preprocessors/test_clearmetadata.py similarity index 97% rename from nbconvert/preprocessors/tests/test_clearmetadata.py rename to tests/preprocessors/test_clearmetadata.py index 12269ad6e..39b9bcaa6 100644 --- a/nbconvert/preprocessors/tests/test_clearmetadata.py +++ b/tests/preprocessors/test_clearmetadata.py @@ -5,7 +5,8 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -from ..clearmetadata import ClearMetadataPreprocessor +from nbconvert.preprocessors.clearmetadata import ClearMetadataPreprocessor + from .base import PreprocessorTestsBase @@ -47,7 +48,7 @@ def test_default_output(self): nb, res = preprocessor(nb, res) assert not nb.cells[0].metadata - # By default we only perserve the langauge name + # By default we only preserve the language name assert nb.metadata == {"language_info": {"name": "python"}} def test_cell_only(self): diff --git a/nbconvert/preprocessors/tests/test_clearoutput.py b/tests/preprocessors/test_clearoutput.py similarity index 96% rename from nbconvert/preprocessors/tests/test_clearoutput.py rename to tests/preprocessors/test_clearoutput.py index 67455ca23..65ecd49e9 100644 --- a/nbconvert/preprocessors/tests/test_clearoutput.py +++ b/tests/preprocessors/test_clearoutput.py @@ -5,7 +5,8 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -from ..clearoutput import ClearOutputPreprocessor +from nbconvert.preprocessors.clearoutput import ClearOutputPreprocessor + from .base import PreprocessorTestsBase diff --git a/nbconvert/preprocessors/tests/test_coalescestreams.py b/tests/preprocessors/test_coalescestreams.py similarity index 97% rename from nbconvert/preprocessors/tests/test_coalescestreams.py rename to tests/preprocessors/test_coalescestreams.py index 917031006..ad899013d 100644 --- a/nbconvert/preprocessors/tests/test_coalescestreams.py +++ b/tests/preprocessors/test_coalescestreams.py @@ -5,7 +5,8 @@ from nbformat import v4 as nbformat -from ..coalescestreams import coalesce_streams +from nbconvert.preprocessors.coalescestreams import coalesce_streams + from .base import PreprocessorTestsBase diff --git a/nbconvert/preprocessors/tests/test_csshtmlheader.py b/tests/preprocessors/test_csshtmlheader.py similarity index 95% rename from nbconvert/preprocessors/tests/test_csshtmlheader.py rename to tests/preprocessors/test_csshtmlheader.py index aefbcb5f6..50de8c848 100644 --- a/nbconvert/preprocessors/tests/test_csshtmlheader.py +++ b/tests/preprocessors/test_csshtmlheader.py @@ -14,7 +14,8 @@ # Imports # ----------------------------------------------------------------------------- -from ..csshtmlheader import CSSHTMLHeaderPreprocessor +from nbconvert.preprocessors.csshtmlheader import CSSHTMLHeaderPreprocessor + from .base import PreprocessorTestsBase # ----------------------------------------------------------------------------- diff --git a/nbconvert/preprocessors/tests/test_execute.py b/tests/preprocessors/test_execute.py similarity index 98% rename from nbconvert/preprocessors/tests/test_execute.py rename to tests/preprocessors/test_execute.py index 2945fe84f..cf6f6ae8b 100644 --- a/nbconvert/preprocessors/tests/test_execute.py +++ b/tests/preprocessors/test_execute.py @@ -11,7 +11,7 @@ import nbformat import pytest -from ..execute import ExecutePreprocessor, executenb +from nbconvert.preprocessors.execute import ExecutePreprocessor, executenb addr_pat = re.compile(r"0x[0-9a-f]{7,9}") diff --git a/nbconvert/preprocessors/tests/test_extractattachments.py b/tests/preprocessors/test_extractattachments.py similarity index 97% rename from nbconvert/preprocessors/tests/test_extractattachments.py rename to tests/preprocessors/test_extractattachments.py index e709b9ef8..739b69199 100644 --- a/nbconvert/preprocessors/tests/test_extractattachments.py +++ b/tests/preprocessors/test_extractattachments.py @@ -6,7 +6,8 @@ import os from base64 import b64decode -from ..extractattachments import ExtractAttachmentsPreprocessor +from nbconvert.preprocessors.extractattachments import ExtractAttachmentsPreprocessor + from .base import PreprocessorTestsBase diff --git a/nbconvert/preprocessors/tests/test_extractoutput.py b/tests/preprocessors/test_extractoutput.py similarity index 97% rename from nbconvert/preprocessors/tests/test_extractoutput.py rename to tests/preprocessors/test_extractoutput.py index 4f83833b6..47578cd96 100644 --- a/nbconvert/preprocessors/tests/test_extractoutput.py +++ b/tests/preprocessors/test_extractoutput.py @@ -5,7 +5,8 @@ import json -from ..extractoutput import ExtractOutputPreprocessor +from nbconvert.preprocessors.extractoutput import ExtractOutputPreprocessor + from .base import PreprocessorTestsBase diff --git a/nbconvert/preprocessors/tests/test_highlightmagics.py b/tests/preprocessors/test_highlightmagics.py similarity index 95% rename from nbconvert/preprocessors/tests/test_highlightmagics.py rename to tests/preprocessors/test_highlightmagics.py index c807b0421..b4a5c05b2 100644 --- a/nbconvert/preprocessors/tests/test_highlightmagics.py +++ b/tests/preprocessors/test_highlightmagics.py @@ -1,6 +1,7 @@ """Tests for the HighlightMagics preprocessor""" -from ..highlightmagics import HighlightMagicsPreprocessor +from nbconvert.preprocessors.highlightmagics import HighlightMagicsPreprocessor + from .base import PreprocessorTestsBase diff --git a/nbconvert/preprocessors/tests/test_latex.py b/tests/preprocessors/test_latex.py similarity index 96% rename from nbconvert/preprocessors/tests/test_latex.py rename to tests/preprocessors/test_latex.py index ea4ecb7b8..f99de664f 100644 --- a/nbconvert/preprocessors/tests/test_latex.py +++ b/tests/preprocessors/test_latex.py @@ -3,7 +3,8 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -from ..latex import LatexPreprocessor +from nbconvert.preprocessors.latex import LatexPreprocessor + from .base import PreprocessorTestsBase diff --git a/nbconvert/preprocessors/tests/test_regexremove.py b/tests/preprocessors/test_regexremove.py similarity index 97% rename from nbconvert/preprocessors/tests/test_regexremove.py rename to tests/preprocessors/test_regexremove.py index 1281ba623..a4636ff23 100644 --- a/nbconvert/preprocessors/tests/test_regexremove.py +++ b/tests/preprocessors/test_regexremove.py @@ -9,7 +9,8 @@ from nbformat import v4 as nbformat -from ..regexremove import RegexRemovePreprocessor +from nbconvert.preprocessors.regexremove import RegexRemovePreprocessor + from .base import PreprocessorTestsBase diff --git a/nbconvert/preprocessors/tests/test_sanitize.py b/tests/preprocessors/test_sanitize.py similarity index 99% rename from nbconvert/preprocessors/tests/test_sanitize.py rename to tests/preprocessors/test_sanitize.py index cfbeb2a7c..9ee8917f9 100644 --- a/nbconvert/preprocessors/tests/test_sanitize.py +++ b/tests/preprocessors/test_sanitize.py @@ -2,7 +2,8 @@ from nbformat import v4 as nbformat -from ..sanitize import SanitizeHTML +from nbconvert.preprocessors.sanitize import SanitizeHTML + from .base import PreprocessorTestsBase diff --git a/nbconvert/preprocessors/tests/test_svg2pdf.py b/tests/preprocessors/test_svg2pdf.py similarity index 96% rename from nbconvert/preprocessors/tests/test_svg2pdf.py rename to tests/preprocessors/test_svg2pdf.py index 988fa35c2..9858e04b1 100644 --- a/nbconvert/preprocessors/tests/test_svg2pdf.py +++ b/tests/preprocessors/test_svg2pdf.py @@ -7,8 +7,9 @@ from nbformat import v4 as nbformat -from ...tests.utils import onlyif_cmds_exist -from ..svg2pdf import SVG2PDFPreprocessor +from nbconvert.preprocessors.svg2pdf import SVG2PDFPreprocessor +from tests.testutils import onlyif_cmds_exist + from .base import PreprocessorTestsBase diff --git a/nbconvert/preprocessors/tests/test_tagremove.py b/tests/preprocessors/test_tagremove.py similarity index 95% rename from nbconvert/preprocessors/tests/test_tagremove.py rename to tests/preprocessors/test_tagremove.py index 610205fb4..7df8df86d 100644 --- a/nbconvert/preprocessors/tests/test_tagremove.py +++ b/tests/preprocessors/test_tagremove.py @@ -7,8 +7,8 @@ from nbformat import v4 as nbformat -from ..tagremove import TagRemovePreprocessor -from .base import PreprocessorTestsBase +from nbconvert.preprocessors.tagremove import TagRemovePreprocessor +from tests.preprocessors.base import PreprocessorTestsBase class TestTagRemove(PreprocessorTestsBase): diff --git a/nbconvert/tests/test_nbconvertapp.py b/tests/test_nbconvertapp.py similarity index 98% rename from nbconvert/tests/test_nbconvertapp.py rename to tests/test_nbconvertapp.py index 8d83caa9b..1bd434bc4 100644 --- a/nbconvert/tests/test_nbconvertapp.py +++ b/tests/test_nbconvertapp.py @@ -13,10 +13,10 @@ from nbconvert.exporters import HTMLExporter from nbconvert.exporters.webpdf import PLAYWRIGHT_INSTALLED +from nbconvert.postprocessors import PostProcessorBase -from ..postprocessors import PostProcessorBase -from ..tests.utils import onlyif_cmds_exist from .base import TestsBase +from .testutils import onlyif_cmds_exist # ----------------------------------------------------------------------------- # Classes and functions @@ -78,7 +78,7 @@ def test_convert_full_qualified_name(self): with self.create_temp_cwd(): self.copy_files_to(["notebook*.ipynb"], "subdir") self.nbconvert( - "--to nbconvert.tests.fake_exporters.MyExporter --log-level 0 " + "--to tests.fake_exporters.MyExporter --log-level 0 " + os.path.join("subdir", "*.ipynb") ) assert os.path.isfile(os.path.join("subdir", "notebook1.test_ext")) @@ -97,7 +97,7 @@ def test_clear_output(self): """ Can we clear outputs? """ - with self.create_temp_cwd(["notebook*.ipynb"]) as td: + with self.create_temp_cwd(["notebook*.ipynb"]): self.nbconvert("--clear-output notebook1") assert os.path.isfile("notebook1.ipynb") with open("notebook1.ipynb", encoding="utf8") as f: @@ -178,7 +178,7 @@ def test_post_processor(self): """Do post processors work?""" with self.create_temp_cwd(["notebook1.ipynb"]): out, err = self.nbconvert( - "--log-level 0 --to python notebook1 --post nbconvert.tests.test_nbconvertapp.DummyPost" + "--log-level 0 --to python notebook1 --post tests.test_nbconvertapp.DummyPost" ) self.assertIn("Dummy:notebook1.py", out) diff --git a/nbconvert/tests/utils.py b/tests/testutils.py similarity index 100% rename from nbconvert/tests/utils.py rename to tests/testutils.py diff --git a/nbconvert/utils/tests/__init__.py b/tests/utils/__init__.py similarity index 100% rename from nbconvert/utils/tests/__init__.py rename to tests/utils/__init__.py diff --git a/nbconvert/utils/tests/test_io.py b/tests/utils/test_io.py similarity index 95% rename from nbconvert/utils/tests/test_io.py rename to tests/utils/test_io.py index ce16c1a51..d90840041 100644 --- a/nbconvert/utils/tests/test_io.py +++ b/tests/utils/test_io.py @@ -7,7 +7,7 @@ import sys from io import StringIO -from ..io import unicode_std_stream +from nbconvert.utils.io import unicode_std_stream def test_UnicodeStdStream(): diff --git a/nbconvert/utils/tests/test_pandoc.py b/tests/utils/test_pandoc.py similarity index 94% rename from nbconvert/utils/tests/test_pandoc.py rename to tests/utils/test_pandoc.py index 2dd07a782..49a40881d 100644 --- a/nbconvert/utils/tests/test_pandoc.py +++ b/tests/utils/test_pandoc.py @@ -12,10 +12,9 @@ import os import warnings -from nbconvert.tests.base import TestsBase - -from ...tests.utils import onlyif_cmds_exist -from .. import pandoc +from nbconvert.utils import pandoc +from tests.base import TestsBase +from tests.testutils import onlyif_cmds_exist # ----------------------------------------------------------------------------- # Classes and functions @@ -56,8 +55,6 @@ def test_pandoc_available(self): @onlyif_cmds_exist("pandoc") def test_minimal_version(self): - original_minversion = pandoc._minimal_version - pandoc._minimal_version = "120.0" with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") diff --git a/nbconvert/utils/tests/test_version.py b/tests/utils/test_version.py similarity index 78% rename from nbconvert/utils/tests/test_version.py rename to tests/utils/test_version.py index 159e3f3f1..52d3f26ab 100644 --- a/nbconvert/utils/tests/test_version.py +++ b/tests/utils/test_version.py @@ -1,8 +1,8 @@ -from ..version import check_version +from nbconvert.utils.version import check_version def test_check_version(): - """Test the behaviour of check_versionself. + """Test the behaviour of check_version. This is mostly used to make sure the pandoc version is appropriate for the library. """ diff --git a/nbconvert/writers/tests/__init__.py b/tests/writers/__init__.py similarity index 100% rename from nbconvert/writers/tests/__init__.py rename to tests/writers/__init__.py diff --git a/nbconvert/writers/tests/test_debug.py b/tests/writers/test_debug.py similarity index 94% rename from nbconvert/writers/tests/test_debug.py rename to tests/writers/test_debug.py index fba58d3b0..2080281d4 100644 --- a/nbconvert/writers/tests/test_debug.py +++ b/tests/writers/test_debug.py @@ -17,8 +17,8 @@ import sys from io import StringIO -from ...tests.base import TestsBase -from ..debug import DebugWriter +from nbconvert.writers.debug import DebugWriter +from tests.base import TestsBase # ----------------------------------------------------------------------------- # Class diff --git a/nbconvert/writers/tests/test_files.py b/tests/writers/test_files.py similarity index 98% rename from nbconvert/writers/tests/test_files.py rename to tests/writers/test_files.py index bca0e59b3..d9a797acf 100644 --- a/nbconvert/writers/tests/test_files.py +++ b/tests/writers/test_files.py @@ -7,8 +7,8 @@ import os -from ...tests.base import TestsBase -from ..files import FilesWriter +from nbconvert.writers.files import FilesWriter +from tests.base import TestsBase class Testfiles(TestsBase): @@ -36,7 +36,7 @@ def test_ext(self): # Work in a temporary directory. with self.create_temp_cwd(): - # Create the resoruces dictionary + # Create the resources dictionary res = {"output_extension": ".txt"} # Create files writer, test output @@ -168,7 +168,7 @@ def test_glob(self): with open(os.path.join("sub", "d"), "w") as f: f.write("e") - # Create the resoruces dictionary + # Create the resources dictionary res: dict = {} # Create files writer, test output diff --git a/nbconvert/writers/tests/test_stdout.py b/tests/writers/test_stdout.py similarity index 93% rename from nbconvert/writers/tests/test_stdout.py rename to tests/writers/test_stdout.py index f1535296b..ded010452 100644 --- a/nbconvert/writers/tests/test_stdout.py +++ b/tests/writers/test_stdout.py @@ -17,8 +17,8 @@ import sys from io import StringIO -from ...tests.base import TestsBase -from ..stdout import StdoutWriter +from nbconvert.writers.stdout import StdoutWriter +from tests.base import TestsBase # ----------------------------------------------------------------------------- # Class