Skip to content

Commit

Permalink
Merge branch 'master' into coalesce_streams
Browse files Browse the repository at this point in the history
  • Loading branch information
bsipocz authored Sep 19, 2024
2 parents 289fb8c + db8cedb commit 4744bf0
Show file tree
Hide file tree
Showing 19 changed files with 262 additions and 48 deletions.
10 changes: 8 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
interval: "monthly"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
interval: "monthly"
groups:
actions:
patterns:
- "*"
labels:
- "github_actions"
46 changes: 21 additions & 25 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ on:
pull_request:

jobs:
pre-commit:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- uses: pre-commit/[email protected]

tests:

Expand All @@ -27,28 +16,33 @@ jobs:
matrix:
os: [ubuntu-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
sphinx: [">=5.0,<=7.*"] # Newest Sphinx (any)
myst-parser: [">=1.0.0,<=2.*"] # Newest MyST Parser (any)
sphinx: [">=5,<9"] # Newest Sphinx (any)
myst-parser: [">=1,<3"] # Newest MyST Parser (any)
include:
# Just check the other platforms once
- os: windows-latest
python-version: "3.10"
sphinx: "~=7.0"
myst-parser: ">=2.0"
python-version: "3.12"
sphinx: "~=8.0"
myst-parser: "~=4.0"
- os: macos-latest
python-version: "3.10"
sphinx: "~=7.0"
myst-parser: ">=2.0"
python-version: "3.12"
sphinx: "~=8.0"
myst-parser: "~=4.0"
# Oldest known-compatible dependencies
- os: ubuntu-latest
python-version: "3.9"
sphinx: "~=5.0"
myst-parser: "~=1.0.0"
sphinx: "==5.0.0"
myst-parser: "==1.0.0"
# Mid-range dependencies
- os: ubuntu-latest
python-version: "3.11"
sphinx: "==7.0.0"
myst-parser: "==2.0.0"
# Newest known-compatible dependencies
- os: ubuntu-latest
python-version: "3.12"
sphinx: "~=7.0"
myst-parser: "~=2.0.0"
sphinx: "==8.0.2"
myst-parser: "==4.0.0"

runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -91,8 +85,10 @@ jobs:
# 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@v3
uses: codecov/codecov-action@v4
if: false
with:
name: myst-nb-pytests
flags: pytests
Expand All @@ -101,7 +97,7 @@ jobs:
publish:

name: Publish to PyPi
needs: [pre-commit, tests]
needs: [tests]
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 4 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ exclude: >
tests/.*\.txt
)$
ci:
autoupdate_schedule: 'monthly'

repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down Expand Up @@ -39,7 +42,7 @@ repos:
additional_dependencies:
- importlib_metadata
- myst-parser~=2.0.0
- "sphinx~=7.0"
- "sphinx~=7.3.7"
- nbclient
- types-PyYAML
files: >
Expand Down
61 changes: 61 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,66 @@
# Change Log

## v1.1.1 - 2024-06-27

([full changelog](https://github.com/executablebooks/MyST-NB/compare/v1.1.0...6ce30cd41fa82543e0f315ac8bbee82669b0cc82))

### Bugs fixed

- FIX: output metadata overwrites image size for all following images [#609](https://github.com/executablebooks/MyST-NB/pull/609) ([@aeisenbarth](https://github.com/aeisenbarth))

- FIX: remove incorrect license classifier [#603](https://github.com/executablebooks/MyST-NB/pull/603) ([@agoose77](https://github.com/agoose77))

### Maintenance and upkeep improvements

- MAINT: bump version [#614](https://github.com/executablebooks/MyST-NB/pull/614) ([@agoose77](https://github.com/agoose77))

- MAINT: appease mypy [#612](https://github.com/executablebooks/MyST-NB/pull/612) ([@agoose77](https://github.com/agoose77))

- MAINT: fix specs for CI matrix [#611](https://github.com/executablebooks/MyST-NB/pull/611) ([@agoose77](https://github.com/agoose77))

- MAINT: bump version [#592](https://github.com/executablebooks/MyST-NB/pull/592) ([@agoose77](https://github.com/agoose77))

### Documentation improvements

- DOCS: set printoptions to disable modern scalar printing [#613](https://github.com/executablebooks/MyST-NB/pull/613) ([@agoose77](https://github.com/agoose77))

- DOCS: extra comma forgotten [#606](https://github.com/executablebooks/MyST-NB/pull/606) ([@jeertmans](https://github.com/jeertmans))

- DOCS: update shown code to match source [#598](https://github.com/executablebooks/MyST-NB/pull/598) ([@OriolAbril](https://github.com/OriolAbril))

### Contributors to this release

([GitHub contributors page for this release](https://github.com/executablebooks/MyST-NB/graphs/contributors?from=2024-04-12&to=2024-06-27&type=c))

[@aeisenbarth](https://github.com/search?q=repo%3Aexecutablebooks%2FMyST-NB+involves%3Aaeisenbarth+updated%3A2024-04-12..2024-06-27&type=Issues) | [@agoose77](https://github.com/search?q=repo%3Aexecutablebooks%2FMyST-NB+involves%3Aagoose77+updated%3A2024-04-12..2024-06-27&type=Issues) | [@jeertmans](https://github.com/search?q=repo%3Aexecutablebooks%2FMyST-NB+involves%3Ajeertmans+updated%3A2024-04-12..2024-06-27&type=Issues) | [@OriolAbril](https://github.com/search?q=repo%3Aexecutablebooks%2FMyST-NB+involves%3AOriolAbril+updated%3A2024-04-12..2024-06-27&type=Issues) | [@sstroemer](https://github.com/search?q=repo%3Aexecutablebooks%2FMyST-NB+involves%3Asstroemer+updated%3A2024-04-12..2024-06-27&type=Issues) | [@welcome](https://github.com/search?q=repo%3Aexecutablebooks%2FMyST-NB+involves%3Awelcome+updated%3A2024-04-12..2024-06-27&type=Issues)


## v1.1.0 - 2024-04-12

([full changelog](https://github.com/executablebooks/MyST-NB/compare/v1.0.0...9943ec214c35844c4535d0184f7840574fc7ab03))

### Enhancements made

- ENH: pass-through image metadata [#588](https://github.com/executablebooks/MyST-NB/pull/588) ([@flying-sheep](https://github.com/flying-sheep))

### Maintenance and upkeep improvements

- MAINT: bump version [#592](https://github.com/executablebooks/MyST-NB/pull/592) ([@agoose77](https://github.com/agoose77))

- MAINT: use `findall` instead of `traverse` [#585](https://github.com/executablebooks/MyST-NB/pull/585) ([@agoose77](https://github.com/agoose77))

- MAINT: restore default line length [#577](https://github.com/executablebooks/MyST-NB/pull/577) ([@agoose77](https://github.com/agoose77))

### Other merged PRs

- build(deps): bump actions/setup-python from 4 to 5 [#576](https://github.com/executablebooks/MyST-NB/pull/576) ([@dependabot](https://github.com/dependabot))

### Contributors to this release

([GitHub contributors page for this release](https://github.com/executablebooks/MyST-NB/graphs/contributors?from=2023-11-08&to=2024-04-12&type=c))

[@agoose77](https://github.com/search?q=repo%3Aexecutablebooks%2FMyST-NB+involves%3Aagoose77+updated%3A2023-11-08..2024-04-12&type=Issues) | [@cisaacstern](https://github.com/search?q=repo%3Aexecutablebooks%2FMyST-NB+involves%3Acisaacstern+updated%3A2023-11-08..2024-04-12&type=Issues) | [@dependabot](https://github.com/search?q=repo%3Aexecutablebooks%2FMyST-NB+involves%3Adependabot+updated%3A2023-11-08..2024-04-12&type=Issues) | [@flying-sheep](https://github.com/search?q=repo%3Aexecutablebooks%2FMyST-NB+involves%3Aflying-sheep+updated%3A2023-11-08..2024-04-12&type=Issues) | [@ma-sadeghi](https://github.com/search?q=repo%3Aexecutablebooks%2FMyST-NB+involves%3Ama-sadeghi+updated%3A2023-11-08..2024-04-12&type=Issues) | [@peytondmurray](https://github.com/search?q=repo%3Aexecutablebooks%2FMyST-NB+involves%3Apeytondmurray+updated%3A2023-11-08..2024-04-12&type=Issues) | [@PhilipVinc](https://github.com/search?q=repo%3Aexecutablebooks%2FMyST-NB+involves%3APhilipVinc+updated%3A2023-11-08..2024-04-12&type=Issues) | [@sphuber](https://github.com/search?q=repo%3Aexecutablebooks%2FMyST-NB+involves%3Asphuber+updated%3A2023-11-08..2024-04-12&type=Issues) | [@welcome](https://github.com/search?q=repo%3Aexecutablebooks%2FMyST-NB+involves%3Awelcome+updated%3A2023-11-08..2024-04-12&type=Issues)


## v1.0.0 - 2023-11-08

Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Tags are a list of strings under the `tags` key in the cell metadata, e.g.
"cell_type": "code",
"source": ["print('hello world')"],
"metadata": {
"tags": ["my-tag1", "my-tag2"],
"tags": ["my-tag1", "my-tag2"]
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/render/format_code_cells.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ You can also wrap the output in a [`figure`](https://docutils.sourceforge.io/doc
---
mystnb:
image:
width: 200px
width: 300px
alt: fun-fish
classes: shadow bg-primary
figure:
Expand Down
29 changes: 26 additions & 3 deletions docs/render/glue.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ To glue keys from other notebooks, see {ref}`glue/crossdoc`.
## Save variables in code cells

You can use `myst_nb.glue()` to assign the output of a variable to a key of your choice.
`glue` will store all of the information that is normally used to display that variable (ie, whatever happens when you display the variable by putting it at the end of a cell).
`glue` will store all of the information that is normally used to display that variable (that is, whatever happens when you display the variable by putting it at the end of a cell).
Choose a key that you will remember, as you will use it later.

The following code glues a variable inside the notebook:
Expand Down Expand Up @@ -54,6 +54,8 @@ We'll hide most of this process below, to focus on the glueing part.
# Simulate some data and bootstrap the mean of the data
import numpy as np
np.set_printoptions(legacy="1.25")
import pandas as pd
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -135,12 +137,12 @@ These variables can be pasted using one of the roles or directives in the `glue:

### The `glue` role/directive

The simplest role and directive are `glue` (a.k.a. `glue:any`),
The simplest role and directive are `glue` (also known as `glue:any`),
which paste the glued output inline or as a block respectively,
with no additional formatting.
Simply add:

````
````md
```{glue} your-key
```
````
Expand Down Expand Up @@ -217,6 +219,27 @@ For example, the following: ``My rounded mean: {glue:text}`boot_mean:.2f` `` wil

My rounded mean: {glue:text}`boot_mean:.2f` (95% CI: {glue:text}`boot_clo:.2f`/{glue:text}`boot_chi:.2f`).

````{warning}
As of NumPy 2.0, the `text/plain` representation of [NumPy objects has changed](https://numpy.org/devdocs/release/2.0.0-notes.html#representation-of-numpy-scalars-changed).
Using text formatting with NumPy>=2.0 will give warnings like:
```
sphinx.errors.SphinxWarning: <filename>:257:Failed to format text/plain data: could not convert string to float: 'np.float64(0.9643970836113095)' [mystnb.glue]
```
This can be resolved by either formatting the number before glueing or by setting NumPy to use legacy print options, as shown below.
```python
var = np.float(1.0)
# Format the variable before glueing
glue("var_glue", f"{var:.2f}")
# Or set NumPy legacy print options
np.setprintoptions(legacy="1.25")
glue("var_glue", var)
```
````

+++

### The `glue:figure` directive
Expand Down
2 changes: 1 addition & 1 deletion myst_nb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""A docutils/sphinx parser for Jupyter Notebooks."""
__version__ = "1.1.0"
__version__ = "1.1.1"


def setup(app):
Expand Down
2 changes: 1 addition & 1 deletion myst_nb/core/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def create_nb_reader(
# we check suffixes ordered by longest first, to ensure we get the "closest" match
iterator = sorted(readers.items(), key=lambda x: len(x[0]), reverse=True)
for suffix, (reader, reader_kwargs, commonmark_only) in iterator:
if path.endswith(suffix):
if Path(path).suffix == suffix:
if isinstance(reader, str):
# attempt to load the reader as an object path
reader = import_object(reader)
Expand Down
2 changes: 1 addition & 1 deletion myst_nb/core/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ def render_image(self, data: MimeData) -> list[nodes.Element]:
# TODO backwards-compatible re-naming to image_options?
image_options = self.renderer.get_cell_level_config(
"render_image_options", data.cell_metadata, line=data.line
)
).copy()
# Overwrite with metadata stored in output
image_options.update(
{
Expand Down
13 changes: 8 additions & 5 deletions myst_nb/sphinx_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ def sphinx_setup(app: Sphinx):
for name, default, field in NbParserConfig().as_triple():
if not field.metadata.get("sphinx_exclude"):
# TODO add types?
app.add_config_value(f"nb_{name}", default, "env", Any)
app.add_config_value(f"nb_{name}", default, "env", Any) # type: ignore[arg-type]
if "legacy_name" in field.metadata:
app.add_config_value(
f"{field.metadata['legacy_name']}", _UNSET, "env", Any
f"{field.metadata['legacy_name']}",
_UNSET,
"env",
Any, # type: ignore[arg-type]
)
# Handle non-standard deprecation
app.add_config_value("nb_render_priority", _UNSET, "env", Any)
app.add_config_value("nb_render_priority", _UNSET, "env", Any) # type: ignore[arg-type]

# generate notebook configuration from Sphinx configuration
# this also validates the configuration values
Expand Down Expand Up @@ -130,7 +133,7 @@ def create_mystnb_config(app):
"""Generate notebook configuration from Sphinx configuration"""

# Ignore type checkers because the attribute is dynamically assigned
from sphinx.util.console import bold # type: ignore[attr-defined]
from sphinx.util.console import bold

values = {}
for name, _, field in NbParserConfig().as_triple():
Expand Down Expand Up @@ -227,4 +230,4 @@ def add_per_page_html_resources(
return
js_files = NbMetadataCollector.get_js_files(cast(SphinxEnvType, app.env), pagename)
for path, kwargs in js_files.values():
app.add_js_file(path, **kwargs) # type: ignore
app.add_js_file(path, **kwargs) # type: ignore[arg-type]
4 changes: 4 additions & 0 deletions tests/notebooks/complex_outputs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@
]
},
"metadata": {
"image/png": {
"width": 432,
"height": 288
},
"needs_background": "light"
},
"output_type": "display_data"
Expand Down
77 changes: 77 additions & 0 deletions tests/notebooks/metadata_image_output.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/test_parser/test_complex_outputs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
<container classes="cell_output" nb_element="cell_code_output">
<container nb_element="mime_bundle">
<container mime_type="image/png">
<image candidates="{'*': '_build/jupyter_execute/16832f45917c1c9862c50f0948f64a498402d6ccde1f3a291da17f240797b160.png'}" height="400" uri="_build/jupyter_execute/16832f45917c1c9862c50f0948f64a498402d6ccde1f3a291da17f240797b160.png">
<image candidates="{'*': '_build/jupyter_execute/16832f45917c1c9862c50f0948f64a498402d6ccde1f3a291da17f240797b160.png'}" height="288" uri="_build/jupyter_execute/16832f45917c1c9862c50f0948f64a498402d6ccde1f3a291da17f240797b160.png" width="432">
<container mime_type="text/plain">
<literal_block classes="output text_plain" language="myst-ansi" xml:space="preserve">
<Figure size 432x288 with 1 Axes>
Expand Down Expand Up @@ -244,7 +244,7 @@
<container classes="cell_output" nb_element="cell_code_output">
<container nb_element="mime_bundle">
<container mime_type="image/png">
<image candidates="{'*': '_build/jupyter_execute/8c43e5c8cccf697754876b7fec1b0a9b731d7900bb585e775a5fa326b4de8c5a.png'}" height="400" uri="_build/jupyter_execute/8c43e5c8cccf697754876b7fec1b0a9b731d7900bb585e775a5fa326b4de8c5a.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">
\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
19 changes: 19 additions & 0 deletions tests/test_render_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest

from myst_nb.core.render import EntryPointError, load_renderer
from sphinx.util.fileutil import copy_asset_file


def test_load_renderer_not_found():
Expand Down Expand Up @@ -116,6 +117,24 @@ def test_metadata_image(sphinx_run, clean_doctree, file_regression):
)


@pytest.mark.sphinx_params(
"metadata_image_output.ipynb",
conf={"nb_execution_mode": "force"},
)
def test_metadata_image_output(
sphinx_run, clean_doctree, file_regression, get_test_path
):
"""Test configuring image attributes to be rendered from cell metadata."""
asset_path = get_test_path("example.jpg")
copy_asset_file(str(asset_path), str(sphinx_run.app.srcdir))
sphinx_run.build()
assert sphinx_run.warnings() == ""
doctree = clean_doctree(sphinx_run.get_resolved_doctree("metadata_image_output"))
file_regression.check(
doctree.pformat().replace(".jpeg", ".jpg"), extension=".xml", encoding="utf-8"
)


@pytest.mark.sphinx_params(
"metadata_figure.ipynb",
conf={"nb_execution_mode": "off", "nb_cell_metadata_key": "myst"},
Expand Down
Loading

0 comments on commit 4744bf0

Please sign in to comment.