Skip to content

Commit fe8a31f

Browse files
committed
Move build phase to the builder
1 parent bb5e545 commit fe8a31f

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
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 & 9 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
@@ -777,19 +779,19 @@ def _write_serial(self, docnames: Sequence[str]) -> None:
777779
self._app.verbosity,
778780
):
779781
_write_docname(
780-
docname, app=self._app, env=self.env, builder=self, tags=self.tags
782+
docname, env=self.env, builder=self, tags=self.tags
781783
)
782784

783785
def _write_parallel(self, docnames: Sequence[str], nproc: int) -> None:
784786
def write_process(docs: list[tuple[str, nodes.document]]) -> None:
785-
self._app.phase = BuildPhase.WRITING
787+
self.phase = BuildPhase.WRITING
786788
for docname, doctree in docs:
787789
self.write_doc(docname, doctree)
788790

789791
# warm up caches/compile templates using the first document
790792
firstname, docnames = docnames[0], docnames[1:]
791793
_write_docname(
792-
firstname, app=self._app, env=self.env, builder=self, tags=self.tags
794+
firstname, env=self.env, builder=self, tags=self.tags
793795
)
794796

795797
tasks = ParallelTasks(nproc)
@@ -808,7 +810,7 @@ def write_process(docs: list[tuple[str, nodes.document]]) -> None:
808810
def on_chunk_done(args: list[tuple[str, nodes.document]], result: None) -> None:
809811
next(progress)
810812

811-
self._app.phase = BuildPhase.RESOLVING
813+
self.phase = BuildPhase.RESOLVING
812814
for chunk in chunks:
813815
arg = []
814816
for docname in chunk:
@@ -884,15 +886,14 @@ def _write_docname(
884886
docname: str,
885887
/,
886888
*,
887-
app: Sphinx,
888889
env: BuildEnvironment,
889890
builder: Builder,
890891
tags: Tags,
891892
) -> None:
892893
"""Write a single document."""
893-
app.phase = BuildPhase.RESOLVING
894+
builder.phase = BuildPhase.RESOLVING
894895
doctree = env.get_and_resolve_doctree(docname, builder=builder, tags=tags)
895-
app.phase = BuildPhase.WRITING
896+
builder.phase = BuildPhase.WRITING
896897
builder.write_doc_serialized(docname, doctree)
897898
builder.write_doc(docname, doctree)
898899

0 commit comments

Comments
 (0)