Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix status_iterator deprecation warning #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions sphinx_gallery/docs_resolv.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

from sphinx.util.console import fuchsia

try:
from sphinx.util import status_iterator
except ImportError:
status_iterator = None

# Try Python 2 first, otherwise load from Python 3
try:
import cPickle as pickle
Expand Down Expand Up @@ -370,9 +375,14 @@ def _embed_code_links(app, gallery_conf, gallery_dir):
flat = [[dirpath, filename]
for dirpath, _, filenames in os.walk(html_gallery_dir)
for filename in filenames]
iterator = app.status_iterator(
flat, os.path.basename(html_gallery_dir), colorfunc=fuchsia,
length=len(flat), stringify_func=lambda x: os.path.basename(x[1]))
if status_iterator is None:
Copy link
Member

@lesteve lesteve Jun 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR. For slightly better readability, I would do something like:

try:
    from sphinx.util import status_iterator
except ImportError:
    # sphinx < 1.6
    status_iterator = app.status_iterator

iterator = status_iterator(...)

i.e. put the import in the _embed_code_links function.

iterator = app.status_iterator(
flat, os.path.basename(html_gallery_dir), colorfunc=fuchsia,
length=len(flat), stringify_func=lambda x: os.path.basename(x[1]))
else:
iterator = status_iterator(
flat, os.path.basename(html_gallery_dir), color=fuchsia,
length=len(flat), stringify_func=lambda x: os.path.basename(x[1]))
for dirpath, fname in iterator:
full_fname = os.path.join(html_gallery_dir, dirpath, fname)
subpath = dirpath[len(html_gallery_dir) + 1:]
Expand Down