Commits

Georg Brandl committed 604814c

There is now a ``-W`` option for sphinx-build that turns warnings into errors.
^

  • Participants
  • Parent commits 3b27d46

Comments (0)

Files changed (4)

 
   - Quickstart can now generate a Windows ``make.bat`` file.
 
+  - There is now a ``-W`` option for sphinx-build that turns warnings
+    into errors.
+
 
 Release 0.5.2 (in development)
 ==============================

File doc/intro.rst

    Do not output anything on standard output, also suppress warnings.  Only
    errors are written to standard error.
 
+**-W**
+   Turn warnings into errors.  This means that the build stops at the first
+   warning and ``sphinx-build`` exits with exit status 1.
+
 **-P**
    (Useful for debugging only.)  Run the Python debugger, :mod:`pdb`, if an
    unhandled exception occurs while building.

File sphinx/application.py

     """
     category = 'Sphinx error'
 
+class SphinxWarning(SphinxError):
+    """Raised for warnings if warnings are treated as errors."""
+    category = 'Warning, treated as error'
+
 class ExtensionError(SphinxError):
     """Raised if something's wrong with the configuration."""
     category = 'Extension error'
 class Sphinx(object):
 
     def __init__(self, srcdir, confdir, outdir, doctreedir, buildername,
-                 confoverrides, status, warning=sys.stderr, freshenv=False):
+                 confoverrides, status, warning=sys.stderr, freshenv=False,
+                 warningiserror=False):
         self.next_listener_id = 0
         self._listeners = {}
         self.builderclasses = BUILTIN_BUILDERS.copy()
         else:
             self._status = status
             self.quiet = False
+
         if warning is None:
             self._warning = StringIO()
         else:
             self._warning = warning
         self._warncount = 0
+        self.warningiserror = warningiserror
 
         self._events = events.copy()
 
         self.builder.cleanup()
 
     def warn(self, message):
+        if self.warningiserror:
+            raise SphinxWarning('WARNING: %s\n' % message)
         self._warncount += 1
         try:
             self._warning.write('WARNING: %s\n' % message)

File sphinx/cmdline.py

          -N        -- do not do colored output
          -q        -- no output on stdout, just warnings on stderr
          -Q        -- no output at all, not even warnings
+         -W        -- turn warnings into errors
          -P        -- run Pdb on exception
 Modi:
 * without -a and without filenames, write new and changed files.
         nocolor()
 
     try:
-        opts, args = getopt.getopt(argv[1:], 'ab:d:c:CD:A:NEqQP')
+        opts, args = getopt.getopt(argv[1:], 'ab:d:c:CD:A:NEqQWP')
         allopts = set(opt[0] for opt in opts)
         srcdir = confdir = path.abspath(args[0])
         if not path.isdir(srcdir):
         return 1
 
     buildername = all_files = None
-    freshenv = use_pdb = False
+    freshenv = warningiserror = use_pdb = False
     status = sys.stdout
     warning = sys.stderr
     confoverrides = {}
         elif opt == '-Q':
             status = None
             warning = None
+        elif opt == '-W':
+            warningiserror = True
         elif opt == '-P':
             use_pdb = True
     confoverrides['html_context'] = htmlcontext
 
     try:
         app = Sphinx(srcdir, confdir, outdir, doctreedir, buildername,
-                     confoverrides, status, warning, freshenv)
+                     confoverrides, status, warning, freshenv, warningiserror)
         app.build(all_files, filenames)
         return app.statuscode
     except KeyboardInterrupt: