Skip to content

Commit

Permalink
Update myst_nb/core/config.py to new warnings system
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Mitchell <yoshanuikabundi@gmail.com>
  • Loading branch information
agoose77 and Yoshanuikabundi committed Jun 23, 2023
1 parent 8b90dce commit 4396dfc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 8 additions & 3 deletions myst_nb/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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)
5 changes: 5 additions & 0 deletions myst_nb/warnings_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 4396dfc

Please sign in to comment.