airtai / nbdev-mkdocs

Extension to nbdev for generating docs with Material for Mkdocs
https://nbdev-mkdocs.airt.ai
Apache License 2.0
17 stars 2 forks source link

Heads up: Griffe's logger names are deprecated #218

Open pawamoy opened 4 months ago

pawamoy commented 4 months ago

Hello! Latest version of Griffe, 0.48, deprecated its logger names. Since it's not possible to detect usage of logger names, we can't emit deprecation warnings, so here am I giving you a heads up :slightly_smiling_face:

I see that you're getting the logger of the Google docstring parser module. Next version of Griffe, v1, will use a single name for all loggers (so, a global logger): "griffe".

But I suspect you don't want to disable all Griffe warning logs, and rather just the ones emitted when parsing docstrings. For this, v1 will let you import the Griffe logger and disable it temporarily:

import griffe

with griffe.logger.disable():
    sections = griffe.parse_google(griffe.Docstring(o.__doc__))

Since we can't allow a deprecation period where both uses are valid, here is a workaround while waiting for v1:

import logging
from contextlib import contextmanager

@contextmanager
def disable_logging(self, name: str) -> Iterator[None]:
    """Temporarily disable logging."""
    logger = logging.getLogger(name)
    old_level = logger.level
    logger.setLevel(100)
    try:
        yield
    finally:
        logger.setLevel(old_level)

This way, you don't use the deprecated logger name, and when upgrading to v1 it will still work. Then you can finally use griffe.logger.disable.

If anything is unclear, let me know!