From b3f596a1330137cf34bc9163cbeebba52ab511e5 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 25 Apr 2017 01:16:19 +0900 Subject: [PATCH 1/2] Fix #3662: ``builder.css_files`` is deprecated --- CHANGES | 3 +++ sphinx/builders/html.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 0d72fa989..2e4e6f676 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,9 @@ Incompatible changes Deprecated ---------- +* #3662: ``builder.css_files`` is deprecated. Please use ``add_stylesheet()`` + API instead. + Features added -------------- diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index 7369ea23d..cea14965a 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -13,6 +13,7 @@ import os import re import sys import codecs +import warnings import posixpath from os import path from hashlib import md5 @@ -38,6 +39,7 @@ from sphinx.util.docutils import is_html5_writer_available, __version_info__ from sphinx.util.fileutil import copy_asset from sphinx.util.matching import patmatch, Matcher, DOTFILES from sphinx.config import string_classes +from sphinx.deprecation import RemovedInSphinx20Warning from sphinx.locale import _, l_ from sphinx.search import js_index from sphinx.theming import HTMLThemeFactory @@ -87,6 +89,35 @@ def get_stable_hash(obj): return md5(text_type(obj).encode('utf8')).hexdigest() +class CSSContainer(list): + """The container of stylesheets. + + To support the extensions which access the container directly, this wraps + the entry with Stylesheet class. + """ + def append(self, obj): + warnings.warn('builder.css_files is deprecated. ' + 'Please use app.add_stylesheet() instead.', + RemovedInSphinx20Warning) + if isinstance(obj, Stylesheet): + super(CSSContainer, self).append(obj) + else: + super(CSSContainer, self).append(Stylesheet(obj, None, 'stylesheet')) + + def extend(self, other): + for item in other: + self.append(item) + + def __iadd__(self, other): + for item in other: + self.append(item) + + def __add__(self, other): + ret = CSSContainer(self) + ret += other + return ret + + class Stylesheet(text_type): """The metadata of stylesheet. @@ -136,7 +167,7 @@ class StandaloneHTMLBuilder(Builder): script_files = ['_static/jquery.js', '_static/underscore.js', '_static/doctools.js'] # type: List[unicode] # Ditto for this one (Sphinx.add_stylesheet). - css_files = [] # type: List[Dict[unicode, unicode]] + css_files = CSSContainer() # type: List[Dict[unicode, unicode]] imgpath = None # type: unicode domain_indices = [] # type: List[Tuple[unicode, Type[Index], List[Tuple[unicode, List[List[Union[unicode, int]]]]], bool]] # NOQA From 02ff0863c671c2468b9c841b5a362eb7435bb4b2 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 27 Apr 2017 00:33:40 +0900 Subject: [PATCH 2/2] Move deprecation warning --- sphinx/builders/html.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index cea14965a..a356c5f23 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -96,19 +96,22 @@ class CSSContainer(list): the entry with Stylesheet class. """ def append(self, obj): - warnings.warn('builder.css_files is deprecated. ' - 'Please use app.add_stylesheet() instead.', - RemovedInSphinx20Warning) if isinstance(obj, Stylesheet): super(CSSContainer, self).append(obj) else: super(CSSContainer, self).append(Stylesheet(obj, None, 'stylesheet')) def extend(self, other): + warnings.warn('builder.css_files is deprecated. ' + 'Please use app.add_stylesheet() instead.', + RemovedInSphinx20Warning) for item in other: self.append(item) def __iadd__(self, other): + warnings.warn('builder.css_files is deprecated. ' + 'Please use app.add_stylesheet() instead.', + RemovedInSphinx20Warning) for item in other: self.append(item)