From da92512adb8e8d8e276fd627188651be71383480 Mon Sep 17 00:00:00 2001 From: Connor Ferster Date: Thu, 27 Jun 2024 13:57:54 -0700 Subject: [PATCH 1/5] chores: remove nbconvert dependencies - remove built-in exporter from handcalcs - add it as an optional install dependency --- handcalcs/exporters.py | 47 ------------------------------------------ pyproject.toml | 16 +++++++------- 2 files changed, 8 insertions(+), 55 deletions(-) delete mode 100644 handcalcs/exporters.py diff --git a/handcalcs/exporters.py b/handcalcs/exporters.py deleted file mode 100644 index 5452727..0000000 --- a/handcalcs/exporters.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2020 Connor Ferster - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from nbconvert import PDFExporter, HTMLExporter, LatexExporter -from copy import deepcopy - - -class HTMLHideInputExporter(HTMLExporter): - """ - Exports HTML documents without input cells. - """ - - export_from_notebook = "HTML Hide Input" - - exclude_input = deepcopy(HTMLExporter.exclude_input) - exclude_input.default_value = True - - -class PDFHideInputExporter(PDFExporter): - """ - Exports PDF documents without input cells. - """ - - export_from_notebook = "PDF Hide Input" - exclude_input = deepcopy(PDFExporter.exclude_input) - exclude_input.default_value = True - - -class LatexHideInputExporter(LatexExporter): - """ - Exports LaTeX documents without input cells. - """ - - export_from_notebook = "LaTeX Hide Input" - exclude_input = deepcopy(LatexExporter.exclude_input) - exclude_input.default_value = True diff --git a/pyproject.toml b/pyproject.toml index 13619ca..a06e70a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,6 @@ classifiers = ["License :: OSI Approved :: Apache Software License"] dynamic = ["version", "description"] dependencies = [ "more_itertools", - "nbconvert >= 7.0.0", "innerscope >= 0.7.0", "pyparsing" ] @@ -22,27 +21,28 @@ Source = "https://github.com/connorferster/handcalcs" [project.optional-dependencies] +exporters = [ + "nb-hideinputs", +] + test = [ "pytest >= 8.0.0", "pytest-cov >= 4.1.0", "coverage[toml] >= 5.5.0", "pint >= 0.23", + "sympy", ] dev = [ "jupyterlab >= 4.0.0", - "sympy", "forallpeople >= 2.0", - "black" + "black", + "pint >= 0.23", + "sympy", ] doc = ["sphinx"] -[project.entry-points."nbconvert.exporters"] -HTML_NoInput = 'handcalcs.exporters:HTMLHideInputExporter' -PDF_NoInput = 'handcalcs.exporters:PDFHideInputExporter' -LaTeX_NoInput = 'handcalcs.exporters:LatexHideInputExporter' - [tool.coverage.paths] source = ['handcalcs', '*/site-packages'] From 9ce45db877d980c7c0502a10cc1afd4a818bd450 Mon Sep 17 00:00:00 2001 From: Connor Ferster Date: Thu, 27 Jun 2024 14:00:48 -0700 Subject: [PATCH 2/5] chore: remove exporter tests --- test_handcalcs/test_handcalcs_file.py | 33 --------------------------- 1 file changed, 33 deletions(-) diff --git a/test_handcalcs/test_handcalcs_file.py b/test_handcalcs/test_handcalcs_file.py index da855eb..decd3b1 100644 --- a/test_handcalcs/test_handcalcs_file.py +++ b/test_handcalcs/test_handcalcs_file.py @@ -16,17 +16,8 @@ import inspect from collections import deque -from handcalcs.exporters import ( - LatexHideInputExporter, - HTMLHideInputExporter, - PDFHideInputExporter, -) - import handcalcs -import pathlib import pytest -import nbconvert -import filecmp import forallpeople as si @@ -353,30 +344,6 @@ def test_handcalcs3(): assert func_3(4, 5) == {"x": 4, "y": 5, "a": 8, "b": 29} -# Test template.py - - -def test_latex_exporter(): - exporter = LatexHideInputExporter() - assert exporter.exclude_input == True - parent = exporter.__class__.__bases__[0]() - assert parent.exclude_input == False - - -def test_pdf_exporter(): - exporter = PDFHideInputExporter() - assert exporter.exclude_input == True - parent = exporter.__class__.__bases__[0]() - assert parent.exclude_input == False - - -def test_html_exporter(): - exporter = HTMLHideInputExporter() - assert exporter.exclude_input == True - parent = exporter.__class__.__bases__[0]() - assert parent.exclude_input == False - - # Test expected exceptions From c66f89b9e719dc44fdd027e995e284f9caba7206 Mon Sep 17 00:00:00 2001 From: Connor Ferster Date: Thu, 27 Jun 2024 14:51:44 -0700 Subject: [PATCH 3/5] chore: update README.md to explain installation of exporters --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 5acbeda..39c1f36 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,14 @@ You can install using pip: `pip install handcalcs` +To install the optional nbconvert "no input" exporters, use: + +`pip install "handcalcs[exporters]"` + +**NEW** + +As of v1.9.0, handcalcs no longer installs the "no input" nbconvert exporters. This was done to lighten the installation load of handcalcs and to ensure the package has appropriate scope. The nbconvert exporters are now "out of scope" and are separately maintained at [https://github.com/connorferster/nb-hideinputs](nb-hideinputs). + ## Basic Usage 1: As a Jupyter cell magic (`%%render`) `handcalcs` is intended to be used with either Jupyter Notebook or Jupyter Lab as a _cell magic_. From 192de798ad3528d3186bd710413a5429bfe0e996 Mon Sep 17 00:00:00 2001 From: Connor Ferster Date: Thu, 27 Jun 2024 14:53:13 -0700 Subject: [PATCH 4/5] chore: removed unused imports from test_sympy_kit.py --- test_handcalcs/test_sympy_kit.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test_handcalcs/test_sympy_kit.py b/test_handcalcs/test_sympy_kit.py index a2fe0ac..325b266 100644 --- a/test_handcalcs/test_sympy_kit.py +++ b/test_handcalcs/test_sympy_kit.py @@ -1,12 +1,7 @@ -import inspect -from collections import deque from handcalcs.handcalcs import CalcLine, round_and_render_line_objects_to_latex import handcalcs.sympy_kit as sk import handcalcs.global_config -import pathlib import pytest -import nbconvert -import filecmp import sympy as sp a, b = sp.symbols("a b") From 366e3ce377a21ef3527ae27c433d7b3b4f1d910a Mon Sep 17 00:00:00 2001 From: Connor Ferster Date: Thu, 27 Jun 2024 14:54:05 -0700 Subject: [PATCH 5/5] chore: remove unused imports from test_render_file.py --- test_handcalcs/test_render_file.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test_handcalcs/test_render_file.py b/test_handcalcs/test_render_file.py index e8d9407..22b2190 100644 --- a/test_handcalcs/test_render_file.py +++ b/test_handcalcs/test_render_file.py @@ -1,15 +1,8 @@ -import inspect -from collections import deque import handcalcs -import pathlib import pytest -import nbconvert -import filecmp from IPython.testing.globalipapp import start_ipython -from IPython.utils.io import capture_output -from IPython.display import Latex @pytest.fixture(scope="session")