Skip to content

Commit

Permalink
Import fallback for older versions of Sphinx
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Wouda authored and AWhetter committed Sep 24, 2023
1 parent 0186a3c commit cf8abe5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
13 changes: 10 additions & 3 deletions autoapi/mappers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
from sphinx.util.osutil import ensuredir
import sphinx.util.logging

try:
from sphinx.util.display import status_iterator
except ImportError:
# This method was moved into sphinx.util.display in Sphinx 6.1.0. Before
# that it resided in sphinx.util.
from sphinx.util import status_iterator

from ..settings import API_ROOT, TEMPLATE_DIR

LOGGER = sphinx.util.logging.getLogger(__name__)
Expand Down Expand Up @@ -207,7 +214,7 @@ def _wrapped_prepare(value):
def load(self, patterns, dirs, ignore=None):
"""Load objects from the filesystem into the ``paths`` dictionary."""
paths = list(self.find_files(patterns=patterns, dirs=dirs, ignore=ignore))
for path in sphinx.util.display.status_iterator(
for path in status_iterator(
paths,
colorize("bold", "[AutoAPI] Reading files... "),
"darkgreen",
Expand Down Expand Up @@ -290,7 +297,7 @@ def add_object(self, obj):

def map(self, options=None):
"""Trigger find of serialized sources and build objects"""
for _, data in sphinx.util.display.status_iterator(
for _, data in status_iterator(
self.paths.items(),
colorize("bold", "[AutoAPI] ") + "Mapping Data... ",
length=len(self.paths),
Expand All @@ -308,7 +315,7 @@ def create_class(self, data, options=None, **kwargs):
raise NotImplementedError

def output_rst(self, root, source_suffix):
for _, obj in sphinx.util.display.status_iterator(
for _, obj in status_iterator(
self.objects.items(),
colorize("bold", "[AutoAPI] ") + "Rendering Data... ",
length=len(self.objects),
Expand Down
9 changes: 8 additions & 1 deletion autoapi/mappers/python/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
import sphinx.util.docstrings
import sphinx.util.logging

try:
from sphinx.util.display import status_iterator
except ImportError:
# This method was moved into sphinx.util.display in Sphinx 6.1.0. Before
# that it resided in sphinx.util.
from sphinx.util import status_iterator

from ..base import SphinxMapperBase
from .parser import Parser
from .objects import (
Expand Down Expand Up @@ -291,7 +298,7 @@ def load(self, patterns, dirs, ignore=None):
)
return False

for dir_root, path in sphinx.util.display.status_iterator(
for dir_root, path in status_iterator(
dir_root_files,
colorize("bold", "[AutoAPI] Reading files... "),
length=len(dir_root_files),
Expand Down

0 comments on commit cf8abe5

Please sign in to comment.