diff --git a/doc/ext/plot2rst.py b/doc/ext/plot2rst.py index 0894b24f..aed81888 100644 --- a/doc/ext/plot2rst.py +++ b/doc/ext/plot2rst.py @@ -210,18 +210,17 @@ def generate_examples_and_gallery(example_dir, rst_dir, cfg): rst_dir.makedirs() # we create an index.rst with all examples - gallery_index = open(rst_dir.pjoin('index'+cfg.source_suffix_str), 'w') - - # Here we don't use an os.walk, but we recurse only twice: flat is - # better than nested. - write_gallery(gallery_index, example_dir, rst_dir, cfg) - for d in sorted(example_dir.listdir()): - example_sub = example_dir.pjoin(d) - if example_sub.isdir: - rst_sub = rst_dir.pjoin(d) - rst_sub.makedirs() - write_gallery(gallery_index, example_sub, rst_sub, cfg, depth=1) - gallery_index.flush() + with open(rst_dir.pjoin('index'+cfg.source_suffix_str), 'w') as gallery_index: + # Here we don't use an os.walk, but we recurse only twice: flat is + # better than nested. + write_gallery(gallery_index, example_dir, rst_dir, cfg) + for d in sorted(example_dir.listdir()): + example_sub = example_dir.pjoin(d) + if example_sub.isdir: + rst_sub = rst_dir.pjoin(d) + rst_sub.makedirs() + write_gallery(gallery_index, example_sub, rst_sub, cfg, depth=1) + gallery_index.flush() def write_gallery(gallery_index, src_dir, rst_dir, cfg, depth=0): @@ -251,7 +250,8 @@ def write_gallery(gallery_index, src_dir, rst_dir, cfg, depth=0): print(80*'_') return - gallery_description = open(gallery_template).read() + with open(gallery_template) as f: + gallery_description = f.read() gallery_index.write('\n\n%s\n\n' % gallery_description) rst_dir.makedirs() diff --git a/doc/source/conf.py b/doc/source/conf.py index 341b391d..e0ae6f6e 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -75,7 +75,8 @@ copyright = '2013, the scikit-image team' # # The short X.Y version. -setup_lines = open('../../skimage/__init__.py').readlines() +with open('../../skimage/__init__.py') as f: + setup_lines = f.readlines() version = 'vUndefined' for l in setup_lines: if l.startswith('__version__'):