Skip to content
Open
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
51 changes: 12 additions & 39 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.10", "3.11", "3.12", "3.13"]
sphinx: ["~=8.0"] # temporary limit, bring it back to newest sphinx once we are sphinx9 compatible
python-version: ["3.11", "3.12", "3.13", "3.14"]
sphinx: [""] # Newest Sphinx
myst-parser: [""] # Newest MyST Parser (any)
include:
# Just check the other platforms once
Expand All @@ -39,6 +39,12 @@ jobs:
sphinx: "~=8.0"
myst-parser: "~=4.0"
pillow: "==11.0.0"
# Oldest known-compatible dependencies
- os: ubuntu-latest
python-version: "3.10"
sphinx: "==5.0.0"
myst-parser: "==1.0.0"
pillow: "==11.0.0"
# Mid-range dependencies
- os: ubuntu-latest
python-version: "3.11"
Expand All @@ -47,9 +53,9 @@ jobs:
pillow: "==11.0.0"
# Newest known-compatible dependencies
- os: ubuntu-latest
python-version: "3.13"
sphinx: "~=8.0"
myst-parser: "==4.0.0"
python-version: "3.14"
sphinx: "~=9.0"
myst-parser: "~=5.0"
pillow: "==11.0.0"

runs-on: ${{ matrix.os }}
Expand All @@ -71,42 +77,9 @@ jobs:
- name: Run pytest
run: pytest --durations=10

coverage:
needs: [tests]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: "3.11"
cache: pip
- name: Install dependencies
run: |
pip install -e .[testing]
pip freeze

- name: Run pytest
run: pytest --durations=10 --cov=myst_nb --cov-report=xml --cov-report=term-missing

- name: Create cov
run: coverage xml
# for some reason the tests/conftest.py::check_nbs fixture breaks pytest-cov's cov-report outputting
# this is why we run `coverage xml` afterwards (required by codecov)

# TEMPORARY FIX: Disable codecov until we can get it working again
- name: Upload to Codecov
uses: codecov/codecov-action@v5
if: false
with:
name: myst-nb-pytests
flags: pytests
files: ./coverage.xml

publish:

name: Publish to PyPi
name: Publish to PyPI
needs: [tests]
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
runs-on: ubuntu-latest
Expand Down
13 changes: 4 additions & 9 deletions myst_nb/sphinx_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from importlib import resources as import_resources
import os
from pathlib import Path
import sys
from types import ModuleType
from typing import Any, Iterator, cast

Expand Down Expand Up @@ -194,14 +193,10 @@ def _get_file_hash(path: Path):

@contextlib.contextmanager
def _import_resources_path(package: ModuleType, resource: str) -> Iterator[Path]:
if sys.version_info < (3, 9):
with import_resources.path(package, resource) as path:
yield path
else:
with import_resources.as_file(
import_resources.files(package).joinpath(resource)
) as path:
yield path
with import_resources.as_file(
import_resources.files(package).joinpath(resource)
) as path:
yield path


def add_css(app: Sphinx):
Expand Down
11 changes: 7 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[build-system]
[build-system]
requires = ["flit_core >=3.11,<4"]
build-backend = "flit_core.buildapi"

Expand All @@ -20,6 +20,7 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Libraries :: Python Modules",
Expand All @@ -42,7 +43,7 @@ dependencies = [
"myst-parser>=1.0.0",
"nbformat>=5.0",
"pyyaml",
"sphinx>=5,<9", # If we get bugs for older versions, just pin this higher
"sphinx>=5", # If we get bugs for older versions, just pin this higher
"typing-extensions",
# ipykernel is not a requirement of the library,
# but is a common requirement for users (registers the python3 kernel)
Expand Down Expand Up @@ -174,12 +175,14 @@ filterwarnings = [
'ignore:datetime.datetime.utcnow\(\) is deprecated:DeprecationWarning:jupyter_cache',
# From matplotlib’s dependencies
'ignore::DeprecationWarning:pyparsing', # imports deprecated `sre_constants`
# From myst-parser on Sphinx 9
'ignore:.*MystReferenceResolver.app.*:DeprecationWarning',
# From myst-parser on Sphinx 9 we hit RemovedInSphinx11Warning
'ignore:.*MystReferenceResolver.app.*',
# Upstream myst-parser still hits env.app deprecations under Sphinx 9
'ignore:.*env\\.app.*:DeprecationWarning:myst_parser',
# Windows issues, some may need to be fixed in MyST-NB, others are upstream
'ignore:Proactor event loop does not implement add_reader:RuntimeWarning:zmq',
# We deal with this pending deprecation later
'ignore:Argument "writer_name" will be removed in Docutils 2.0:PendingDeprecationWarning'
]

markers = [
Expand Down
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from nbdime.prettyprint import pretty_print_diff
import nbformat as nbf
import pytest
import docutils
import sphinx
from sphinx import version_info as sphinx_version_info
from sphinx.util.console import nocolor
Expand Down Expand Up @@ -304,6 +305,7 @@ class FileRegression:
r"original_uri=\"[^\"]*\"\s",
# TODO: Remove when support for Sphinx<8 is dropped,
re.escape(' translated="True"'),
re.escape(' translated="1"'),
re.escape(" translation_progress=\"{'total': 4, 'translated': 2}\""),
)

Expand All @@ -316,4 +318,10 @@ def check(self, data, **kwargs):
def _strip_ignores(self, data):
for ig in self.ignores:
data = re.sub(ig, "", data)

if docutils.__version_info__ < (0, 22):
data = data.replace('linenos="False"', 'linenos="0"')
data = data.replace('nowrap="False"', 'nowrap="0"')
data = data.replace('linenos="True"', 'linenos="1"')
data = data.replace('internal="True"', 'internal="1"')
return data
6 changes: 3 additions & 3 deletions tests/test_eval/test_sphinx.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
Inline evaluation
<container cell_index="1" cell_metadata="{}" classes="cell" exec_count="1" nb_element="cell_code">
<container classes="cell_input" nb_element="cell_code_source">
<literal_block language="ipython3" linenos="False" xml:space="preserve">
<literal_block language="ipython3" linenos="0" xml:space="preserve">
a = 1
<paragraph>
Evaluated inline variable:
<inline classes="output text_plain">
1
<literal_block classes="output text_plain" language="myst-ansi" linenos="False" xml:space="preserve">
<literal_block classes="output text_plain" language="myst-ansi" linenos="0" xml:space="preserve">
1
<container cell_index="3" cell_metadata="{}" classes="cell" exec_count="2" nb_element="cell_code">
<container classes="cell_input" nb_element="cell_code_source">
<literal_block language="ipython3" linenos="False" xml:space="preserve">
<literal_block language="ipython3" linenos="0" xml:space="preserve">
import base64
from IPython.display import Image
string = "iVBORw0KGgoAAAANSUhEUgAAAHQAAAB0CAYAAABUmhYnAAAEd0lEQVR4Xu2c0ZLjIAwEk///6GzVvZlspWtWksNRnVcwiGmNwHaS5+v1ej38HKPAU6DHsPy3EIGexVOgh/EUqEBPU+Cw9biHCvQwBQ5bjg4V6GEKHLYcHSrQwxQ4bDk6VKCHKXDYcnSoQA9T4LDllB36fD5vlWR9fUvz0+ve9fp0/O7FU7w0n0CXhBSoDiXTRO06FBKKBLLkLvlGgkTp+UvndPzu/ul46Xq7x2/fQ8kR0wtOBaL+1J6uZ+3fPb5Aw0PRtxOWEkigAr3mCJUMuk9cM45uG3ZvJwel8dN4byW8+r1cgWYPVgRaLIlpwqWCT1cgHbr8skOgYUqkgtHwVYfQKZTiTW8rdCgQFWjtt2Pjty3TGdztOB0aHlosuVcHpglJ+h3nUFow7bE6dDOHCjRN2fBty917qEAF+jEHaI+bTlhK0Nsf/aUBpXtYdXy6noDS9dTePf74oYgWRO3dC6b57k6o7vUJFAh3Cz6dMAIV6FWB9FCQlry1f/ejQXLgt9eX6tXu0DSAtL9APysm0OYHI2mCUgVKxxOoQNOcubc/7XnF5yj3LuYPs5Ud+oc5Ry8R6GEpK1CBjlaMuwcvl1xyBC2I8im9T0xva6pPbtL1V+MjPQW6KEQJRAlAggs0vK2oCibQ4g9+LbnXb96THlQBvl5y0yclqYNQAKgAVGIJQHWPpfjf4uv+bUsagECvClCCkL46VIdecyQtKZRhlKGW3OG3LekeQ0DSBOk+1VLCdbdTAqfzlUuuQFPJe/fM9kORQAV6UYBKJslF11NJS0s8xZO2U3zpeO0lNw2g2+HV8dLbKJov1aMKWKDFfyITKKRsegqmjE7H06FpTRHoRwUoQUnu9pJLh4z0EFMdjwRI46ESWwVC8VK7QMN/TRHookDqCB1Knry261AdmmXMdG86xabzd49H83fP1+5QWkB3e7sg4eu06nra46++4K4uqHp9uyACrSKpXS/Q5kMRnUJruN6vnr7Po/VMn9KrepX3UBKgGmD1UVw6P61HoKmi0F+HfhZIhy766NDhU2F66CEgzQXjQRUjjb8aX7tDaYFpwKkgAi0SSAUXaO0Pjkk/HUoKFQ9p0wm/hjcONC2B6W3B24KKv1ZLx0vzgfQoFsyHQJe3LQINHUEZrUNre6wO1aHLw+AvO5QOHdReLbE0/vSeedyhKBWUDh00XpoAAg2/EkIAqD0FlPYXqEDp3Pix/b8/FKUOIMem7fR6j8Yr0fvlYoEWK4JAw0dplOE6dLnrqH5JrCp4NcMFejPQ6h7RnTAUT/eTKkpYiidtH99D04C6bwvS+QX65W8sUMkVaKgAlcRwuLfuNL5Ah/fQKkC6Pi2JKXB6NEjxUTslKF1P7e17KE1YbRfoZwUFuuijQ4v/l5s6VocOOzQFYv9ZBcoldzY8R08VEGiq2Ob9Bbo5oDQ8gaaKbd5foJsDSsMTaKrY5v0FujmgNDyBpopt3l+gmwNKwxNoqtjm/QW6OaA0PIGmim3eX6CbA0rDE2iq2Ob9Bbo5oDS8H8eCMw7yCzx+AAAAAElFTkSuQmCC"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_execute/test_complex_outputs_unrun_auto.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
<literal_block classes="output text_plain" language="myst-ansi" xml:space="preserve">
<IPython.core.display.Latex object>
<container mime_type="text/latex">
<math_block classes="output text_latex" nowrap="False" number="True" xml:space="preserve">
<math_block classes="output text_latex" nowrap="0" number="True" xml:space="preserve">
a = b+c
<paragraph>
The plotting code for a sympy equation (=@eqn:example_sympy).
Expand All @@ -216,7 +216,7 @@
<container mime_type="image/png">
<image candidates="{'*': '_build/jupyter_execute/e2dfbe330154316cfb6f3186e8f57fc4df8aee03b0303ed1345fc22cd51f66de.png'}" uri="_build/jupyter_execute/e2dfbe330154316cfb6f3186e8f57fc4df8aee03b0303ed1345fc22cd51f66de.png">
<container mime_type="text/latex">
<math_block classes="output text_latex" nowrap="False" number="True" xml:space="preserve">
<math_block classes="output text_latex" nowrap="0" 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)
<section ids="interactive-outputs" names="interactive\ outputs">
<title>
Expand Down
4 changes: 2 additions & 2 deletions tests/test_execute/test_complex_outputs_unrun_cache.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
<literal_block classes="output text_plain" language="myst-ansi" xml:space="preserve">
<IPython.core.display.Latex object>
<container mime_type="text/latex">
<math_block classes="output text_latex" nowrap="False" number="True" xml:space="preserve">
<math_block classes="output text_latex" nowrap="0" number="True" xml:space="preserve">
a = b+c
<paragraph>
The plotting code for a sympy equation (=@eqn:example_sympy).
Expand All @@ -216,7 +216,7 @@
<container mime_type="image/png">
<image candidates="{'*': '_build/jupyter_execute/e2dfbe330154316cfb6f3186e8f57fc4df8aee03b0303ed1345fc22cd51f66de.png'}" uri="_build/jupyter_execute/e2dfbe330154316cfb6f3186e8f57fc4df8aee03b0303ed1345fc22cd51f66de.png">
<container mime_type="text/latex">
<math_block classes="output text_latex" nowrap="False" number="True" xml:space="preserve">
<math_block classes="output text_latex" nowrap="0" 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)
<section ids="interactive-outputs" names="interactive\ outputs">
<title>
Expand Down
20 changes: 10 additions & 10 deletions tests/test_glue/test_parser.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
Glue Tests
<container cell_index="1" cell_metadata="{}" classes="cell" exec_count="1" nb_element="cell_code">
<container classes="cell_input" nb_element="cell_code_source">
<literal_block language="ipython3" linenos="False" xml:space="preserve">
<literal_block language="ipython3" linenos="0" xml:space="preserve">
from myst_nb import glue
<container cell_index="2" cell_metadata="{}" classes="cell" exec_count="2" nb_element="cell_code">
<container classes="cell_input" nb_element="cell_code_source">
<literal_block language="ipython3" linenos="False" xml:space="preserve">
<literal_block language="ipython3" linenos="0" xml:space="preserve">
glue("key_text1", "text1")
glue("key_float", 3.14159)
<container classes="cell_output" nb_element="cell_code_output">
<literal_block classes="output text_plain" language="myst-ansi" linenos="False" xml:space="preserve">
<literal_block classes="output text_plain" language="myst-ansi" linenos="0" xml:space="preserve">
'text1'
<literal_block classes="output text_plain" language="myst-ansi" linenos="False" xml:space="preserve">
<literal_block classes="output text_plain" language="myst-ansi" linenos="0" xml:space="preserve">
3.14159
<container cell_index="3" cell_metadata="{}" classes="cell" exec_count="3" nb_element="cell_code">
<container classes="cell_input" nb_element="cell_code_source">
<literal_block language="ipython3" linenos="False" xml:space="preserve">
<literal_block language="ipython3" linenos="0" xml:space="preserve">
glue("key_undisplayed", "undisplayed", display=False)
<container cell_index="4" cell_metadata="{'scrolled': True}" classes="cell" exec_count="4" nb_element="cell_code">
<container classes="cell_input" nb_element="cell_code_source">
<literal_block language="ipython3" linenos="False" xml:space="preserve">
<literal_block language="ipython3" linenos="0" xml:space="preserve">
import pandas as pd

df = pd.DataFrame({"header": [1, 2, 3]})
Expand Down Expand Up @@ -68,7 +68,7 @@
</div>
<container cell_index="5" cell_metadata="{}" classes="cell" exec_count="5" nb_element="cell_code">
<container classes="cell_input" nb_element="cell_code_source">
<literal_block language="ipython3" linenos="False" xml:space="preserve">
<literal_block language="ipython3" linenos="0" xml:space="preserve">
import matplotlib.pyplot as plt

plt.plot([1, 2, 3])
Expand Down Expand Up @@ -149,7 +149,7 @@
Math
<container cell_index="8" cell_metadata="{}" classes="cell" exec_count="6" nb_element="cell_code">
<container classes="cell_input" nb_element="cell_code_source">
<literal_block language="ipython3" linenos="False" xml:space="preserve">
<literal_block language="ipython3" linenos="0" xml:space="preserve">
import sympy as sym

f = sym.Function("f")
Expand All @@ -158,8 +158,8 @@
f = y(n) - 2 * y(n - 1 / sym.pi) - 5 * y(n - 2)
glue("sym_eq", sym.rsolve(f, y(n), [1, 4]))
<container classes="cell_output" nb_element="cell_code_output">
<math_block classes="output text_latex" nowrap="False" number="True" xml:space="preserve">
<math_block classes="output text_latex" nowrap="0" 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">
<math_block classes="pasted-math" docname="with_glue" ids="equation-eq-sym" label="eq-sym" nowrap="0" 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)
6 changes: 3 additions & 3 deletions tests/test_parser/test_complex_outputs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
</table>
</div>
<container mime_type="text/latex">
<math_block classes="output text_latex" nowrap="False" number="True" xml:space="preserve">
<math_block classes="output text_latex" nowrap="0" number="True" xml:space="preserve">
\begin{tabular}{lllrr}
\toprule
{} & a & b & c & d \\
Expand All @@ -227,7 +227,7 @@
<container classes="cell_output" nb_element="cell_code_output">
<container nb_element="mime_bundle">
<container mime_type="text/latex">
<math_block classes="output text_latex" nowrap="False" number="True" xml:space="preserve">
<math_block classes="output text_latex" nowrap="0" number="True" xml:space="preserve">
a = b+c
<container mime_type="text/plain">
<literal_block classes="output text_plain" language="myst-ansi" xml:space="preserve">
Expand All @@ -246,7 +246,7 @@
<container mime_type="image/png">
<image candidates="{'*': '_build/jupyter_execute/8c43e5c8cccf697754876b7fec1b0a9b731d7900bb585e775a5fa326b4de8c5a.png'}" uri="_build/jupyter_execute/8c43e5c8cccf697754876b7fec1b0a9b731d7900bb585e775a5fa326b4de8c5a.png">
<container mime_type="text/latex">
<math_block classes="output text_latex" nowrap="False" number="True" xml:space="preserve">
<math_block classes="output text_latex" nowrap="0" 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)
<container mime_type="text/plain">
<literal_block classes="output text_plain" language="myst-ansi" xml:space="preserve">
Expand Down
4 changes: 2 additions & 2 deletions tests/test_render_outputs/test_basic_run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
some text
<container cell_index="1" cell_metadata="{}" classes="cell" exec_count="1" nb_element="cell_code">
<container classes="cell_input" nb_element="cell_code_source">
<literal_block language="ipython3" linenos="False" xml:space="preserve">
<literal_block language="ipython3" linenos="0" xml:space="preserve">
a = 1
print(a)
<container classes="cell_output" nb_element="cell_code_output">
<literal_block classes="output stream" language="myst-ansi" linenos="False" xml:space="preserve">
<literal_block classes="output stream" language="myst-ansi" linenos="0" xml:space="preserve">
1
Loading
Loading