Skip to content

Commit

Permalink
Merge pull request #9144 from tk0miya/refactor_linkcheck2
Browse files Browse the repository at this point in the history
refactor: linkcheck: Call write_linkstat() at the top of process_result()
  • Loading branch information
tk0miya committed Apr 30, 2021
2 parents 55b55fd + 29038c9 commit d656aca
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions sphinx/builders/linkcheck.py
Expand Up @@ -230,14 +230,15 @@ def wqueue(self, response: Response) -> Queue:

def process_result(self, result: CheckResult) -> None:
filename = self.env.doc2path(result.docname, None)

linkstat = dict(filename=filename, lineno=result.lineno,
status=result.status, code=result.code, uri=result.uri,
info=result.message)
self.write_linkstat(linkstat)

if result.status == 'unchecked':
self.write_linkstat(linkstat)
return
if result.status == 'working' and result.message == 'old':
self.write_linkstat(linkstat)
return
if result.lineno:
logger.info('(%16s: line %4d) ', result.docname, result.lineno, nonl=True)
Expand All @@ -246,14 +247,11 @@ def process_result(self, result: CheckResult) -> None:
logger.info(darkgray('-ignored- ') + result.uri + ': ' + result.message)
else:
logger.info(darkgray('-ignored- ') + result.uri)
self.write_linkstat(linkstat)
elif result.status == 'local':
logger.info(darkgray('-local- ') + result.uri)
self.write_entry('local', result.docname, filename, result.lineno, result.uri)
self.write_linkstat(linkstat)
elif result.status == 'working':
logger.info(darkgreen('ok ') + result.uri + result.message)
self.write_linkstat(linkstat)
elif result.status == 'broken':
if self.app.quiet or self.app.warningiserror:
logger.warning(__('broken link: %s (%s)'), result.uri, result.message,
Expand All @@ -262,7 +260,6 @@ def process_result(self, result: CheckResult) -> None:
logger.info(red('broken ') + result.uri + red(' - ' + result.message))
self.write_entry('broken', result.docname, filename, result.lineno,
result.uri + ': ' + result.message)
self.write_linkstat(linkstat)
elif result.status == 'redirected':
try:
text, color = {
Expand All @@ -279,7 +276,6 @@ def process_result(self, result: CheckResult) -> None:
color(' - ' + text + ' to ' + result.message))
self.write_entry('redirected ' + text, result.docname, filename,
result.lineno, result.uri + ' to ' + result.message)
self.write_linkstat(linkstat)
else:
raise ValueError("Unknown status %s." % result.status)

Expand Down

0 comments on commit d656aca

Please sign in to comment.