Skip to content

Commit

Permalink
maint: use findall instead of traverse (#585)
Browse files Browse the repository at this point in the history
* maint: use findall

* fix: add pyarrow test dep

* fix: remove deprecated code

* chore: update tests for new pins

* chore: pin pandas
  • Loading branch information
agoose77 authored Apr 12, 2024
1 parent c3e015e commit 1efadf7
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion myst_nb/docutils_.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def _parse(self, inputstring: str, document: nodes.document) -> None:
css_paths.append(
nb_renderer.write_file(
["mystnb.css"],
import_resources.read_binary(static, "mystnb.css"),
(import_resources.files(static) / "mystnb.css").read_bytes(),
overwrite=True,
)
)
Expand Down
3 changes: 2 additions & 1 deletion myst_nb/ext/execution_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from sphinx.util import logging
from sphinx.util.docutils import SphinxDirective

from myst_nb._compat import findall
from myst_nb.sphinx_ import NbMetadataCollector, SphinxEnvType

SPHINX_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -76,7 +77,7 @@ class ExecutionStatsPostTransform(SphinxPostTransform):
def run(self, **kwargs) -> None:
"""Replace the placeholder node with the final table nodes."""
self.env: SphinxEnvType
for node in self.document.traverse(ExecutionStatsNode):
for node in findall(self.document)(ExecutionStatsNode):
node.replace_self(
make_stat_table(
self.env.docname, NbMetadataCollector.get_doc_data(self.env)
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ testing = [
"matplotlib==3.7.*",
"nbdime",
"numpy",
"pandas",
"pandas==1.5.*",
"pyarrow",
"pytest~=7.1",
"pytest-cov>=3,<5",
"pytest-regressions",
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ def _check_nbs(obtained_filename, expected_filename):
def clean_doctree():
def _func(doctree):
if os.name == "nt": # on Windows file paths are absolute
for node in doctree.traverse(image_node): # type: image_node
findall = getattr(doctree, "findall", doctree.traverse)
for node in findall(image_node): # type: image_node
if "candidates" in node:
node["candidates"]["*"] = (
"_build/jupyter_execute/"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_execute/test_complex_outputs_unrun_auto.xml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
(√5⋅ⅈ) ⋅⎜─ - ──────⎟ + (-√5⋅ⅈ) ⋅⎜─ + ──────⎟
⎝2 5 ⎠ ⎝2 5 ⎠
<container mime_type="image/png">
<image candidates="{'*': '_build/jupyter_execute/a04ee1a78ad33a6345469c5f6d84ff6ef0bfcb4d9e3a8d10eaa7ea3f445bbc5c.png'}" uri="_build/jupyter_execute/a04ee1a78ad33a6345469c5f6d84ff6ef0bfcb4d9e3a8d10eaa7ea3f445bbc5c.png">
<image candidates="{'*': '_build/jupyter_execute/9bc81205a14646a235d284d1b68223d17f30f7f1d3d8ed3e52cf47830b02e3bb.png'}" uri="_build/jupyter_execute/9bc81205a14646a235d284d1b68223d17f30f7f1d3d8ed3e52cf47830b02e3bb.png">
<container mime_type="text/latex">
<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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_execute/test_complex_outputs_unrun_cache.xml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
(√5⋅ⅈ) ⋅⎜─ - ──────⎟ + (-√5⋅ⅈ) ⋅⎜─ + ──────⎟
⎝2 5 ⎠ ⎝2 5 ⎠
<container mime_type="image/png">
<image candidates="{'*': '_build/jupyter_execute/a04ee1a78ad33a6345469c5f6d84ff6ef0bfcb4d9e3a8d10eaa7ea3f445bbc5c.png'}" uri="_build/jupyter_execute/a04ee1a78ad33a6345469c5f6d84ff6ef0bfcb4d9e3a8d10eaa7ea3f445bbc5c.png">
<image candidates="{'*': '_build/jupyter_execute/9bc81205a14646a235d284d1b68223d17f30f7f1d3d8ed3e52cf47830b02e3bb.png'}" uri="_build/jupyter_execute/9bc81205a14646a235d284d1b68223d17f30f7f1d3d8ed3e52cf47830b02e3bb.png">
<container mime_type="text/latex">
<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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_execute/test_custom_convert_auto.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
<literal_block classes="output text_plain" language="myst-ansi" xml:space="preserve">
<Figure size 640x480 with 1 Axes>
<container mime_type="image/png">
<image candidates="{'*': '_build/jupyter_execute/79c62be209810029709c370dc93d2e5dba383561eb0d8bc1ce8b30db61641985.png'}" uri="_build/jupyter_execute/79c62be209810029709c370dc93d2e5dba383561eb0d8bc1ce8b30db61641985.png">
<image candidates="{'*': '_build/jupyter_execute/a2e637020dfe58f670ba2c942d7a55e49ba48bed09312569ee15a84f5ac680cb.png'}" uri="_build/jupyter_execute/a2e637020dfe58f670ba2c942d7a55e49ba48bed09312569ee15a84f5ac680cb.png">
2 changes: 1 addition & 1 deletion tests/test_execute/test_custom_convert_cache.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
<literal_block classes="output text_plain" language="myst-ansi" xml:space="preserve">
<Figure size 640x480 with 1 Axes>
<container mime_type="image/png">
<image candidates="{'*': '_build/jupyter_execute/79c62be209810029709c370dc93d2e5dba383561eb0d8bc1ce8b30db61641985.png'}" uri="_build/jupyter_execute/79c62be209810029709c370dc93d2e5dba383561eb0d8bc1ce8b30db61641985.png">
<image candidates="{'*': '_build/jupyter_execute/a2e637020dfe58f670ba2c942d7a55e49ba48bed09312569ee15a84f5ac680cb.png'}" uri="_build/jupyter_execute/a2e637020dfe58f670ba2c942d7a55e49ba48bed09312569ee15a84f5ac680cb.png">

0 comments on commit 1efadf7

Please sign in to comment.