|
2 | 2 | generate the rst files for the examples by iterating over the pylab examples |
3 | 3 | """ |
4 | 4 | from __future__ import print_function |
| 5 | +import io |
5 | 6 | import os, glob |
6 | 7 |
|
7 | 8 | import os |
@@ -37,15 +38,15 @@ def generate_example_rst(app): |
37 | 38 | continue |
38 | 39 |
|
39 | 40 | fullpath = os.path.join(root,fname) |
40 | | - contents = file(fullpath).read() |
| 41 | + contents = io.open(fullpath, encoding='utf8').read() |
41 | 42 | # indent |
42 | 43 | relpath = os.path.split(root)[-1] |
43 | 44 | datad.setdefault(relpath, []).append((fullpath, fname, contents)) |
44 | 45 |
|
45 | | - subdirs = datad.keys() |
| 46 | + subdirs = list(datad.keys()) |
46 | 47 | subdirs.sort() |
47 | 48 |
|
48 | | - fhindex = file(os.path.join(exampledir, 'index.rst'), 'w') |
| 49 | + fhindex = open(os.path.join(exampledir, 'index.rst'), 'w') |
49 | 50 | fhindex.write("""\ |
50 | 51 | .. _examples-index: |
51 | 52 |
|
@@ -77,7 +78,7 @@ def generate_example_rst(app): |
77 | 78 | os.makedirs(outputdir) |
78 | 79 |
|
79 | 80 | subdirIndexFile = os.path.join(rstdir, 'index.rst') |
80 | | - fhsubdirIndex = file(subdirIndexFile, 'w') |
| 81 | + fhsubdirIndex = open(subdirIndexFile, 'w') |
81 | 82 | fhindex.write(' %s/index.rst\n\n'%subdir) |
82 | 83 |
|
83 | 84 | fhsubdirIndex.write("""\ |
@@ -122,14 +123,14 @@ def generate_example_rst(app): |
122 | 123 | ) and |
123 | 124 | not noplot_regex.search(contents)) |
124 | 125 | if not do_plot: |
125 | | - fhstatic = file(outputfile, 'w') |
| 126 | + fhstatic = open(outputfile, 'w') |
126 | 127 | fhstatic.write(contents) |
127 | 128 | fhstatic.close() |
128 | 129 |
|
129 | 130 | if not out_of_date(fullpath, outrstfile): |
130 | 131 | continue |
131 | 132 |
|
132 | | - fh = file(outrstfile, 'w') |
| 133 | + fh = io.open(outrstfile, 'w', encoding='utf8') |
133 | 134 | fh.write('.. _%s-%s:\n\n'%(subdir, basename)) |
134 | 135 | title = '%s example code: %s'%(subdir, fname) |
135 | 136 | #title = '<img src=%s> %s example code: %s'%(thumbfile, subdir, fname) |
|
0 commit comments