mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #1707 from Eric89GXL/context-encoding
FIX: Use context managers and explicit encoding
This commit is contained in:
commit
4b396d4232
@ -24,6 +24,7 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
import pydoc
|
import pydoc
|
||||||
import optparse
|
import optparse
|
||||||
|
import codecs
|
||||||
|
|
||||||
from jinja2 import FileSystemLoader, TemplateNotFound
|
from jinja2 import FileSystemLoader, TemplateNotFound
|
||||||
from jinja2.sandbox import SandboxedEnvironment
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
@ -137,9 +138,7 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
|
|||||||
|
|
||||||
new_files.append(fn)
|
new_files.append(fn)
|
||||||
|
|
||||||
f = open(fn, 'w')
|
with open(fn, 'w') as f:
|
||||||
|
|
||||||
try:
|
|
||||||
doc = get_documenter(obj, parent)
|
doc = get_documenter(obj, parent)
|
||||||
|
|
||||||
if template_name is not None:
|
if template_name is not None:
|
||||||
@ -201,8 +200,6 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
|
|||||||
|
|
||||||
rendered = template.render(**ns)
|
rendered = template.render(**ns)
|
||||||
f.write(rendered)
|
f.write(rendered)
|
||||||
finally:
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
# descend recursively to new files
|
# descend recursively to new files
|
||||||
if new_files:
|
if new_files:
|
||||||
@ -221,12 +218,14 @@ def find_autosummary_in_files(filenames):
|
|||||||
"""
|
"""
|
||||||
documented = []
|
documented = []
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
f = open(filename, 'r')
|
with codecs.open(filename, 'r', encoding='utf-8',
|
||||||
lines = f.read().splitlines()
|
errors='ignore') as f:
|
||||||
documented.extend(find_autosummary_in_lines(lines, filename=filename))
|
lines = f.read().splitlines()
|
||||||
f.close()
|
documented.extend(find_autosummary_in_lines(lines,
|
||||||
|
filename=filename))
|
||||||
return documented
|
return documented
|
||||||
|
|
||||||
|
|
||||||
def find_autosummary_in_docstring(name, module=None, filename=None):
|
def find_autosummary_in_docstring(name, module=None, filename=None):
|
||||||
"""Find out what items are documented in the given object's docstring.
|
"""Find out what items are documented in the given object's docstring.
|
||||||
|
|
||||||
@ -245,6 +244,7 @@ def find_autosummary_in_docstring(name, module=None, filename=None):
|
|||||||
"statement and it might call sys.exit()." % name)
|
"statement and it might call sys.exit()." % name)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def find_autosummary_in_lines(lines, module=None, filename=None):
|
def find_autosummary_in_lines(lines, module=None, filename=None):
|
||||||
"""Find out what items appear in autosummary:: directives in the
|
"""Find out what items appear in autosummary:: directives in the
|
||||||
given lines.
|
given lines.
|
||||||
|
Loading…
Reference in New Issue
Block a user