From 3afc72fba41f945610263be79d14c95d21478248 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 3 Apr 2018 23:55:39 +0900 Subject: [PATCH] Rename add_stylesheet() to add_css_file() --- CHANGES | 2 +- doc/extdev/index.rst | 5 +++++ sphinx/application.py | 38 +++++++++++++++++++++++++++----------- sphinx/deprecation.py | 4 ++++ 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index 42af691ae..0788e1c77 100644 --- a/CHANGES +++ b/CHANGES @@ -35,6 +35,7 @@ Deprecated * #2157: helper function ``warn()`` for HTML themes is deprecated * ``env._nitpick_ignore`` is deprecated * ``app.override_domain()`` is deprecated +* ``app.add_stylesheet()`` is deprecated For more details, see `deprecation APIs list `_ @@ -58,7 +59,6 @@ Features added * LaTeX: new key ``'fvset'`` for :confval:`latex_elements`. For XeLaTeX/LuaLaTeX its default sets ``fanvyvrb`` to use normal, not small, fontsize in code-blocks (refs: #4793) -* ``app.add_stylesheet()`` allows additional attributes Bugs fixed ---------- diff --git a/doc/extdev/index.rst b/doc/extdev/index.rst index 78414cd09..a4776275f 100644 --- a/doc/extdev/index.rst +++ b/doc/extdev/index.rst @@ -113,6 +113,11 @@ The following is a list of deprecated interface. - (will be) Removed - Alternatives + * - :meth:`~sphinx.application.Sphinx.add_stylesheet()` + - 1.8 + - 4.0 + - :meth:`~sphinx.application.Sphinx.add_css_file()` + * - ``sphinx.application.Sphinx.override_domain()`` - 1.8 - 3.0 diff --git a/sphinx/application.py b/sphinx/application.py index d089fd3e6..d19744cf7 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -27,7 +27,9 @@ from six.moves import cStringIO import sphinx from sphinx import package_dir, locale from sphinx.config import Config -from sphinx.deprecation import RemovedInSphinx20Warning, RemovedInSphinx30Warning +from sphinx.deprecation import ( + RemovedInSphinx20Warning, RemovedInSphinx30Warning, RemovedInSphinx40Warning +) from sphinx.environment import BuildEnvironment from sphinx.errors import ( ApplicationError, ConfigError, ExtensionError, VersionRequirementError @@ -1001,7 +1003,7 @@ class Sphinx(object): StandaloneHTMLBuilder.script_files.append( posixpath.join('_static', filename)) - def add_stylesheet(self, filename, **kwargs): + def add_css_file(self, filename, **kwargs): # type: (unicode, **unicode) -> None """Register a stylesheet to include in the HTML output. @@ -1012,14 +1014,14 @@ class Sphinx(object): Example:: - app.add_stylesheet('custom.css') + app.add_css_file('custom.css') # => - app.add_stylesheet('print.css', media='print') + app.add_css_file('print.css', media='print') # => - app.add_stylesheet('fancy.css', rel='alternate stylesheet', title='fancy') + app.add_css_file('fancy.css', rel='alternate stylesheet', title='fancy') # => @@ -1033,18 +1035,32 @@ class Sphinx(object): `__. .. versionchanged:: 1.8 - Allows keyword arguments as attributes of link tag. + Renamed from ``app.add_stylesheet()``. + And it allows keyword arguments as attributes of link tag. """ logger.debug('[app] adding stylesheet: %r', filename) if '://' not in filename: filename = posixpath.join('_static', filename) - if kwargs.pop('alternate', None): - warnings.warn('The alternate option for app.add_stylesheet() is deprecated. ' - 'Please use rel="alternate stylesheet" option instead.', - RemovedInSphinx30Warning) - kwargs['rel'] = 'alternate stylesheet' self.registry.add_css_files(filename, **kwargs) + def add_stylesheet(self, filename, alternate=False, title=None): + # type: (unicode, bool, unicode) -> None + """An alias of :meth:`add_css_file`.""" + warnings.warn('The app.add_stylesheet() is deprecated. ' + 'Please use app.add_css_file() instead.', + RemovedInSphinx40Warning) + + attributes = {} # type: Dict[unicode, unicode] + if alternate: + attributes['rel'] = 'alternate stylesheet' + else: + attributes['rel'] = 'stylesheet' + + if title: + attributes['title'] = title + + self.add_css_file(filename, **attributes) + def add_latex_package(self, packagename, options=None): # type: (unicode, unicode) -> None r"""Register a package to include in the LaTeX source code. diff --git a/sphinx/deprecation.py b/sphinx/deprecation.py index 1b0e862f0..d4067055a 100644 --- a/sphinx/deprecation.py +++ b/sphinx/deprecation.py @@ -33,6 +33,10 @@ class RemovedInSphinx30Warning(PendingDeprecationWarning): pass +class RemovedInSphinx40Warning(PendingDeprecationWarning): + pass + + RemovedInNextVersionWarning = RemovedInSphinx18Warning