summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sphinx/builders/latex/__init__.py1
-rw-r--r--sphinx/builders/latex/compat.py22
-rw-r--r--sphinx/deprecation.py30
-rw-r--r--sphinx/writers/latex.py12
4 files changed, 57 insertions, 8 deletions
diff --git a/sphinx/builders/latex/__init__.py b/sphinx/builders/latex/__init__.py
index a629d77b0..a3bc89161 100644
--- a/sphinx/builders/latex/__init__.py
+++ b/sphinx/builders/latex/__init__.py
@@ -13,6 +13,7 @@ from os import path
from docutils.frontend import OptionParser
+import sphinx.builders.latex.nodes # NOQA # Workaround: import this before writer to avoid ImportError
from sphinx import package_dir, addnodes, highlighting
from sphinx.builders import Builder
from sphinx.builders.latex.transforms import (
diff --git a/sphinx/builders/latex/compat.py b/sphinx/builders/latex/compat.py
new file mode 100644
index 000000000..d527e7688
--- /dev/null
+++ b/sphinx/builders/latex/compat.py
@@ -0,0 +1,22 @@
+"""
+ sphinx.builders.latex.compat
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ Compatibility module for LaTeX writer.
+ This module will be removed after deprecation period.
+ Don't use components in this modules directly.
+
+ :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+from sphinx.builders.latex.transforms import URI_SCHEMES, ShowUrlsTransform
+from sphinx.deprecation import RemovedInSphinx30Warning, deprecated_alias
+
+
+deprecated_alias('sphinx.writers.latex',
+ {
+ 'ShowUrlsTransform': ShowUrlsTransform,
+ 'URI_SCHEMES': URI_SCHEMES,
+ },
+ RemovedInSphinx30Warning)
diff --git a/sphinx/deprecation.py b/sphinx/deprecation.py
index bc346bff3..ea4099a93 100644
--- a/sphinx/deprecation.py
+++ b/sphinx/deprecation.py
@@ -8,7 +8,9 @@
:license: BSD, see LICENSE for details.
"""
+import sys
import warnings
+from importlib import import_module
if False:
# For type annotation
@@ -26,6 +28,34 @@ class RemovedInSphinx40Warning(PendingDeprecationWarning):
RemovedInNextVersionWarning = RemovedInSphinx30Warning
+def deprecated_alias(modname, objects, warning):
+ # type: (str, Dict, Type[Warning]) -> None
+ module = sys.modules.get(modname)
+ if module is None:
+ module = import_module(modname)
+
+ sys.modules[modname] = _ModuleWrapper(module, modname, objects, warning) # type: ignore
+
+
+class _ModuleWrapper(object):
+ def __init__(self, module, modname, objects, warning):
+ # type: (Any, str, Dict, Type[Warning]) -> None
+ self._module = module
+ self._modname = modname
+ self._objects = objects
+ self._warning = warning
+
+ def __getattr__(self, name):
+ # type: (str) -> Any
+ if name in self._objects:
+ warnings.warn("%s.%s is now deprecated. Please refer CHANGES to grasp"
+ "the changes of Sphinx API." % (self._modname, name),
+ self._warning, stacklevel=3)
+ return self._objects[name]
+
+ return getattr(self._module, name)
+
+
class DeprecatedDict(dict):
"""A deprecated dict which warns on each access."""
diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py
index 4e8ff4f4d..08d7e188f 100644
--- a/sphinx/writers/latex.py
+++ b/sphinx/writers/latex.py
@@ -23,6 +23,9 @@ from docutils.writers.latex2e import Babel
from sphinx import addnodes
from sphinx import highlighting
+from sphinx.builders.latex.nodes import (
+ HYPERLINK_SUPPORT_NODES, captioned_literal_block, footnotetext
+)
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
from sphinx.domains.std import StandardDomain
from sphinx.errors import SphinxError
@@ -2655,11 +2658,4 @@ class LaTeXTranslator(SphinxTranslator):
return visit_admonition
# Import old modules here for compatibility
-# They should be imported after `LaTeXTranslator` to avoid recursive import.
-#
-# refs: https://github.com/sphinx-doc/sphinx/issues/4889
-from sphinx.builders.latex.transforms import URI_SCHEMES, ShowUrlsTransform # NOQA
-
-# FIXME: Workaround to avoid circular import
-# refs: https://github.com/sphinx-doc/sphinx/issues/5433
-from sphinx.builders.latex.nodes import HYPERLINK_SUPPORT_NODES, captioned_literal_block, footnotetext # NOQA
+import sphinx.builders.latex.compat # NOQA