diff --git a/CHANGES b/CHANGES index c5844d112..f80a760ea 100644 --- a/CHANGES +++ b/CHANGES @@ -185,6 +185,7 @@ Features added * Add ``app.add_html_math_renderer()`` to register a math renderer for HTML * Apply :confval:`trim_doctest_flags` to all builders (cf. text, manpages) * #5140: linkcheck: Add better Accept header to HTTP client +* #4614: sphinx-build: Add ``--keep-going`` option to show all warnings Bugs fixed ---------- diff --git a/doc/man/sphinx-build.rst b/doc/man/sphinx-build.rst index 72235efad..f7194a955 100644 --- a/doc/man/sphinx-build.rst +++ b/doc/man/sphinx-build.rst @@ -229,6 +229,13 @@ Options Turn warnings into errors. This means that the build stops at the first warning and ``sphinx-build`` exits with exit status 1. +.. option:: --keep-going + + With -W option, keep going processing when getting warnings to the end + of build, and ``sphinx-build`` exits with exit status 1. + + .. versionadded:: 1.8 + .. option:: -T Display the full traceback when an unhandled exception occurs. Otherwise, diff --git a/sphinx/application.py b/sphinx/application.py index 5da89dd31..5c6bfc52e 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -129,8 +129,8 @@ class Sphinx(object): def __init__(self, srcdir, confdir, outdir, doctreedir, buildername, confoverrides=None, status=sys.stdout, warning=sys.stderr, freshenv=False, warningiserror=False, tags=None, verbosity=0, - parallel=0): - # type: (unicode, unicode, unicode, unicode, unicode, Dict, IO, IO, bool, bool, List[unicode], int, int) -> None # NOQA + parallel=0, keep_going=False): + # type: (unicode, unicode, unicode, unicode, unicode, Dict, IO, IO, bool, bool, List[unicode], int, int, bool) -> None # NOQA self.phase = BuildPhase.INITIALIZATION self.verbosity = verbosity self.extensions = {} # type: Dict[unicode, Extension] @@ -173,7 +173,11 @@ class Sphinx(object): else: self._warning = warning self._warncount = 0 - self.warningiserror = warningiserror + self.keep_going = warningiserror and keep_going + if self.keep_going: + self.warningiserror = False + else: + self.warningiserror = warningiserror logging.setup(self, self._status, self._warning) self.events = EventManager() @@ -335,6 +339,9 @@ class Sphinx(object): self.builder.compile_update_catalogs() self.builder.build_update() + if self._warncount and self.keep_going: + self.statuscode = 1 + status = (self.statuscode == 0 and __('succeeded') or __('finished with problems')) if self._warncount: diff --git a/sphinx/cmd/build.py b/sphinx/cmd/build.py index f21a5ac45..7fc12e78a 100644 --- a/sphinx/cmd/build.py +++ b/sphinx/cmd/build.py @@ -189,6 +189,8 @@ files can be built by specifying individual filenames. help=__('write warnings (and errors) to given file')) group.add_argument('-W', action='store_true', dest='warningiserror', help=__('turn warnings into errors')) + group.add_argument('--keep-going', action='store_true', dest='keep_going', + help=__("With -W, Keep going when getting warnings")) group.add_argument('-T', action='store_true', dest='traceback', help=__('show full traceback on exception')) group.add_argument('-P', action='store_true', dest='pdb', @@ -298,7 +300,7 @@ def build_main(argv=sys.argv[1:]): # type: ignore app = Sphinx(args.sourcedir, args.confdir, args.outputdir, args.doctreedir, args.builder, confoverrides, status, warning, args.freshenv, args.warningiserror, - args.tags, args.verbosity, args.jobs) + args.tags, args.verbosity, args.jobs, args.keep_going) app.build(args.force_all, filenames) return app.statuscode except (Exception, KeyboardInterrupt) as exc: