Skip to content

Commit

Permalink
MAINT: use with to close the file
Browse files Browse the repository at this point in the history
  • Loading branch information
François Boulogne committed Sep 22, 2015
1 parent 1458836 commit e6a3643
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
26 changes: 13 additions & 13 deletions doc/ext/plot2rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
#
# 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__'):
Expand Down

0 comments on commit e6a3643

Please sign in to comment.