Skip to content

Commit

Permalink
Fix #10110: sphinx-build: Emit builder-finished before shutdown
Browse files Browse the repository at this point in the history
The error on the builder-finished event has been ignored for the
calculation of the exit code.  This emits the event earilier step to be
calculated correctly.
  • Loading branch information
tk0miya committed May 15, 2022
1 parent 23ab36b commit 6065ab6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Expand Up @@ -16,6 +16,9 @@ Features added
Bugs fixed
----------

* #10110: sphinx-build: exit code is not changed when error is raised on
builder-finished event

Testing
--------

Expand Down
57 changes: 29 additions & 28 deletions sphinx/application.py
Expand Up @@ -328,42 +328,43 @@ def build(self, force_all: bool = False, filenames: List[str] = None) -> None:
self.builder.compile_update_catalogs()
self.builder.build_update()

if self._warncount and self.keep_going:
self.statuscode = 1

status = (__('succeeded') if self.statuscode == 0
else __('finished with problems'))
if self._warncount:
if self.warningiserror:
if self._warncount == 1:
msg = __('build %s, %s warning (with warnings treated as errors).')
else:
msg = __('build %s, %s warnings (with warnings treated as errors).')
else:
if self._warncount == 1:
msg = __('build %s, %s warning.')
else:
msg = __('build %s, %s warnings.')

logger.info(bold(msg % (status, self._warncount)))
else:
logger.info(bold(__('build %s.') % status))

if self.statuscode == 0 and self.builder.epilog:
logger.info('')
logger.info(self.builder.epilog % {
'outdir': relpath(self.outdir),
'project': self.config.project
})
self.events.emit('build-finished', None)
except Exception as err:
# delete the saved env to force a fresh build next time
envfile = path.join(self.doctreedir, ENV_PICKLE_FILENAME)
if path.isfile(envfile):
os.unlink(envfile)
self.events.emit('build-finished', err)
raise

if self._warncount and self.keep_going:
self.statuscode = 1

status = (__('succeeded') if self.statuscode == 0
else __('finished with problems'))
if self._warncount:
if self.warningiserror:
if self._warncount == 1:
msg = __('build %s, %s warning (with warnings treated as errors).')
else:
msg = __('build %s, %s warnings (with warnings treated as errors).')
else:
if self._warncount == 1:
msg = __('build %s, %s warning.')
else:
msg = __('build %s, %s warnings.')

logger.info(bold(msg % (status, self._warncount)))
else:
self.events.emit('build-finished', None)
logger.info(bold(__('build %s.') % status))

if self.statuscode == 0 and self.builder.epilog:
logger.info('')
logger.info(self.builder.epilog % {
'outdir': relpath(self.outdir),
'project': self.config.project
})

self.builder.cleanup()

# ---- general extensibility interface -------------------------------------
Expand Down

0 comments on commit 6065ab6

Please sign in to comment.