Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬆️ UPGRADE: Upgrade to support sphinx4, remove support for sphinx2 #356

Merged
merged 7 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 5 additions & 1 deletion tests/test_glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
169 changes: 169 additions & 0 deletions tests/test_glue/test_parser.sphinx4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<document source="with_glue">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we now expect a new one of these files for every major version of Sphinx that we support?

Copy link
Member Author

@mmcky mmcky Aug 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@choldgraf the sphinx3 is the same as the old fixture file. There is a minor difference in what sphinx includes in the xml "align='default'" is no longer specified in sphinx4

<section classes="tex2jax_ignore mathjax_ignore" ids="glue-tests" names="glue\ tests">
<title>
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)
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
Expand Down