Skip to content

Commit b7ee11b

Browse files
committed
Merge pull request scikit-learn#3797 from Titan-C/clean
A short cleanup
2 parents afae1c7 + 9be8718 commit b7ee11b

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

doc/sphinxext/gen_rst.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import gzip
2020
import posixpath
2121
import subprocess
22-
from textwrap import dedent
22+
import warnings
2323

2424

2525
# Try Python 2 first, otherwise load from Python 3
@@ -513,9 +513,9 @@ def generate_example_rst(app):
513513
# better than nested.
514514
seen_backrefs = set()
515515
generate_dir_rst('.', fhindex, example_dir, root_dir, plot_gallery, seen_backrefs)
516-
for dir in sorted(os.listdir(example_dir)):
517-
if os.path.isdir(os.path.join(example_dir, dir)):
518-
generate_dir_rst(dir, fhindex, example_dir, root_dir, plot_gallery, seen_backrefs)
516+
for directory in sorted(os.listdir(example_dir)):
517+
if os.path.isdir(os.path.join(example_dir, directory)):
518+
generate_dir_rst(directory, fhindex, example_dir, root_dir, plot_gallery, seen_backrefs)
519519
fhindex.flush()
520520

521521

@@ -535,7 +535,7 @@ def extract_line_count(filename, target_dir):
535535
tok_type = token.tok_name[tok_type]
536536
if tok_type in ('NEWLINE', 'COMMENT', 'NL', 'INDENT', 'DEDENT'):
537537
continue
538-
elif ((tok_type == 'STRING') and check_docstring):
538+
elif (tok_type == 'STRING') and check_docstring:
539539
erow_docstring = erow
540540
check_docstring = False
541541
return erow_docstring+1+start_row, erow+1+start_row
@@ -597,12 +597,12 @@ def _thumbnail_div(subdir, full_dir, fname, snippet):
597597
return ''.join(out)
598598

599599

600-
def generate_dir_rst(dir, fhindex, example_dir, root_dir, plot_gallery, seen_backrefs):
600+
def generate_dir_rst(directory, fhindex, example_dir, root_dir, plot_gallery, seen_backrefs):
601601
""" Generate the rst file for an example directory.
602602
"""
603-
if not dir == '.':
604-
target_dir = os.path.join(root_dir, dir)
605-
src_dir = os.path.join(example_dir, dir)
603+
if not directory == '.':
604+
target_dir = os.path.join(root_dir, directory)
605+
src_dir = os.path.join(example_dir, directory)
606606
else:
607607
target_dir = root_dir
608608
src_dir = example_dir
@@ -621,22 +621,22 @@ def generate_dir_rst(dir, fhindex, example_dir, root_dir, plot_gallery, seen_bac
621621
os.makedirs(target_dir)
622622
sorted_listdir = line_count_sort(os.listdir(src_dir),
623623
src_dir)
624-
if not os.path.exists(os.path.join(dir, 'images', 'thumb')):
625-
os.makedirs(os.path.join(dir, 'images', 'thumb'))
624+
if not os.path.exists(os.path.join(directory, 'images', 'thumb')):
625+
os.makedirs(os.path.join(directory, 'images', 'thumb'))
626626
for fname in sorted_listdir:
627627
if fname.endswith('py'):
628628
backrefs = generate_file_rst(fname, target_dir, src_dir, root_dir, plot_gallery)
629629
new_fname = os.path.join(src_dir, fname)
630630
_, snippet, _ = extract_docstring(new_fname, True)
631-
fhindex.write(_thumbnail_div(dir, dir, fname, snippet))
631+
fhindex.write(_thumbnail_div(directory, directory, fname, snippet))
632632
fhindex.write("""
633633
634634
.. toctree::
635635
:hidden:
636636
637637
%s/%s
638638
639-
""" % (dir, fname[:-3]))
639+
""" % (directory, fname[:-3]))
640640
for backref in backrefs:
641641
include_path = os.path.join(root_dir, '../modules/generated/%s.examples' % backref)
642642
seen = backref in seen_backrefs
@@ -648,8 +648,8 @@ def generate_dir_rst(dir, fhindex, example_dir, root_dir, plot_gallery, seen_bac
648648
print('-----------------%s--' % ('-' * len(backref)),
649649
file=ex_file)
650650
print(file=ex_file)
651-
rel_dir = os.path.join('../../auto_examples', dir)
652-
ex_file.write(_thumbnail_div(dir, rel_dir, fname, snippet))
651+
rel_dir = os.path.join('../../auto_examples', directory)
652+
ex_file.write(_thumbnail_div(directory, rel_dir, fname, snippet))
653653
seen_backrefs.add(backref)
654654
fhindex.write("""
655655
.. raw:: html
@@ -828,8 +828,6 @@ def generate_file_rst(fname, target_dir, src_dir, root_dir, plot_gallery):
828828
'time_%s.txt' % base_image_name)
829829
thumb_file = os.path.join(thumb_dir, fname[:-3] + '.png')
830830
time_elapsed = 0
831-
time_m = 0
832-
time_s = 0
833831
if plot_gallery and fname.startswith('plot'):
834832
# generate the plot as png image if file name
835833
# starts with plot and if it is more recent than an

0 commit comments

Comments
 (0)