Skip to content

Commit

Permalink
feat: Skip consistency checking
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverRainZ committed Oct 18, 2024
1 parent 6fbf33b commit 3db58e5
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/sphinxnotes/fasthtml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
TODO:
- [ ] skip 'checking consistency'
- [ ] config-able.
"""
Expand All @@ -20,6 +19,9 @@
from sphinx.builders.html import StandaloneHTMLBuilder
from sphinx.util import logging
from sphinx.environment import CONFIG_CHANGED, CONFIG_EXTENSIONS_CHANGED
from sphinx.util.display import progress_message, SkipProgressMessage
from sphinx.locale import __


if TYPE_CHECKING:
from sphinx.application import Sphinx
Expand Down Expand Up @@ -53,6 +55,11 @@ def __init__(self, app: Sphinx, env: BuildEnvironment) -> None:
def gen_pages_from_extensions(self) -> None:
pass # skip gen

@progress_message(__('writing additional pages'))
def gen_additional_pages(self) -> None:
raise SkipProgressMessage


def _overwrite_config(self) -> None:
"""
Overwrite sphinx.config.Config to skip some operations that slow down
Expand Down Expand Up @@ -104,16 +111,39 @@ def _on_builder_inited(app: Sphinx):
app.env.reread_always = set() # marked by env.note_reread()


original_check_consistency = None
"""Original value of :meth:`BuildEnvironment.check_consistency`."""


def dummy_check_consistency() -> None:
"""Used to skip the consistency checking of Sphinx by overwriting
:meth:`BuildEnvironment.check_consistency`.
The function is called from :meth:`Builder.build`.
"""
raise SkipProgressMessage


def _on_env_get_outdated(
app: Sphinx,
env: BuildEnvironment,
added: set[str],
changed: set[str],
removed: set[str],
) -> list[str]:
global original_check_consistency
if not isinstance(app.builder, FastHTMLBuilder):
# Restore check_consistency method.
if env.check_consistency == dummy_check_consistency:
env.check_consistency = original_check_consistency
return []

# Overwrite :meth:`BuildEnvironment.check_consistency` to skip consistency
# checking.
if env.check_consistency != dummy_check_consistency:
original_check_consistency = env.check_consistency
env.check_consistency = dummy_check_consistency

# Do not trigger a full rebuild when config changed.
if env.config_status in [CONFIG_CHANGED, CONFIG_EXTENSIONS_CHANGED]:
# Require the env to re-calculate which docs should be rebuilt when the
Expand Down

0 comments on commit 3db58e5

Please sign in to comment.