Skip to content

Commit

Permalink
Move custom_admonitions monkey patching out of extension setup function
Browse files Browse the repository at this point in the history
This ensures it is not redundantly patched if the extension is loaded
more than once in a given process (only really relevant for tests).
  • Loading branch information
jbms committed Jan 22, 2023
1 parent 4ea9b28 commit a0647ca
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sphinx_immaterial/custom_admonitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def depart_admonition(self: HTML5Translator, node: Optional[nodes.Element] = Non
HTML5Translator.depart_admonition = depart_admonition # type: ignore[assignment]


patch_visit_admonition()
patch_depart_admonition()


class CustomAdmonitionDirective(Directive, ABC):
"""A base class to define custom admonition directives.
Expand Down Expand Up @@ -364,9 +368,6 @@ def setup(app: Sphinx):
app.connect("env-check-consistency", add_admonition_and_icon_css)
app.connect("config-inited", on_config_inited)

patch_visit_admonition()
patch_depart_admonition()

return {
"parallel_read_safe": True,
"parallel_write_safe": True,
Expand Down

0 comments on commit a0647ca

Please sign in to comment.