Skip to content

Commit 4396dfc

Browse files
Update myst_nb/core/config.py to new warnings system
Co-authored-by: Josh Mitchell <yoshanuikabundi@gmail.com>
1 parent 8b90dce commit 4396dfc

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

myst_nb/core/config.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
)
1515
from typing_extensions import Literal
1616

17+
from myst_nb.warnings_ import MystNBWarnings
18+
1719

1820
def custom_formats_converter(value: dict) -> Dict[str, Tuple[str, dict, bool]]:
1921
"""Convert the custom format dict."""
@@ -567,7 +569,7 @@ def get_cell_level_config(
567569
self,
568570
field_name: str,
569571
cell_metadata: Dict[str, Any],
570-
warning_callback: Callable[[str, str], Any],
572+
warning_callback: Callable[[str, MystNBWarnings], Any],
571573
) -> Any:
572574
"""Get a configuration value at the cell level.
573575
@@ -593,7 +595,7 @@ def get_cell_level_config(
593595
warning_callback(
594596
f"Deprecated `cell_metadata_key` 'render' "
595597
f"found, replace with {self.cell_metadata_key!r}",
596-
"cell_metadata_key",
598+
MystNBWarnings.CELL_METADATA_KEY,
597599
)
598600
cell_meta = cell_metadata["render"]
599601
else:
@@ -611,7 +613,10 @@ def get_cell_level_config(
611613
field.metadata["validator"](self, field, value)
612614
return value
613615
except Exception as exc:
614-
warning_callback(f"Cell metadata invalid: {exc}", "cell_config")
616+
warning_callback(
617+
f"Cell metadata invalid: {exc}",
618+
MystNBWarnings.CELL_CONFIG,
619+
)
615620

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

myst_nb/warnings_.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class MystNBWarnings(Enum):
2929
OUTPUT_TYPE = "output_type"
3030
"""Issue resolving Output type"""
3131

32+
CELL_METADATA_KEY = "cell_metadata_key"
33+
"""Issue with a key in a cell's `metadata` dictionary."""
34+
CELL_CONFIG = "cell_config"
35+
"""Issue with a cell's configuration or metadata."""
36+
3237

3338
def _is_suppressed_warning(
3439
type: str, subtype: str, suppress_warnings: Sequence[str]

0 commit comments

Comments
 (0)