Skip to content

Commit

Permalink
Merge old_status_iterator into status_iterator.
Browse files Browse the repository at this point in the history
`old_status_iterator` was deprecated in version 1.6, but only in CHANGES.
  • Loading branch information
AA-Turner committed Sep 9, 2022
1 parent af1570b commit 45fdf73
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions sphinx/util/__init__.py
Expand Up @@ -13,11 +13,11 @@
from importlib import import_module
from os import path
from time import mktime, strptime
from typing import (IO, TYPE_CHECKING, Any, Callable, Dict, Generator, Iterable, List,
Optional, Pattern, Set, Tuple, Type, TypeVar)
from typing import (IO, TYPE_CHECKING, Any, Callable, Dict, Iterable, Iterator, List, Optional,
Pattern, Set, Tuple, Type, TypeVar)
from urllib.parse import parse_qsl, quote_plus, urlencode, urlsplit, urlunsplit

from sphinx.deprecation import RemovedInSphinx70Warning
from sphinx.deprecation import RemovedInSphinx60Warning, RemovedInSphinx70Warning
from sphinx.errors import ExtensionError, FiletypeNotFoundError, SphinxParallelError
from sphinx.locale import __
from sphinx.util import logging
Expand Down Expand Up @@ -460,7 +460,9 @@ def display_chunk(chunk: Any) -> str:

def old_status_iterator(iterable: Iterable[T], summary: str, color: str = "darkgreen",
stringify_func: Callable[[Any], str] = display_chunk
) -> Generator[T, None, None]:
) -> Iterator[T]:
warnings.warn("sphinx.util.old_status_iterator is deprecated and will be "
"removed in Sphinx 6.0", RemovedInSphinx60Warning, stacklevel=2)
l = 0
for item in iterable:
if l == 0:
Expand All @@ -477,22 +479,24 @@ def old_status_iterator(iterable: Iterable[T], summary: str, color: str = "darkg
def status_iterator(iterable: Iterable[T], summary: str, color: str = "darkgreen",
length: int = 0, verbosity: int = 0,
stringify_func: Callable[[Any], str] = display_chunk
) -> Generator[T, None, None]:
if length == 0:
yield from old_status_iterator(iterable, summary, color, stringify_func)
return
l = 0
) -> Iterator[T]:
i = 0
summary = bold(summary)
for item in iterable:
l += 1
s = '%s[%3d%%] %s' % (summary, 100 * l / length, colorize(color, stringify_func(item)))
if verbosity:
s += '\n'
for i, item in enumerate(iterable):
item_str = stringify_func(item)
if length == 0:
if i == 0:
logger.info(summary, nonl=True)
logger.info(item_str, color=color, nonl=True)
logger.info(" ", nonl=True)
else:
s = term_width_line(s)
logger.info(s, nonl=True)
s = f'{summary}[{100 * i / length:3d}%] {colorize(color, item_str)}'
if verbosity:
logger.info(s + '\n', nonl=True)
else:
logger.info(term_width_line(s), nonl=True)
yield item
if l > 0:
if i > 0:
logger.info('')


Expand Down

0 comments on commit 45fdf73

Please sign in to comment.