mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #2687: Uninstall sphinx directives and roles after build
This commit is contained in:
1
CHANGES
1
CHANGES
@@ -141,6 +141,7 @@ Bugs fixed
|
||||
* #1734: Could not translate the caption of toctree directive
|
||||
* Could not translate the content of meta directive (ref: #1734)
|
||||
* #2550: external links are opened in help viewer
|
||||
* #2687: Running Sphinx multiple times produces 'already registered' warnings
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
@@ -23,6 +23,7 @@ from sphinx.errors import SphinxError
|
||||
from sphinx.application import Sphinx
|
||||
from sphinx.util import Tee, format_exception_cut_frames, save_traceback
|
||||
from sphinx.util.console import red, nocolor, color_terminal
|
||||
from sphinx.util.docutils import docutils_namespace
|
||||
from sphinx.util.osutil import abspath, fs_encoding
|
||||
from sphinx.util.pycompat import terminal_safe
|
||||
|
||||
@@ -288,11 +289,12 @@ def main(argv):
|
||||
|
||||
app = None
|
||||
try:
|
||||
app = Sphinx(srcdir, confdir, outdir, doctreedir, opts.builder,
|
||||
confoverrides, status, warning, opts.freshenv,
|
||||
opts.warningiserror, opts.tags, opts.verbosity, opts.jobs)
|
||||
app.build(opts.force_all, filenames)
|
||||
return app.statuscode
|
||||
with docutils_namespace():
|
||||
app = Sphinx(srcdir, confdir, outdir, doctreedir, opts.builder,
|
||||
confoverrides, status, warning, opts.freshenv,
|
||||
opts.warningiserror, opts.tags, opts.verbosity, opts.jobs)
|
||||
app.build(opts.force_all, filenames)
|
||||
return app.statuscode
|
||||
except (Exception, KeyboardInterrupt) as exc:
|
||||
handle_exception(app, opts, exc, error)
|
||||
return 1
|
||||
|
@@ -23,6 +23,7 @@ from distutils.errors import DistutilsOptionError, DistutilsExecError
|
||||
from sphinx.application import Sphinx
|
||||
from sphinx.cmdline import handle_exception
|
||||
from sphinx.util.console import nocolor, color_terminal
|
||||
from sphinx.util.docutils import docutils_namespace
|
||||
from sphinx.util.osutil import abspath
|
||||
|
||||
|
||||
@@ -165,15 +166,16 @@ class BuildDoc(Command):
|
||||
confoverrides['copyright'] = self.copyright
|
||||
|
||||
try:
|
||||
app = Sphinx(self.source_dir, self.config_dir,
|
||||
self.builder_target_dir, self.doctree_dir,
|
||||
self.builder, confoverrides, status_stream,
|
||||
freshenv=self.fresh_env,
|
||||
warningiserror=self.warning_is_error)
|
||||
app.build(force_all=self.all_files)
|
||||
if app.statuscode:
|
||||
raise DistutilsExecError(
|
||||
'caused by %s builder.' % app.builder.name)
|
||||
with docutils_namespace():
|
||||
app = Sphinx(self.source_dir, self.config_dir,
|
||||
self.builder_target_dir, self.doctree_dir,
|
||||
self.builder, confoverrides, status_stream,
|
||||
freshenv=self.fresh_env,
|
||||
warningiserror=self.warning_is_error)
|
||||
app.build(force_all=self.all_files)
|
||||
if app.statuscode:
|
||||
raise DistutilsExecError(
|
||||
'caused by %s builder.' % app.builder.name)
|
||||
except Exception as exc:
|
||||
handle_exception(app, self, exc, sys.stderr)
|
||||
if not self.pdb:
|
||||
|
@@ -8,6 +8,7 @@
|
||||
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
import re
|
||||
|
@@ -8,6 +8,8 @@
|
||||
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import warnings
|
||||
|
||||
from docutils import nodes
|
||||
|
@@ -9,6 +9,7 @@
|
||||
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from docutils import nodes
|
||||
|
||||
|
28
sphinx/util/docutils.py
Normal file
28
sphinx/util/docutils.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
sphinx.util.docutils
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Utility functions for docutils.
|
||||
|
||||
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from copy import copy
|
||||
from contextlib import contextmanager
|
||||
from docutils.parsers.rst import directives, roles
|
||||
|
||||
|
||||
@contextmanager
|
||||
def docutils_namespace():
|
||||
"""Create namespace for reST parsers."""
|
||||
try:
|
||||
_directives = copy(directives._directives)
|
||||
_roles = copy(roles._roles)
|
||||
|
||||
yield
|
||||
finally:
|
||||
directives._directives = _directives
|
||||
roles._roles = _roles
|
@@ -8,6 +8,8 @@
|
||||
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
import codecs
|
||||
import posixpath
|
||||
|
@@ -8,6 +8,7 @@
|
||||
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import re
|
||||
|
||||
|
Reference in New Issue
Block a user