diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3eb1ce80..b34018a1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,14 +27,14 @@ jobs: matrix: os: [ubuntu-latest] python-version: [3.6, 3.7, 3.8, 3.9] - sphinx: [">=3,<4"] + sphinx: [">=3,<4", ">=4,<5"] include: - - os: ubuntu-latest - python-version: 3.8 - sphinx: ">=2,<3" - os: windows-latest python-version: 3.7 sphinx: ">=3,<4" + - os: macos-latest + python-version: 3.9 + sphinx: ">=4,<5" runs-on: ${{ matrix.os }} diff --git a/setup.cfg b/setup.cfg index 02997266..dfaeb482 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,7 +38,7 @@ project_urls = [options] packages = find: install_requires = - docutils>=0.15 + docutils>=0.15,<0.18 importlib_metadata ipython ipywidgets>=7.0.0,<8 @@ -48,7 +48,7 @@ install_requires = nbconvert>=5.6,<7 nbformat~=5.0 pyyaml - sphinx>=2,<4 + sphinx>=3.1,<5 sphinx-togglebutton~=0.2.2 python_requires = >=3.6 include_package_data = True diff --git a/tests/conftest.py b/tests/conftest.py index 9147190f..12e8353b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,6 +5,7 @@ import nbformat as nbf import pytest +import sphinx from docutils.nodes import image as image_node from nbconvert.filters import strip_ansi from nbdime.diffing.notebooks import ( @@ -60,6 +61,9 @@ def __init__(self, app, filenames): self.app = app self.env = app.env self.files = [os.path.splitext(ff) for ff in filenames] + self.software_versions = ( + f".sphinx{sphinx.version_info[0]}" # software version tracking for fixtures + ) # self.nb_file = nb_file # self.nb_name = os.path.splitext(nb_file)[0] diff --git a/tests/test_glue.py b/tests/test_glue.py index 96935e3a..ffd7fbf5 100644 --- a/tests/test_glue.py +++ b/tests/test_glue.py @@ -110,7 +110,11 @@ def test_parser(sphinx_run, clean_doctree, file_regression): # print(sphinx_run.status()) assert sphinx_run.warnings() == "" doctree = clean_doctree(sphinx_run.get_resolved_doctree("with_glue")) - file_regression.check(doctree.pformat(), extension=".xml", encoding="utf8") + file_regression.check( + doctree.pformat(), + extension=f"{sphinx_run.software_versions}.xml", + encoding="utf8", + ) glue_domain = NbGlueDomain.from_env(sphinx_run.app.env) assert set(glue_domain.cache) == { "key_text1", diff --git a/tests/test_glue/test_parser.xml b/tests/test_glue/test_parser.sphinx3.xml similarity index 100% rename from tests/test_glue/test_parser.xml rename to tests/test_glue/test_parser.sphinx3.xml diff --git a/tests/test_glue/test_parser.sphinx4.xml b/tests/test_glue/test_parser.sphinx4.xml new file mode 100644 index 00000000..eff7afc6 --- /dev/null +++ b/tests/test_glue/test_parser.sphinx4.xml @@ -0,0 +1,169 @@ + +
+ + Glue Tests + <CellNode cell_type="code" classes="cell"> + <CellInputNode classes="cell_input"> + <literal_block language="ipython3" linenos="False" xml:space="preserve"> + from myst_nb import glue + <CellNode cell_type="code" classes="cell"> + <CellInputNode classes="cell_input"> + <literal_block language="ipython3" linenos="False" xml:space="preserve"> + glue("key_text1", "text1") + glue("key_float", 3.14159) + <CellOutputNode classes="cell_output"> + <literal_block classes="output text_plain" language="myst-ansi" linenos="False" xml:space="preserve"> + 'text1' + <literal_block classes="output text_plain" language="myst-ansi" linenos="False" xml:space="preserve"> + 3.14159 + <CellNode cell_type="code" classes="cell"> + <CellInputNode classes="cell_input"> + <literal_block language="ipython3" linenos="False" xml:space="preserve"> + glue("key_undisplayed", "undisplayed", display=False) + <CellOutputNode classes="cell_output"> + <CellNode cell_type="code" classes="cell"> + <CellInputNode classes="cell_input"> + <literal_block language="ipython3" linenos="False" xml:space="preserve"> + import pandas as pd + df = pd.DataFrame({"header": [1, 2, 3]}) + glue("key_df", df) + <CellOutputNode classes="cell_output"> + <raw classes="output text_html" format="html" xml:space="preserve"> + <div> + <style scoped> + .dataframe tbody tr th:only-of-type { + vertical-align: middle; + } + + .dataframe tbody tr th { + vertical-align: top; + } + + .dataframe thead th { + text-align: right; + } + </style> + <table border="1" class="dataframe"> + <thead> + <tr style="text-align: right;"> + <th></th> + <th>header</th> + </tr> + </thead> + <tbody> + <tr> + <th>0</th> + <td>1</td> + </tr> + <tr> + <th>1</th> + <td>2</td> + </tr> + <tr> + <th>2</th> + <td>3</td> + </tr> + </tbody> + </table> + </div> + <CellNode cell_type="code" classes="cell"> + <CellInputNode classes="cell_input"> + <literal_block language="ipython3" linenos="False" xml:space="preserve"> + import matplotlib.pyplot as plt + plt.plot([1, 2, 3]) + glue("key_plt", plt.gcf(), display=False) + <CellOutputNode classes="cell_output"> + <image candidates="{'*': '_build/jupyter_execute/with_glue_5_1.png'}" uri="_build/jupyter_execute/with_glue_5_1.png"> + <section ids="referencing-the-figs" names="referencing\ the\ figs"> + <title> + Referencing the figs + <paragraph> + <inline classes="pasted-inline"> + <literal classes="output text_plain" language="none"> + 'text1' + , + <inline classes="pasted-inline"> + <image candidates="{'*': '_build/jupyter_execute/with_glue_5_0.png'}" uri="_build/jupyter_execute/with_glue_5_0.png"> + <CellOutputNode classes="cell_output"> + <raw classes="output text_html" format="html" xml:space="preserve"> + <div> + <style scoped> + .dataframe tbody tr th:only-of-type { + vertical-align: middle; + } + + .dataframe tbody tr th { + vertical-align: top; + } + + .dataframe thead th { + text-align: right; + } + </style> + <table border="1" class="dataframe"> + <thead> + <tr style="text-align: right;"> + <th></th> + <th>header</th> + </tr> + </thead> + <tbody> + <tr> + <th>0</th> + <td>1</td> + </tr> + <tr> + <th>1</th> + <td>2</td> + </tr> + <tr> + <th>2</th> + <td>3</td> + </tr> + </tbody> + </table> + </div> + <paragraph> + and + <inline classes="pasted-text"> + text1 + inline… + <paragraph> + and formatted + <inline classes="pasted-text"> + 3.14 + <CellOutputNode classes="cell_output"> + <image candidates="{'*': '_build/jupyter_execute/with_glue_5_0.png'}" uri="_build/jupyter_execute/with_glue_5_0.png"> + <paragraph> + and + <inline classes="pasted-text"> + undisplayed + inline… + <figure ids="abc" names="abc"> + <CellOutputNode classes="cell_output"> + <image candidates="{'*': '_build/jupyter_execute/with_glue_5_0.png'}" uri="_build/jupyter_execute/with_glue_5_0.png"> + <caption> + A caption…. + + ```## A test title + <inline classes="pasted-inline"> + <literal classes="output text_plain" language="none"> + 'text1' + <section ids="math" names="math"> + <title> + Math + <CellNode cell_type="code" classes="cell"> + <CellInputNode classes="cell_input"> + <literal_block language="ipython3" linenos="False" xml:space="preserve"> + import sympy as sym + f = sym.Function('f') + y = sym.Function('y') + n = sym.symbols(r'\alpha') + f = y(n)-2*y(n-1/sym.pi)-5*y(n-2) + glue("sym_eq", sym.rsolve(f,y(n),[1,4])) + <CellOutputNode classes="cell_output"> + <math_block classes="output text_latex" nowrap="False" number="True" xml:space="preserve"> + \displaystyle \left(\sqrt{5} i\right)^{\alpha} \left(\frac{1}{2} - \frac{2 \sqrt{5} i}{5}\right) + \left(- \sqrt{5} i\right)^{\alpha} \left(\frac{1}{2} + \frac{2 \sqrt{5} i}{5}\right) + <target refid="equation-eq-sym"> + <math_block classes="pasted-math" docname="with_glue" ids="equation-eq-sym" label="eq-sym" nowrap="False" number="1" xml:space="preserve"> + \displaystyle \left(\sqrt{5} i\right)^{\alpha} \left(\frac{1}{2} - \frac{2 \sqrt{5} i}{5}\right) + \left(- \sqrt{5} i\right)^{\alpha} \left(\frac{1}{2} + \frac{2 \sqrt{5} i}{5}\right) diff --git a/tox.ini b/tox.ini index 152376ae..fa70650b 100644 --- a/tox.ini +++ b/tox.ini @@ -13,11 +13,11 @@ [tox] envlist = py37-sphinx3 -[testenv:py{36,37,38,39}-sphinx{2,3}] +[testenv:py{36,37,38,39}-sphinx{3,4}] extras = testing deps = - sphinx2: sphinx>=2,<3 sphinx3: sphinx>=3,<4 + sphinx4: sphinx>=4,<5 commands = pytest {posargs} [testenv:docs-{update,clean}]