Skip to content

Commit 7439a9d

Browse files
committed
Merge branch 'master' into add-cell-ids
2 parents 8297f9d + 3d6a5d1 commit 7439a9d

35 files changed

+274
-160
lines changed

.github/workflows/tests.yml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ jobs:
2626
fail-fast: false
2727
matrix:
2828
os: [ubuntu-latest]
29-
python-version: ["3.8", "3.9", "3.10"]
30-
sphinx: [">=5,<6"]
29+
python-version: ["3.8", "3.9", "3.10", "3.11"]
30+
sphinx: ["~=5.0","~=6.0","~=7.0"]
3131
include:
3232
- os: windows-latest
3333
python-version: 3.9
34-
sphinx: ">=5,<6"
34+
sphinx: "~=5.0"
3535
- os: macos-latest
3636
python-version: 3.9
37-
sphinx: ">=5,<6"
37+
sphinx: "~=5.0"
3838

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

@@ -44,10 +44,29 @@ jobs:
4444
uses: actions/setup-python@v4
4545
with:
4646
python-version: ${{ matrix.python-version }}
47+
cache: pip
48+
- name: Install myst-nb with Sphinx ${{ matrix.sphinx }}
49+
run: |
50+
pip install --upgrade pip
51+
pip install --upgrade "Sphinx${{ matrix.sphinx }}" -e .[testing]
52+
53+
- name: Run pytest
54+
run: pytest --durations=10
55+
56+
coverage:
57+
needs: [tests]
58+
runs-on: ubuntu-latest
59+
60+
steps:
61+
- uses: actions/checkout@v3
62+
- name: Set up Python ${{ matrix.python-version }}
63+
uses: actions/setup-python@v4
64+
with:
65+
python-version: 3.11
66+
cache: pip
4767
- name: Install dependencies
4868
run: |
49-
python -m pip install --upgrade pip
50-
pip install "sphinx${{ matrix.sphinx }}"
69+
pip install --upgrade pip
5170
pip install -e .[testing]
5271
5372
- name: Run pytest
@@ -59,13 +78,11 @@ jobs:
5978
# this is why we run `coverage xml` afterwards (required by codecov)
6079

6180
- name: Upload to Codecov
62-
if: github.repository == 'executablebooks/MyST-NB' && matrix.python-version == '3.9' && matrix.os == 'ubuntu-latest'
6381
uses: codecov/codecov-action@v3
6482
with:
6583
name: myst-nb-pytests
6684
flags: pytests
6785
files: ./coverage.xml
68-
fail_ci_if_error: true
6986

7087
publish:
7188

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repos:
2020
- id: trailing-whitespace
2121

2222
- repo: https://github.com/asottile/pyupgrade
23-
rev: v3.3.2
23+
rev: v3.7.0
2424
hooks:
2525
- id: pyupgrade
2626
args: [--py37-plus]
@@ -42,13 +42,13 @@ repos:
4242
additional_dependencies: [flake8-bugbear]
4343

4444
- repo: https://github.com/pre-commit/mirrors-mypy
45-
rev: v1.2.0
45+
rev: v1.4.1
4646
hooks:
4747
- id: mypy
4848
args: [--config-file=pyproject.toml]
4949
additional_dependencies:
5050
- importlib_metadata
51-
- myst-parser~=0.18.0
51+
- myst-parser~=1.0.0
5252
- "sphinx~=5.0"
5353
- nbclient
5454
- types-PyYAML

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ WARNING: 'jupyter_execute_notebooks' is deprecated for 'nb_execution_mode' [myst
9292

9393
`nb_render_priority` has been removed and replaced by `nb_mime_priority_overrides`, which has a different format and is more flexible. See [Outputs MIME priority](docs/render/format_code_cells.md) for more information.
9494

95-
As per the changes in [`myst_parser`](myst:develop/_changelog), the `dollarmath` syntax extension is no longer included by default.
95+
As per the changes in [`myst_parser`](inv:myst#develop/_changelog), the `dollarmath` syntax extension is no longer included by default.
9696
To re-add this extension, ensure that it is specified in your `conf.py`: `myst_enable_extensions = ["dollarmath"]`.
9797

9898
For cell-level configuration the top-level key `render` has now been deprecated for `mystnb`.
@@ -168,7 +168,7 @@ See [Embedding outputs as variables](docs/render/glue.md) for more details.
168168
- `nbconvert`
169169
- Updated:
170170
- `Python`: `3.6+ -> 3.7+`
171-
- `myst_parser`: [`0.15 -> 0.17`](myst:develop/_changelog)
171+
- `myst_parser`: [`0.15 -> 0.17`](inv:myst#develop/_changelog)
172172
- `jupyter-cache`: [`0.4 -> 0.5`](https://github.com/executablebooks/jupyter-cache/blob/master/CHANGELOG.md)
173173
- `sphinx-togglebutton`: [`0.1 -> 0.3`](https://sphinx-togglebutton.readthedocs.io/en/latest/changelog.html)
174174

docs/authoring/custom-formats.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ nb_custom_formats = {
2121
```
2222

2323
- The string should be a Python function that will be loaded by `import mylibrary.converter_function`
24-
- The function should take a file's contents (as a `str`) and return an [nbformat.NotebookNode](nbformat:api)
24+
- The function should take a file's contents (as a `str`) and return an [nbformat.NotebookNode](inv:nbformat#api)
2525

2626
If the function takes additional keyword arguments, then you can specify these as dictionary in a second argument.
2727
For example this is what the default conversion would look like:

docs/authoring/jupyter-notebooks.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ Sphinx using the MyST parser.[^download]
1616

1717
:::{seealso}
1818
For more information about what you can write with MyST Markdown, see the
19-
[MyST Parser documentation](myst:intro/get-started).
19+
[MyST Parser documentation](inv:myst#intro/get-started).
2020
:::
2121

2222
### Configuration
2323

24-
The MyST-NB parser derives from [the base MyST-Parser](myst:intro/get-started), and so all the same configuration options are available.
25-
See the [MyST configuration options](myst:sphinx/config-options) for the full set of options, and [MyST syntax guide](myst:syntax/core) for all the syntax options.
24+
The MyST-NB parser derives from [the base MyST-Parser](inv:myst#intro/get-started), and so all the same configuration options are available.
25+
See the [MyST configuration options](inv:myst#sphinx/config-options) for the full set of options, and [MyST syntax guide](inv:myst#syntax/core) for all the syntax options.
2626

2727
To build documentation from this notebook, the following options are set:
2828

@@ -38,7 +38,7 @@ myst_url_schemes = ("http", "https", "mailto")
3838
```
3939

4040
:::{note}
41-
Loading the `myst_nb` extension also activates the [`myst_parser`](myst:index) extension, for enabling the MyST flavour of Markdown.
41+
Loading the `myst_nb` extension also activates the [`myst_parser`](inv:myst#index) extension, for enabling the MyST flavour of Markdown.
4242
It is not required to add this explicitly in the list of `extensions`.
4343
:::
4444

@@ -53,7 +53,7 @@ For example, here's the MyST-NB logo:
5353

5454
![myst-nb logo](../_static/logo-wide.svg)
5555

56-
By adding `"html_image"` to the `myst_enable_extensions` list in the sphinx configuration ([see here](myst:syntax/images)), you can even add HTML `img` tags with attributes:
56+
By adding `"html_image"` to the `myst_enable_extensions` list in the sphinx configuration ([see here](inv:myst#syntax/images)), you can even add HTML `img` tags with attributes:
5757

5858
```html
5959
<img src="../_static/logo-wide.svg" alt="logo" width="200px" class="shadow mb-2">
@@ -66,7 +66,7 @@ For example, here's a note admonition block:
6666

6767
:::::{note}
6868
**Wow**, a note!
69-
It was generated with this code ([as explained here](myst:syntax/admonitions)):
69+
It was generated with this code ([as explained here](inv:myst:std:label#syntax/admonitions)):
7070

7171
````md
7272
:::{note}
@@ -77,7 +77,7 @@ It was generated with this code ([as explained here](myst:syntax/admonitions)):
7777
:::::
7878

7979
If you wish to use "bare" LaTeX equations, then you should add `"amsmath"` to the `myst_enable_extensions` list in the sphinx configuration.
80-
This is [explained here](myst:syntax/amsmath), and works as such:
80+
This is [explained here](inv:myst:std:label#syntax/amsmath), and works as such:
8181

8282
```latex
8383
\begin{equation}
@@ -110,7 +110,7 @@ $$e^{i\pi} + 1 = 0$$ (euler)
110110
Euler's identity, equation {math:numref}`euler`, was elected one of the
111111
most beautiful mathematical formulas.
112112

113-
You can see the syntax used for this example [here in the MyST documentation](myst:syntax/math).
113+
You can see the syntax used for this example [here in the MyST documentation](inv:myst:std:label#syntax/math).
114114

115115
## Code cells and outputs
116116

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Build single or collections of documents into multiple formats (HTML, PDF, ...).
8686

8787
MyST-NB is a module within the [Executable Books Project](https://executablebooks.org),
8888
an international collaboration to build open source tools that facilitate publishing computational narratives using the Jupyter ecosystem.
89-
It is also a core component of [Jupyter Book](jb:intro).
89+
It is also a core component of [Jupyter Book](inv:jb#intro).
9090

9191
Check out the [Gallery of Jupyter Books](https://executablebooks.org/en/latest/gallery),
9292
for inspiration from across the community.

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# this is only required by coconut kernel
2-
ipython<=7.11.0
2+
ipython<=8.14.0

myst_nb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""A docutils/sphinx parser for Jupyter Notebooks."""
2-
__version__ = "0.17.2"
2+
__version__ = "0.18.0"
33

44

55
def setup(app):

myst_nb/core/config.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Configuration for myst-nb."""
22
import dataclasses as dc
33
from enum import Enum
4+
import sys
45
from typing import Any, Callable, Dict, Iterable, Optional, Sequence, Tuple
56

67
from myst_parser.config.dc_validators import (
@@ -12,7 +13,13 @@
1213
optional,
1314
validate_fields,
1415
)
15-
from typing_extensions import Literal
16+
17+
if sys.version_info >= (3, 8):
18+
from typing import Literal
19+
else:
20+
from typing_extensions import Literal # noqa: F401
21+
22+
from myst_nb.warnings_ import MystNBWarnings
1623

1724

1825
def custom_formats_converter(value: dict) -> Dict[str, Tuple[str, dict, bool]]:
@@ -130,7 +137,7 @@ def __post_init__(self):
130137
default_factory=dict,
131138
metadata={
132139
"help": "Custom formats for reading notebook; suffix -> reader",
133-
"docutils_exclude": True,
140+
"omit": ["docutils"],
134141
"sections": (Section.global_lvl, Section.read),
135142
},
136143
)
@@ -184,10 +191,18 @@ def __post_init__(self):
184191
"validator": deep_mapping(instance_of(str), instance_of(str)),
185192
"help": "Mapping of kernel name regex to replacement kernel name"
186193
"(applied before execution)",
187-
"docutils_exclude": True,
194+
"omit": ["docutils"],
188195
"sections": (Section.global_lvl, Section.execute),
189196
},
190197
)
198+
eval_name_regex: str = dc.field(
199+
default=r"^[a-zA-Z_][a-zA-Z0-9_]*$",
200+
metadata={
201+
"validator": instance_of(str),
202+
"help": "Regex that matches permitted values of eval expressions",
203+
"sections": (Section.global_lvl, Section.file_lvl, Section.execute),
204+
},
205+
)
191206
execution_mode: Literal["off", "force", "auto", "cache", "inline"] = dc.field(
192207
default="auto",
193208
metadata={
@@ -220,7 +235,7 @@ def __post_init__(self):
220235
"validator": deep_iterable(instance_of(str)),
221236
"help": "Exclude (POSIX) glob patterns for notebooks",
222237
"legacy_name": "execution_excludepatterns",
223-
"docutils_exclude": True,
238+
"omit": ["docutils"],
224239
"sections": (Section.global_lvl, Section.execute),
225240
},
226241
)
@@ -387,7 +402,7 @@ def __post_init__(self):
387402
"help": "Overrides for the base render priority of mime types: "
388403
"list of (builder name, mime type, priority)",
389404
# TODO how to allow this in docutils?
390-
"docutils_exclude": True,
405+
"omit": ["docutils"],
391406
"sections": (Section.global_lvl, Section.file_lvl, Section.render),
392407
},
393408
repr=False,
@@ -454,7 +469,7 @@ def __post_init__(self):
454469
metadata={
455470
"validator": deep_mapping(instance_of(str), instance_of((str, int))),
456471
"help": "Options for image outputs (class|alt|height|width|scale|align)",
457-
"docutils_exclude": True,
472+
"omit": ["docutils"],
458473
# TODO backward-compatible change to "image_options"?
459474
"cell_key": "image",
460475
"sections": (
@@ -471,7 +486,7 @@ def __post_init__(self):
471486
metadata={
472487
"validator": deep_mapping(instance_of(str), instance_of((str, int))),
473488
"help": "Options for figure outputs (classes|name|caption|caption_before)",
474-
"docutils_exclude": True,
489+
"omit": ["docutils"],
475490
"cell_key": "figure",
476491
"sections": (
477492
Section.global_lvl,
@@ -505,7 +520,7 @@ def __post_init__(self):
505520
instance_of(str), deep_mapping(instance_of(str), instance_of(str))
506521
),
507522
"help": "Javascript to be loaded on pages containing ipywidgets",
508-
"docutils_exclude": True,
523+
"omit": ["docutils"],
509524
"sections": (Section.global_lvl, Section.render),
510525
},
511526
repr=False,
@@ -567,7 +582,7 @@ def get_cell_level_config(
567582
self,
568583
field_name: str,
569584
cell_metadata: Dict[str, Any],
570-
warning_callback: Callable[[str, str], Any],
585+
warning_callback: Callable[[str, MystNBWarnings], Any],
571586
) -> Any:
572587
"""Get a configuration value at the cell level.
573588
@@ -593,7 +608,7 @@ def get_cell_level_config(
593608
warning_callback(
594609
f"Deprecated `cell_metadata_key` 'render' "
595610
f"found, replace with {self.cell_metadata_key!r}",
596-
"cell_metadata_key",
611+
MystNBWarnings.CELL_METADATA_KEY,
597612
)
598613
cell_meta = cell_metadata["render"]
599614
else:
@@ -611,7 +626,10 @@ def get_cell_level_config(
611626
field.metadata["validator"](self, field, value)
612627
return value
613628
except Exception as exc:
614-
warning_callback(f"Cell metadata invalid: {exc}", "cell_config")
629+
warning_callback(
630+
f"Cell metadata invalid: {exc}",
631+
MystNBWarnings.CELL_CONFIG,
632+
)
615633

616634
# default/global/file level should have already been merged
617635
return getattr(self, field.name)

myst_nb/core/execute/base.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import annotations
33

44
from pathlib import Path
5-
import re
65
from typing import Any
76

87
from nbformat import NotebookNode
@@ -39,9 +38,6 @@ class EvalNameError(Exception):
3938
"""An exception for if an evaluation variable name is invalid."""
4039

4140

42-
EVAL_NAME_REGEX = re.compile(r"^[a-zA-Z_][a-zA-Z0-9_]*$")
43-
44-
4541
class NotebookClientBase:
4642
"""A base client for interacting with Jupyter notebooks.
4743

0 commit comments

Comments
 (0)