Skip to content

Commit a536639

Browse files
authored
Move build phase to the builder (#13645)
1 parent bb5e545 commit a536639

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

sphinx/application.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ def __init__(
196196
:param pdb: If true, enable the Python debugger on an exception.
197197
:param exception_on_warning: If true, raise an exception on warnings.
198198
"""
199-
self.phase = BuildPhase.INITIALIZATION
200199
self.verbosity = verbosity
201200
self._fresh_env_used: bool | None = None
202201
self.extensions: dict[str, Extension] = {}
@@ -340,6 +339,12 @@ def fresh_env_used(self) -> bool | None:
340339
"""
341340
return self._fresh_env_used
342341

342+
@property
343+
def phase(self) -> BuildPhase:
344+
if not hasattr(self, 'builder'):
345+
return BuildPhase.INITIALIZATION
346+
return self.builder.phase
347+
343348
def _init_i18n(self) -> None:
344349
"""Load translated strings from the configured localedirs if enabled in
345350
the configuration.
@@ -420,7 +425,7 @@ def _init_builder(self) -> None:
420425
# ---- main "build" method -------------------------------------------------
421426

422427
def build(self, force_all: bool = False, filenames: Sequence[Path] = ()) -> None:
423-
self.phase = BuildPhase.READING
428+
self.builder.phase = BuildPhase.READING
424429
try:
425430
if force_all:
426431
self.builder.build_all()

sphinx/builders/__init__.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class Builder:
103103
#: The file format produced by the builder allows images to be embedded using data-URIs.
104104
supported_data_uri_images: ClassVar[bool] = False
105105

106+
phase: BuildPhase = BuildPhase.INITIALIZATION
107+
106108
srcdir = _StrPathProperty()
107109
confdir = _StrPathProperty()
108110
outdir = _StrPathProperty()
@@ -431,14 +433,14 @@ def build(
431433
pickle.dump(self.env, f, pickle.HIGHEST_PROTOCOL)
432434

433435
# global actions
434-
self._app.phase = BuildPhase.CONSISTENCY_CHECK
436+
self.phase = BuildPhase.CONSISTENCY_CHECK
435437
with progress_message(__('checking consistency')):
436438
self.env.check_consistency()
437439
else:
438440
if method == 'update' and not docnames:
439441
logger.info(bold(__('no targets are out of date.')))
440442

441-
self._app.phase = BuildPhase.RESOLVING
443+
self.phase = BuildPhase.RESOLVING
442444

443445
# filter "docnames" (list of outdated files) by the updated
444446
# found_docs of the environment; this will remove docs that
@@ -776,21 +778,17 @@ def _write_serial(self, docnames: Sequence[str]) -> None:
776778
len(docnames),
777779
self._app.verbosity,
778780
):
779-
_write_docname(
780-
docname, app=self._app, env=self.env, builder=self, tags=self.tags
781-
)
781+
_write_docname(docname, env=self.env, builder=self, tags=self.tags)
782782

783783
def _write_parallel(self, docnames: Sequence[str], nproc: int) -> None:
784784
def write_process(docs: list[tuple[str, nodes.document]]) -> None:
785-
self._app.phase = BuildPhase.WRITING
785+
self.phase = BuildPhase.WRITING
786786
for docname, doctree in docs:
787787
self.write_doc(docname, doctree)
788788

789789
# warm up caches/compile templates using the first document
790790
firstname, docnames = docnames[0], docnames[1:]
791-
_write_docname(
792-
firstname, app=self._app, env=self.env, builder=self, tags=self.tags
793-
)
791+
_write_docname(firstname, env=self.env, builder=self, tags=self.tags)
794792

795793
tasks = ParallelTasks(nproc)
796794
chunks = make_chunks(docnames, nproc)
@@ -808,7 +806,7 @@ def write_process(docs: list[tuple[str, nodes.document]]) -> None:
808806
def on_chunk_done(args: list[tuple[str, nodes.document]], result: None) -> None:
809807
next(progress)
810808

811-
self._app.phase = BuildPhase.RESOLVING
809+
self.phase = BuildPhase.RESOLVING
812810
for chunk in chunks:
813811
arg = []
814812
for docname in chunk:
@@ -884,15 +882,14 @@ def _write_docname(
884882
docname: str,
885883
/,
886884
*,
887-
app: Sphinx,
888885
env: BuildEnvironment,
889886
builder: Builder,
890887
tags: Tags,
891888
) -> None:
892889
"""Write a single document."""
893-
app.phase = BuildPhase.RESOLVING
890+
builder.phase = BuildPhase.RESOLVING
894891
doctree = env.get_and_resolve_doctree(docname, builder=builder, tags=tags)
895-
app.phase = BuildPhase.WRITING
892+
builder.phase = BuildPhase.WRITING
896893
builder.write_doc_serialized(docname, doctree)
897894
builder.write_doc(docname, doctree)
898895

0 commit comments

Comments
 (0)