1919import gzip
2020import posixpath
2121import subprocess
22- from textwrap import dedent
2322
2423
2524# Try Python 2 first, otherwise load from Python 3
@@ -513,9 +512,9 @@ def generate_example_rst(app):
513512 # better than nested.
514513 seen_backrefs = set ()
515514 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 )
515+ for directory in sorted (os .listdir (example_dir )):
516+ if os .path .isdir (os .path .join (example_dir , directory )):
517+ generate_dir_rst (directory , fhindex , example_dir , root_dir , plot_gallery , seen_backrefs )
519518 fhindex .flush ()
520519
521520
@@ -535,7 +534,7 @@ def extract_line_count(filename, target_dir):
535534 tok_type = token .tok_name [tok_type ]
536535 if tok_type in ('NEWLINE' , 'COMMENT' , 'NL' , 'INDENT' , 'DEDENT' ):
537536 continue
538- elif (( tok_type == 'STRING' ) and check_docstring ) :
537+ elif (tok_type == 'STRING' ) and check_docstring :
539538 erow_docstring = erow
540539 check_docstring = False
541540 return erow_docstring + 1 + start_row , erow + 1 + start_row
@@ -597,12 +596,12 @@ def _thumbnail_div(subdir, full_dir, fname, snippet):
597596 return '' .join (out )
598597
599598
600- def generate_dir_rst (dir , fhindex , example_dir , root_dir , plot_gallery , seen_backrefs ):
599+ def generate_dir_rst (directory , fhindex , example_dir , root_dir , plot_gallery , seen_backrefs ):
601600 """ Generate the rst file for an example directory.
602601 """
603- if not dir == '.' :
604- target_dir = os .path .join (root_dir , dir )
605- src_dir = os .path .join (example_dir , dir )
602+ if not directory == '.' :
603+ target_dir = os .path .join (root_dir , directory )
604+ src_dir = os .path .join (example_dir , directory )
606605 else :
607606 target_dir = root_dir
608607 src_dir = example_dir
@@ -621,22 +620,22 @@ def generate_dir_rst(dir, fhindex, example_dir, root_dir, plot_gallery, seen_bac
621620 os .makedirs (target_dir )
622621 sorted_listdir = line_count_sort (os .listdir (src_dir ),
623622 src_dir )
624- if not os .path .exists (os .path .join (dir , 'images' , 'thumb' )):
625- os .makedirs (os .path .join (dir , 'images' , 'thumb' ))
623+ if not os .path .exists (os .path .join (directory , 'images' , 'thumb' )):
624+ os .makedirs (os .path .join (directory , 'images' , 'thumb' ))
626625 for fname in sorted_listdir :
627626 if fname .endswith ('py' ):
628627 backrefs = generate_file_rst (fname , target_dir , src_dir , root_dir , plot_gallery )
629628 new_fname = os .path .join (src_dir , fname )
630629 _ , snippet , _ = extract_docstring (new_fname , True )
631- fhindex .write (_thumbnail_div (dir , dir , fname , snippet ))
630+ fhindex .write (_thumbnail_div (directory , directory , fname , snippet ))
632631 fhindex .write ("""
633632
634633.. toctree::
635634 :hidden:
636635
637636 %s/%s
638637
639- """ % (dir , fname [:- 3 ]))
638+ """ % (directory , fname [:- 3 ]))
640639 for backref in backrefs :
641640 include_path = os .path .join (root_dir , '../modules/generated/%s.examples' % backref )
642641 seen = backref in seen_backrefs
@@ -648,8 +647,8 @@ def generate_dir_rst(dir, fhindex, example_dir, root_dir, plot_gallery, seen_bac
648647 print ('-----------------%s--' % ('-' * len (backref )),
649648 file = ex_file )
650649 print (file = ex_file )
651- rel_dir = os .path .join ('../../auto_examples' , dir )
652- ex_file .write (_thumbnail_div (dir , rel_dir , fname , snippet ))
650+ rel_dir = os .path .join ('../../auto_examples' , directory )
651+ ex_file .write (_thumbnail_div (directory , rel_dir , fname , snippet ))
653652 seen_backrefs .add (backref )
654653 fhindex .write ("""
655654.. raw:: html
@@ -698,6 +697,7 @@ def make_thumbnail(in_fname, out_fname, width, height):
698697 try :
699698 subprocess .call (["optipng" , "-quiet" , "-o" , "9" , out_fname ])
700699 except Exception :
700+ import warnings
701701 warnings .warn ('Install optipng to reduce the size of the generated images' )
702702
703703
@@ -807,7 +807,7 @@ def generate_file_rst(fname, target_dir, src_dir, root_dir, plot_gallery):
807807 last_dir = ''
808808 else :
809809 last_dir += '_'
810- short_fname = last_dir + fname
810+
811811 src_file = os .path .join (src_dir , fname )
812812 example_file = os .path .join (target_dir , fname )
813813 shutil .copyfile (src_file , example_file )
@@ -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