summaryrefslogtreecommitdiff
path: root/sphinx/util
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/util')
-rw-r--r--sphinx/util/__init__.py38
-rw-r--r--sphinx/util/cfamily.py4
-rw-r--r--sphinx/util/console.py2
-rw-r--r--sphinx/util/docfields.py6
-rw-r--r--sphinx/util/docstrings.py1
-rw-r--r--sphinx/util/docutils.py6
-rw-r--r--sphinx/util/inspect.py13
-rw-r--r--sphinx/util/inventory.py3
-rw-r--r--sphinx/util/jsdump.py2
-rw-r--r--sphinx/util/jsonimpl.py3
-rw-r--r--sphinx/util/logging.py3
-rw-r--r--sphinx/util/nodes.py4
-rw-r--r--sphinx/util/png.py1
-rw-r--r--sphinx/util/pycompat.py3
-rw-r--r--sphinx/util/rst.py6
-rw-r--r--sphinx/util/smartypants.py1
-rw-r--r--sphinx/util/texescape.py1
-rw-r--r--sphinx/util/typing.py1
18 files changed, 39 insertions, 59 deletions
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py
index 082c5caa3..9349ed0e4 100644
--- a/sphinx/util/__init__.py
+++ b/sphinx/util/__init__.py
@@ -25,33 +25,29 @@ from datetime import datetime
from importlib import import_module
from os import path
from time import mktime, strptime
-from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Pattern, Set, Tuple
-from urllib.parse import urlsplit, urlunsplit, quote_plus, parse_qsl, urlencode
+from typing import IO, Any, Callable, Dict, Iterable, Iterator, List, Pattern, Set, Tuple
+from urllib.parse import parse_qsl, quote_plus, urlencode, urlsplit, urlunsplit
from sphinx.deprecation import RemovedInSphinx40Warning, RemovedInSphinx50Warning
-from sphinx.errors import (
- PycodeError, SphinxParallelError, ExtensionError, FiletypeNotFoundError
-)
+from sphinx.errors import (ExtensionError, FiletypeNotFoundError, PycodeError,
+ SphinxParallelError)
from sphinx.locale import __
-from sphinx.util import logging
-from sphinx.util.console import strip_colors, colorize, bold, term_width_line # type: ignore
-from sphinx.util.typing import PathMatcher
from sphinx.util import smartypants # noqa
-
+from sphinx.util import logging
+from sphinx.util.console import bold, colorize, strip_colors, term_width_line # type: ignore
+from sphinx.util.matching import patfilter # noqa
+from sphinx.util.nodes import (caption_ref_re, explicit_title_re, # noqa
+ nested_parse_with_titles, split_explicit_title)
# import other utilities; partly for backwards compatibility, so don't
# prune unused ones indiscriminately
-from sphinx.util.osutil import ( # noqa
- SEP, os_path, relative_uri, ensuredir, walk, mtimes_of_files, movefile,
- copyfile, copytimes, make_filename)
-from sphinx.util.nodes import ( # noqa
- nested_parse_with_titles, split_explicit_title, explicit_title_re,
- caption_ref_re)
-from sphinx.util.matching import patfilter # noqa
-
+from sphinx.util.osutil import (SEP, copyfile, copytimes, ensuredir, make_filename, # noqa
+ movefile, mtimes_of_files, os_path, relative_uri, walk)
+from sphinx.util.typing import PathMatcher
if False:
# For type annotation
from typing import Type # for python3.5.1
+
from sphinx.application import Sphinx
@@ -241,10 +237,12 @@ _DEBUG_HEADER = '''\
def save_traceback(app: "Sphinx") -> str:
"""Save the current exception's traceback in a temporary file."""
- import sphinx
- import jinja2
- import docutils
import platform
+
+ import docutils
+ import jinja2
+
+ import sphinx
exc = sys.exc_info()[1]
if isinstance(exc, SphinxParallelError):
exc_format = '(Error in parallel process)\n' + exc.traceback
diff --git a/sphinx/util/cfamily.py b/sphinx/util/cfamily.py
index 0edea128c..17c335b60 100644
--- a/sphinx/util/cfamily.py
+++ b/sphinx/util/cfamily.py
@@ -11,9 +11,7 @@
import re
import warnings
from copy import deepcopy
-from typing import (
- Any, Callable, List, Match, Optional, Pattern, Tuple, Union
-)
+from typing import Any, Callable, List, Match, Optional, Pattern, Tuple, Union
from docutils import nodes
from docutils.nodes import TextElement
diff --git a/sphinx/util/console.py b/sphinx/util/console.py
index d429be602..579a95134 100644
--- a/sphinx/util/console.py
+++ b/sphinx/util/console.py
@@ -32,9 +32,9 @@ def terminal_safe(s: str) -> str:
def get_terminal_width() -> int:
"""Borrowed from the py lib."""
try:
- import termios
import fcntl
import struct
+ import termios
call = fcntl.ioctl(0, termios.TIOCGWINSZ, struct.pack('hhhh', 0, 0, 0, 0))
height, width = struct.unpack('hhhh', call)[:2]
terminal_width = width
diff --git a/sphinx/util/docfields.py b/sphinx/util/docfields.py
index c07bc7f66..404bb127f 100644
--- a/sphinx/util/docfields.py
+++ b/sphinx/util/docfields.py
@@ -10,8 +10,7 @@
"""
import warnings
-from typing import Any, Dict, List, Tuple, Union
-from typing import cast
+from typing import Any, Dict, List, Tuple, Union, cast
from docutils import nodes
from docutils.nodes import Node
@@ -23,8 +22,9 @@ from sphinx.util.typing import TextlikeNode
if False:
# For type annotation
from typing import Type # for python3.5.1
- from sphinx.environment import BuildEnvironment
+
from sphinx.directive import ObjectDescription
+ from sphinx.environment import BuildEnvironment
def _is_single_paragraph(node: nodes.field_body) -> bool:
diff --git a/sphinx/util/docstrings.py b/sphinx/util/docstrings.py
index 67a008643..206986bd0 100644
--- a/sphinx/util/docstrings.py
+++ b/sphinx/util/docstrings.py
@@ -17,7 +17,6 @@ from docutils.parsers.rst.states import Body
from sphinx.deprecation import RemovedInSphinx50Warning
-
field_list_item_re = re.compile(Body.patterns['field_marker'])
diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py
index 3ba7813b6..7831f267c 100644
--- a/sphinx/util/docutils.py
+++ b/sphinx/util/docutils.py
@@ -15,8 +15,7 @@ from copy import copy
from distutils.version import LooseVersion
from os import path
from types import ModuleType
-from typing import Any, Callable, Dict, Generator, IO, List, Optional, Set, Tuple
-from typing import cast
+from typing import IO, Any, Callable, Dict, Generator, List, Optional, Set, Tuple, cast
import docutils
from docutils import nodes
@@ -24,7 +23,7 @@ from docutils.io import FileOutput
from docutils.nodes import Element, Node, system_message
from docutils.parsers.rst import Directive, directives, roles
from docutils.parsers.rst.states import Inliner
-from docutils.statemachine import StateMachine, State, StringList
+from docutils.statemachine import State, StateMachine, StringList
from docutils.utils import Reporter, unescape
from sphinx.errors import SphinxError
@@ -37,6 +36,7 @@ report_re = re.compile('^(.+?:(?:\\d+)?): \\((DEBUG|INFO|WARNING|ERROR|SEVERE)/(
if False:
# For type annotation
from typing import Type # for python3.5.1
+
from sphinx.builders import Builder
from sphinx.config import Config
from sphinx.environment import BuildEnvironment
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index 9896ec884..9f04567d3 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -18,12 +18,9 @@ import types
import typing
import warnings
from functools import partial, partialmethod
-from inspect import ( # NOQA
- Parameter, isclass, ismethod, ismethoddescriptor, ismodule
-)
+from inspect import Parameter, isclass, ismethod, ismethoddescriptor, ismodule # NOQA
from io import StringIO
-from typing import Any, Callable, Dict, Mapping, List, Optional, Tuple
-from typing import cast
+from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple, cast
from sphinx.deprecation import RemovedInSphinx40Warning, RemovedInSphinx50Warning
from sphinx.pycode.ast import ast # for py35-37
@@ -33,11 +30,7 @@ from sphinx.util.typing import ForwardRef
from sphinx.util.typing import stringify as stringify_annotation
if sys.version_info > (3, 7):
- from types import (
- ClassMethodDescriptorType,
- MethodDescriptorType,
- WrapperDescriptorType
- )
+ from types import ClassMethodDescriptorType, MethodDescriptorType, WrapperDescriptorType
else:
ClassMethodDescriptorType = type(object.__init__)
MethodDescriptorType = type(str.join)
diff --git a/sphinx/util/inventory.py b/sphinx/util/inventory.py
index 1e3572323..6d3b5f455 100644
--- a/sphinx/util/inventory.py
+++ b/sphinx/util/inventory.py
@@ -10,12 +10,11 @@
import os
import re
import zlib
-from typing import Callable, IO, Iterator
+from typing import IO, Callable, Iterator
from sphinx.util import logging
from sphinx.util.typing import Inventory
-
BUFSIZE = 16 * 1024
logger = logging.getLogger(__name__)
diff --git a/sphinx/util/jsdump.py b/sphinx/util/jsdump.py
index 1f0e258cb..0cd3c8b8c 100644
--- a/sphinx/util/jsdump.py
+++ b/sphinx/util/jsdump.py
@@ -10,7 +10,7 @@
"""
import re
-from typing import Any, Dict, IO, List, Match, Union
+from typing import IO, Any, Dict, List, Match, Union
_str_re = re.compile(r'"(\\\\|\\"|[^"])*"')
_int_re = re.compile(r'\d+')
diff --git a/sphinx/util/jsonimpl.py b/sphinx/util/jsonimpl.py
index 35501f03a..4cb3bc93f 100644
--- a/sphinx/util/jsonimpl.py
+++ b/sphinx/util/jsonimpl.py
@@ -11,11 +11,10 @@
import json
import warnings
from collections import UserString
-from typing import Any, IO
+from typing import IO, Any
from sphinx.deprecation import RemovedInSphinx40Warning
-
warnings.warn('sphinx.util.jsonimpl is deprecated',
RemovedInSphinx40Warning, stacklevel=2)
diff --git a/sphinx/util/logging.py b/sphinx/util/logging.py
index 5889f3860..0f2a8b6f0 100644
--- a/sphinx/util/logging.py
+++ b/sphinx/util/logging.py
@@ -12,7 +12,7 @@ import logging
import logging.handlers
from collections import defaultdict
from contextlib import contextmanager
-from typing import Any, Dict, Generator, IO, List, Tuple, Union
+from typing import IO, Any, Dict, Generator, List, Tuple, Union
from docutils import nodes
from docutils.nodes import Node
@@ -24,6 +24,7 @@ from sphinx.util.console import colorize
if False:
# For type annotation
from typing import Type # for python3.5.1
+
from sphinx.application import Sphinx
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py
index b4d796f61..05e9cb7b2 100644
--- a/sphinx/util/nodes.py
+++ b/sphinx/util/nodes.py
@@ -11,8 +11,7 @@
import re
import unicodedata
import warnings
-from typing import Any, Callable, Iterable, List, Set, Tuple
-from typing import cast
+from typing import Any, Callable, Iterable, List, Set, Tuple, cast
from docutils import nodes
from docutils.nodes import Element, Node
@@ -28,6 +27,7 @@ from sphinx.util import logging
if False:
# For type annotation
from typing import Type # for python3.5.1
+
from sphinx.builders import Builder
from sphinx.domain import IndexEntry
from sphinx.environment import BuildEnvironment
diff --git a/sphinx/util/png.py b/sphinx/util/png.py
index 22c35d991..3dd22d7ff 100644
--- a/sphinx/util/png.py
+++ b/sphinx/util/png.py
@@ -12,7 +12,6 @@ import binascii
import struct
from typing import Optional
-
LEN_IEND = 12
LEN_DEPTH = 22
diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py
index 50eee5ce3..6474cf141 100644
--- a/sphinx/util/pycompat.py
+++ b/sphinx/util/pycompat.py
@@ -21,7 +21,6 @@ from sphinx.util import logging
from sphinx.util.console import terminal_safe
from sphinx.util.typing import NoneType
-
logger = logging.getLogger(__name__)
@@ -32,8 +31,8 @@ logger = logging.getLogger(__name__)
# support for running 2to3 over config files
def convert_with_2to3(filepath: str) -> str:
try:
- from lib2to3.refactor import RefactoringTool, get_fixers_from_package
from lib2to3.pgen2.parse import ParseError
+ from lib2to3.refactor import RefactoringTool, get_fixers_from_package
except ImportError as exc:
# python 3.9.0a6+ emits PendingDeprecationWarning for lib2to3.
# Additionally, removal of the module is still discussed at PEP-594.
diff --git a/sphinx/util/rst.py b/sphinx/util/rst.py
index e93849b70..b67b68c4a 100644
--- a/sphinx/util/rst.py
+++ b/sphinx/util/rst.py
@@ -18,12 +18,10 @@ from docutils.parsers.rst import roles
from docutils.parsers.rst.languages import en as english
from docutils.statemachine import StringList
from docutils.utils import Reporter
-from jinja2 import Environment
-from jinja2 import environmentfilter
+from jinja2 import Environment, environmentfilter
from sphinx.locale import __
-from sphinx.util import docutils
-from sphinx.util import logging
+from sphinx.util import docutils, logging
logger = logging.getLogger(__name__)
diff --git a/sphinx/util/smartypants.py b/sphinx/util/smartypants.py
index 43f8bc724..ec6b2172c 100644
--- a/sphinx/util/smartypants.py
+++ b/sphinx/util/smartypants.py
@@ -32,7 +32,6 @@ from docutils.utils import smartquotes
from sphinx.util.docutils import __version_info__ as docutils_version
-
langquotes = {'af': '“”‘’',
'af-x-altquot': '„”‚’',
'bg': '„“‚‘', # Bulgarian, https://bg.wikipedia.org/wiki/Кавички
diff --git a/sphinx/util/texescape.py b/sphinx/util/texescape.py
index afa1c349e..98e763aaf 100644
--- a/sphinx/util/texescape.py
+++ b/sphinx/util/texescape.py
@@ -13,7 +13,6 @@ from typing import Dict
from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
-
tex_replacements = [
# map TeX special chars
('$', r'\$'),
diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py
index cc4d648be..28f9c5e38 100644
--- a/sphinx/util/typing.py
+++ b/sphinx/util/typing.py
@@ -15,7 +15,6 @@ from typing import Any, Callable, Dict, Generator, List, Optional, Tuple, TypeVa
from docutils import nodes
from docutils.parsers.rst.states import Inliner
-
if sys.version_info > (3, 7):
from typing import ForwardRef
else: