mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
There is now a `-W
` option for sphinx-build that turns warnings into errors.
^
This commit is contained in:
parent
03a9656c72
commit
905ed46696
3
CHANGES
3
CHANGES
@ -131,6 +131,9 @@ New features added
|
||||
|
||||
- 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)
|
||||
==============================
|
||||
|
@ -133,6 +133,10 @@ The :program:`sphinx-build` script has several more options:
|
||||
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.
|
||||
|
@ -28,6 +28,10 @@ class SphinxError(Exception):
|
||||
"""
|
||||
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'
|
||||
@ -78,7 +82,8 @@ CONFIG_FILENAME = 'conf.py'
|
||||
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()
|
||||
@ -95,11 +100,13 @@ class Sphinx(object):
|
||||
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()
|
||||
|
||||
@ -153,6 +160,8 @@ class Sphinx(object):
|
||||
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)
|
||||
|
@ -44,6 +44,7 @@ new and changed files
|
||||
-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.
|
||||
@ -57,7 +58,7 @@ def main(argv):
|
||||
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):
|
||||
@ -86,7 +87,7 @@ def main(argv):
|
||||
return 1
|
||||
|
||||
buildername = all_files = None
|
||||
freshenv = use_pdb = False
|
||||
freshenv = warningiserror = use_pdb = False
|
||||
status = sys.stdout
|
||||
warning = sys.stderr
|
||||
confoverrides = {}
|
||||
@ -143,13 +144,15 @@ def main(argv):
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user