Skip to content

Commit

Permalink
feat: For handler expected to return value
Browse files Browse the repository at this point in the history
  • Loading branch information
attakei committed Mar 17, 2024
1 parent 608eae3 commit 73d7f3b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/atsphinx/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def emit_only(
builders: Optional[List[str]] = None,
formats: Optional[List[str]] = None,
loglevel: int = logging.INFO,
return_alt: Any = None,
):
"""Restict event handler workings by builder types or formats.
Expand All @@ -91,6 +92,7 @@ def setup(app):
:params builders: List of builder names for restrict target.
:params formats: List of format types for restrict target.
:params return_alt: Return value if guard is worked.
"""
if builders is None and formats is None:
Logger.log(
Expand All @@ -108,13 +110,13 @@ def __only(app: Sphinx, *args, **kwargs) -> Any:
loglevel,
f"{func.__name__} is not supported '{app.builder.name}' builder.",
)
return
return return_alt
if formats and app.builder.format not in formats:
logger.log(
loglevel,
f"{func.__name__} is not supported '{app.builder.format}' format.",
)
return
return return_alt
return func(app, *args, **kwargs)

return __only
Expand Down

0 comments on commit 73d7f3b

Please sign in to comment.