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:
3
CHANGES
3
CHANGES
@@ -131,6 +131,9 @@ New features added
|
|||||||
|
|
||||||
- Quickstart can now generate a Windows ``make.bat`` file.
|
- 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)
|
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
|
Do not output anything on standard output, also suppress warnings. Only
|
||||||
errors are written to standard error.
|
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**
|
**-P**
|
||||||
(Useful for debugging only.) Run the Python debugger, :mod:`pdb`, if an
|
(Useful for debugging only.) Run the Python debugger, :mod:`pdb`, if an
|
||||||
unhandled exception occurs while building.
|
unhandled exception occurs while building.
|
||||||
|
@@ -28,6 +28,10 @@ class SphinxError(Exception):
|
|||||||
"""
|
"""
|
||||||
category = 'Sphinx error'
|
category = 'Sphinx error'
|
||||||
|
|
||||||
|
class SphinxWarning(SphinxError):
|
||||||
|
"""Raised for warnings if warnings are treated as errors."""
|
||||||
|
category = 'Warning, treated as error'
|
||||||
|
|
||||||
class ExtensionError(SphinxError):
|
class ExtensionError(SphinxError):
|
||||||
"""Raised if something's wrong with the configuration."""
|
"""Raised if something's wrong with the configuration."""
|
||||||
category = 'Extension error'
|
category = 'Extension error'
|
||||||
@@ -78,7 +82,8 @@ CONFIG_FILENAME = 'conf.py'
|
|||||||
class Sphinx(object):
|
class Sphinx(object):
|
||||||
|
|
||||||
def __init__(self, srcdir, confdir, outdir, doctreedir, buildername,
|
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.next_listener_id = 0
|
||||||
self._listeners = {}
|
self._listeners = {}
|
||||||
self.builderclasses = BUILTIN_BUILDERS.copy()
|
self.builderclasses = BUILTIN_BUILDERS.copy()
|
||||||
@@ -95,11 +100,13 @@ class Sphinx(object):
|
|||||||
else:
|
else:
|
||||||
self._status = status
|
self._status = status
|
||||||
self.quiet = False
|
self.quiet = False
|
||||||
|
|
||||||
if warning is None:
|
if warning is None:
|
||||||
self._warning = StringIO()
|
self._warning = StringIO()
|
||||||
else:
|
else:
|
||||||
self._warning = warning
|
self._warning = warning
|
||||||
self._warncount = 0
|
self._warncount = 0
|
||||||
|
self.warningiserror = warningiserror
|
||||||
|
|
||||||
self._events = events.copy()
|
self._events = events.copy()
|
||||||
|
|
||||||
@@ -153,6 +160,8 @@ class Sphinx(object):
|
|||||||
self.builder.cleanup()
|
self.builder.cleanup()
|
||||||
|
|
||||||
def warn(self, message):
|
def warn(self, message):
|
||||||
|
if self.warningiserror:
|
||||||
|
raise SphinxWarning('WARNING: %s\n' % message)
|
||||||
self._warncount += 1
|
self._warncount += 1
|
||||||
try:
|
try:
|
||||||
self._warning.write('WARNING: %s\n' % message)
|
self._warning.write('WARNING: %s\n' % message)
|
||||||
|
@@ -44,6 +44,7 @@ new and changed files
|
|||||||
-N -- do not do colored output
|
-N -- do not do colored output
|
||||||
-q -- no output on stdout, just warnings on stderr
|
-q -- no output on stdout, just warnings on stderr
|
||||||
-Q -- no output at all, not even warnings
|
-Q -- no output at all, not even warnings
|
||||||
|
-W -- turn warnings into errors
|
||||||
-P -- run Pdb on exception
|
-P -- run Pdb on exception
|
||||||
Modi:
|
Modi:
|
||||||
* without -a and without filenames, write new and changed files.
|
* without -a and without filenames, write new and changed files.
|
||||||
@@ -57,7 +58,7 @@ def main(argv):
|
|||||||
nocolor()
|
nocolor()
|
||||||
|
|
||||||
try:
|
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)
|
allopts = set(opt[0] for opt in opts)
|
||||||
srcdir = confdir = path.abspath(args[0])
|
srcdir = confdir = path.abspath(args[0])
|
||||||
if not path.isdir(srcdir):
|
if not path.isdir(srcdir):
|
||||||
@@ -86,7 +87,7 @@ def main(argv):
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
buildername = all_files = None
|
buildername = all_files = None
|
||||||
freshenv = use_pdb = False
|
freshenv = warningiserror = use_pdb = False
|
||||||
status = sys.stdout
|
status = sys.stdout
|
||||||
warning = sys.stderr
|
warning = sys.stderr
|
||||||
confoverrides = {}
|
confoverrides = {}
|
||||||
@@ -143,13 +144,15 @@ def main(argv):
|
|||||||
elif opt == '-Q':
|
elif opt == '-Q':
|
||||||
status = None
|
status = None
|
||||||
warning = None
|
warning = None
|
||||||
|
elif opt == '-W':
|
||||||
|
warningiserror = True
|
||||||
elif opt == '-P':
|
elif opt == '-P':
|
||||||
use_pdb = True
|
use_pdb = True
|
||||||
confoverrides['html_context'] = htmlcontext
|
confoverrides['html_context'] = htmlcontext
|
||||||
|
|
||||||
try:
|
try:
|
||||||
app = Sphinx(srcdir, confdir, outdir, doctreedir, buildername,
|
app = Sphinx(srcdir, confdir, outdir, doctreedir, buildername,
|
||||||
confoverrides, status, warning, freshenv)
|
confoverrides, status, warning, freshenv, warningiserror)
|
||||||
app.build(all_files, filenames)
|
app.build(all_files, filenames)
|
||||||
return app.statuscode
|
return app.statuscode
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
Reference in New Issue
Block a user