diff --git a/myst_nb/core/config.py b/myst_nb/core/config.py index 1c7b2d36..2f73f607 100644 --- a/myst_nb/core/config.py +++ b/myst_nb/core/config.py @@ -14,6 +14,8 @@ ) from typing_extensions import Literal +from myst_nb.warnings_ import MystNBWarnings + def custom_formats_converter(value: dict) -> Dict[str, Tuple[str, dict, bool]]: """Convert the custom format dict.""" @@ -567,7 +569,7 @@ def get_cell_level_config( self, field_name: str, cell_metadata: Dict[str, Any], - warning_callback: Callable[[str, str], Any], + warning_callback: Callable[[str, MystNBWarnings], Any], ) -> Any: """Get a configuration value at the cell level. @@ -593,7 +595,7 @@ def get_cell_level_config( warning_callback( f"Deprecated `cell_metadata_key` 'render' " f"found, replace with {self.cell_metadata_key!r}", - "cell_metadata_key", + MystNBWarnings.CELL_METADATA_KEY, ) cell_meta = cell_metadata["render"] else: @@ -611,7 +613,10 @@ def get_cell_level_config( field.metadata["validator"](self, field, value) return value except Exception as exc: - warning_callback(f"Cell metadata invalid: {exc}", "cell_config") + warning_callback( + f"Cell metadata invalid: {exc}", + MystNBWarnings.CELL_CONFIG, + ) # default/global/file level should have already been merged return getattr(self, field.name) diff --git a/myst_nb/warnings_.py b/myst_nb/warnings_.py index 3679b2be..de8e66ce 100644 --- a/myst_nb/warnings_.py +++ b/myst_nb/warnings_.py @@ -29,6 +29,11 @@ class MystNBWarnings(Enum): OUTPUT_TYPE = "output_type" """Issue resolving Output type""" + CELL_METADATA_KEY = "cell_metadata_key" + """Issue with a key in a cell's `metadata` dictionary.""" + CELL_CONFIG = "cell_config" + """Issue with a cell's configuration or metadata.""" + def _is_suppressed_warning( type: str, subtype: str, suppress_warnings: Sequence[str]