Catch DeprecationWarning for docutils.frontend.OptionParser

This commit is contained in:
Adam Turner
2022-04-22 02:53:25 +01:00
parent 55669f6cfc
commit a8827f3329
7 changed files with 57 additions and 22 deletions

View File

@@ -5,6 +5,7 @@ import os
import posixpath
import re
import sys
import warnings
from datetime import datetime
from os import path
from typing import IO, Any, Dict, Iterable, Iterator, List, Optional, Set, Tuple, Type
@@ -443,10 +444,14 @@ class StandaloneHTMLBuilder(Builder):
self.load_indexer(docnames)
self.docwriter = HTMLWriter(self)
self.docsettings: Any = OptionParser(
defaults=self.env.settings,
components=(self.docwriter,),
read_config_files=True).get_default_values()
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=DeprecationWarning)
# DeprecationWarning: The frontend.OptionParser class will be replaced
# by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
self.docsettings: Any = OptionParser(
defaults=self.env.settings,
components=(self.docwriter,),
read_config_files=True).get_default_values()
self.docsettings.compact_lists = bool(self.config.html_compact_lists)
# determine the additional indices to include

View File

@@ -1,6 +1,7 @@
"""LaTeX builder."""
import os
import warnings
from os import path
from typing import Any, Dict, Iterable, List, Tuple, Union
@@ -250,10 +251,14 @@ class LaTeXBuilder(Builder):
def write(self, *ignored: Any) -> None:
docwriter = LaTeXWriter(self)
docsettings: Any = OptionParser(
defaults=self.env.settings,
components=(docwriter,),
read_config_files=True).get_default_values()
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=DeprecationWarning)
# DeprecationWarning: The frontend.OptionParser class will be replaced
# by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
docsettings: Any = OptionParser(
defaults=self.env.settings,
components=(docwriter,),
read_config_files=True).get_default_values()
self.init_document_data()
self.write_stylesheet()

View File

@@ -1,5 +1,6 @@
"""Manual pages builder."""
import warnings
from os import path
from typing import Any, Dict, List, Set, Tuple, Union
@@ -45,10 +46,14 @@ class ManualPageBuilder(Builder):
@progress_message(__('writing'))
def write(self, *ignored: Any) -> None:
docwriter = ManualPageWriter(self)
docsettings: Any = OptionParser(
defaults=self.env.settings,
components=(docwriter,),
read_config_files=True).get_default_values()
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=DeprecationWarning)
# DeprecationWarning: The frontend.OptionParser class will be replaced
# by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
docsettings: Any = OptionParser(
defaults=self.env.settings,
components=(docwriter,),
read_config_files=True).get_default_values()
for info in self.config.man_pages:
docname, name, description, authors, section = info

View File

@@ -1,6 +1,7 @@
"""Texinfo builder."""
import os
import warnings
from os import path
from typing import Any, Dict, Iterable, List, Tuple, Union
@@ -101,10 +102,14 @@ class TexinfoBuilder(Builder):
with progress_message(__("writing")):
self.post_process_images(doctree)
docwriter = TexinfoWriter(self)
settings: Any = OptionParser(
defaults=self.env.settings,
components=(docwriter,),
read_config_files=True).get_default_values()
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=DeprecationWarning)
# DeprecationWarning: The frontend.OptionParser class will be replaced
# by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
settings: Any = OptionParser(
defaults=self.env.settings,
components=(docwriter,),
read_config_files=True).get_default_values()
settings.author = author
settings.title = title
settings.texinfo_filename = targetname[:-5] + '.info'

View File

@@ -1,6 +1,7 @@
"""Test various Sphinx-specific markup extensions."""
import re
import warnings
import pytest
from docutils import frontend, nodes, utils
@@ -22,9 +23,13 @@ from sphinx.writers.latex import LaTeXTranslator, LaTeXWriter
@pytest.fixture
def settings(app):
texescape.init() # otherwise done by the latex builder
optparser = frontend.OptionParser(
components=(RstParser, HTMLWriter, LaTeXWriter),
defaults=default_settings)
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=DeprecationWarning)
# DeprecationWarning: The frontend.OptionParser class will be replaced
# by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
optparser = frontend.OptionParser(
components=(RstParser, HTMLWriter, LaTeXWriter),
defaults=default_settings)
settings = optparser.get_default_values()
settings.smart_quotes = True
settings.env = app.builder.env

View File

@@ -1,5 +1,6 @@
"""Test the search index builder."""
import warnings
from collections import namedtuple
from io import BytesIO
@@ -27,7 +28,11 @@ settings = parser = None
def setup_module():
global settings, parser
optparser = frontend.OptionParser(components=(rst.Parser,))
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=DeprecationWarning)
# DeprecationWarning: The frontend.OptionParser class will be replaced
# by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
optparser = frontend.OptionParser(components=(rst.Parser,))
settings = optparser.get_default_values()
parser = rst.Parser()

View File

@@ -1,4 +1,5 @@
"""Tests uti.nodes functions."""
import warnings
from textwrap import dedent
from typing import Any
@@ -17,8 +18,12 @@ def _transform(doctree):
def create_new_document():
settings = frontend.OptionParser(
components=(rst.Parser,)).get_default_values()
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=DeprecationWarning)
# DeprecationWarning: The frontend.OptionParser class will be replaced
# by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
settings = frontend.OptionParser(
components=(rst.Parser,)).get_default_values()
settings.id_prefix = 'id'
document = new_document('dummy.txt', settings)
return document