mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #5757 from jdufresne/open
Simplify open() call by removing default mode
This commit is contained in:
commit
4c7143c85a
2
setup.py
2
setup.py
@ -132,7 +132,7 @@ else:
|
|||||||
domain + '.js'))
|
domain + '.js'))
|
||||||
|
|
||||||
for js_file, (locale, po_file) in zip(js_files, po_files):
|
for js_file, (locale, po_file) in zip(js_files, po_files):
|
||||||
with open(po_file, 'r') as infile:
|
with open(po_file) as infile:
|
||||||
catalog = read_po(infile, locale)
|
catalog = read_po(infile, locale)
|
||||||
|
|
||||||
if catalog.fuzzy and not self.use_fuzzy:
|
if catalog.fuzzy and not self.use_fuzzy:
|
||||||
|
@ -135,7 +135,7 @@ class ChangesBuilder(Builder):
|
|||||||
|
|
||||||
logger.info(bold(__('copying source files...')))
|
logger.info(bold(__('copying source files...')))
|
||||||
for docname in self.env.all_docs:
|
for docname in self.env.all_docs:
|
||||||
with open(self.env.doc2path(docname), 'r', # type: ignore
|
with open(self.env.doc2path(docname), # type: ignore
|
||||||
encoding=self.env.config.source_encoding) as f:
|
encoding=self.env.config.source_encoding) as f:
|
||||||
try:
|
try:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
|
@ -198,7 +198,7 @@ def should_write(filepath, new_content):
|
|||||||
if not path.exists(filepath):
|
if not path.exists(filepath):
|
||||||
return True
|
return True
|
||||||
try:
|
try:
|
||||||
with open(filepath, 'r', encoding='utf-8') as oldpot: # type: ignore
|
with open(filepath, encoding='utf-8') as oldpot: # type: ignore
|
||||||
old_content = oldpot.read()
|
old_content = oldpot.read()
|
||||||
old_header_index = old_content.index('"POT-Creation-Date:')
|
old_header_index = old_content.index('"POT-Creation-Date:')
|
||||||
new_header_index = new_content.index('"POT-Creation-Date:')
|
new_header_index = new_content.index('"POT-Creation-Date:')
|
||||||
@ -249,7 +249,7 @@ class MessageCatalogBuilder(I18nBuilder):
|
|||||||
for template in status_iterator(files, __('reading templates... '), "purple", # type: ignore # NOQA
|
for template in status_iterator(files, __('reading templates... '), "purple", # type: ignore # NOQA
|
||||||
len(files), self.app.verbosity):
|
len(files), self.app.verbosity):
|
||||||
try:
|
try:
|
||||||
with open(template, 'r', encoding='utf-8') as f: # type: ignore
|
with open(template, encoding='utf-8') as f: # type: ignore
|
||||||
context = f.read()
|
context = f.read()
|
||||||
for line, meth, msg in extract_translations(context):
|
for line, meth, msg in extract_translations(context):
|
||||||
origin = MsgOrigin(template, line)
|
origin = MsgOrigin(template, line)
|
||||||
|
@ -956,7 +956,7 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
try:
|
try:
|
||||||
searchindexfn = path.join(self.outdir, self.searchindex_filename)
|
searchindexfn = path.join(self.outdir, self.searchindex_filename)
|
||||||
if self.indexer_dumps_unicode:
|
if self.indexer_dumps_unicode:
|
||||||
with open(searchindexfn, 'r', encoding='utf-8') as ft: # type: ignore
|
with open(searchindexfn, encoding='utf-8') as ft: # type: ignore
|
||||||
self.indexer.load(ft, self.indexer_format)
|
self.indexer.load(ft, self.indexer_format)
|
||||||
else:
|
else:
|
||||||
with open(searchindexfn, 'rb') as fb:
|
with open(searchindexfn, 'rb') as fb:
|
||||||
|
@ -216,7 +216,7 @@ class LiteralIncludeReader:
|
|||||||
def read_file(self, filename, location=None):
|
def read_file(self, filename, location=None):
|
||||||
# type: (unicode, Any) -> List[unicode]
|
# type: (unicode, Any) -> List[unicode]
|
||||||
try:
|
try:
|
||||||
with open(filename, 'r', # type: ignore
|
with open(filename, # type: ignore
|
||||||
encoding=self.encoding, errors='strict') as f:
|
encoding=self.encoding, errors='strict') as f:
|
||||||
text = f.read() # type: unicode
|
text = f.read() # type: unicode
|
||||||
if 'tab-width' in self.options:
|
if 'tab-width' in self.options:
|
||||||
|
@ -248,7 +248,7 @@ def find_autosummary_in_files(filenames):
|
|||||||
"""
|
"""
|
||||||
documented = [] # type: List[Tuple[unicode, unicode, unicode]]
|
documented = [] # type: List[Tuple[unicode, unicode, unicode]]
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
with open(filename, 'r', encoding='utf-8', # type: ignore
|
with open(filename, encoding='utf-8', # type: ignore
|
||||||
errors='ignore') as f:
|
errors='ignore') as f:
|
||||||
lines = f.read().splitlines()
|
lines = f.read().splitlines()
|
||||||
documented.extend(find_autosummary_in_lines(lines, filename=filename))
|
documented.extend(find_autosummary_in_lines(lines, filename=filename))
|
||||||
|
@ -102,7 +102,7 @@ class CoverageBuilder(Builder):
|
|||||||
c_objects = self.env.domaindata['c']['objects']
|
c_objects = self.env.domaindata['c']['objects']
|
||||||
for filename in self.c_sourcefiles:
|
for filename in self.c_sourcefiles:
|
||||||
undoc = set() # type: Set[Tuple[unicode, unicode]]
|
undoc = set() # type: Set[Tuple[unicode, unicode]]
|
||||||
with open(filename, 'r') as f:
|
with open(filename) as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
for key, regex in self.c_regexes:
|
for key, regex in self.c_regexes:
|
||||||
match = regex.match(line)
|
match = regex.match(line)
|
||||||
|
@ -145,7 +145,7 @@ class Graphviz(SphinxDirective):
|
|||||||
rel_filename, filename = self.env.relfn2path(argument)
|
rel_filename, filename = self.env.relfn2path(argument)
|
||||||
self.env.note_dependency(rel_filename)
|
self.env.note_dependency(rel_filename)
|
||||||
try:
|
try:
|
||||||
with open(filename, 'r', encoding='utf-8') as fp: # type: ignore
|
with open(filename, encoding='utf-8') as fp: # type: ignore
|
||||||
dotcode = fp.read()
|
dotcode = fp.read()
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
return [document.reporter.warning(
|
return [document.reporter.warning(
|
||||||
@ -310,7 +310,7 @@ def render_dot_html(self, node, code, options, prefix='graphviz',
|
|||||||
self.body.append('<p class="warning">%s</p>' % alt)
|
self.body.append('<p class="warning">%s</p>' % alt)
|
||||||
self.body.append('</object></div>\n')
|
self.body.append('</object></div>\n')
|
||||||
else:
|
else:
|
||||||
with open(outfn + '.map', 'r', encoding='utf-8') as mapfile: # type: ignore
|
with open(outfn + '.map', encoding='utf-8') as mapfile: # type: ignore
|
||||||
imgmap = ClickableMapDefinition(outfn + '.map', mapfile.read(), dot=code)
|
imgmap = ClickableMapDefinition(outfn + '.map', mapfile.read(), dot=code)
|
||||||
if imgmap.clickable:
|
if imgmap.clickable:
|
||||||
# has a map
|
# has a map
|
||||||
|
@ -163,7 +163,7 @@ class path(text_type):
|
|||||||
"""
|
"""
|
||||||
Returns the text in the file.
|
Returns the text in the file.
|
||||||
"""
|
"""
|
||||||
with open(self, mode='r', encoding=encoding, **kwargs) as f: # type: ignore
|
with open(self, encoding=encoding, **kwargs) as f: # type: ignore
|
||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
def bytes(self):
|
def bytes(self):
|
||||||
|
@ -49,7 +49,7 @@ def copy_asset_file(source, destination, context=None, renderer=None):
|
|||||||
from sphinx.util.template import SphinxRenderer
|
from sphinx.util.template import SphinxRenderer
|
||||||
renderer = SphinxRenderer()
|
renderer = SphinxRenderer()
|
||||||
|
|
||||||
with open(source, 'r', encoding='utf-8') as fsrc: # type: ignore
|
with open(source, encoding='utf-8') as fsrc: # type: ignore
|
||||||
if destination.lower().endswith('_t'):
|
if destination.lower().endswith('_t'):
|
||||||
destination = destination[:-2]
|
destination = destination[:-2]
|
||||||
with open(destination, 'w', encoding='utf-8') as fdst: # type: ignore
|
with open(destination, 'w', encoding='utf-8') as fdst: # type: ignore
|
||||||
|
@ -69,7 +69,7 @@ class CatalogInfo(LocaleFileInfoBase):
|
|||||||
|
|
||||||
def write_mo(self, locale):
|
def write_mo(self, locale):
|
||||||
# type: (unicode) -> None
|
# type: (unicode) -> None
|
||||||
with open(self.po_path, 'rt', encoding=self.charset) as file_po: # type: ignore
|
with open(self.po_path, encoding=self.charset) as file_po: # type: ignore
|
||||||
try:
|
try:
|
||||||
po = read_po(file_po, locale)
|
po = read_po(file_po, locale)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
Loading…
Reference in New Issue
Block a user