mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
fix for make style-check
This commit is contained in:
parent
d7bebce5e6
commit
03f061f898
@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
sphinx.builders.dummy
|
sphinx.builders.dummy
|
||||||
~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Do syntax checks, but no writing.
|
Do syntax checks, but no writing.
|
||||||
|
|
||||||
|
250
sphinx/io.py
250
sphinx/io.py
@ -1,125 +1,125 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
sphinx.io
|
sphinx.io
|
||||||
~~~~~~~~~
|
~~~~~~~~~
|
||||||
|
|
||||||
Input/Output files
|
Input/Output files
|
||||||
|
|
||||||
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||||
:license: BSD, see LICENSE for details.
|
:license: BSD, see LICENSE for details.
|
||||||
"""
|
"""
|
||||||
from docutils.io import FileInput
|
from docutils.io import FileInput
|
||||||
from docutils.readers import standalone
|
from docutils.readers import standalone
|
||||||
from docutils.writers import UnfilteredWriter
|
from docutils.writers import UnfilteredWriter
|
||||||
from six import string_types, text_type
|
from six import string_types, text_type
|
||||||
|
|
||||||
from sphinx.transforms import ApplySourceWorkaround, ExtraTranslatableNodes, Locale, \
|
from sphinx.transforms import ApplySourceWorkaround, ExtraTranslatableNodes, Locale, \
|
||||||
CitationReferences, DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks, \
|
CitationReferences, DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks, \
|
||||||
AutoNumbering, SortIds, RemoveTranslatableInline
|
AutoNumbering, SortIds, RemoveTranslatableInline
|
||||||
from sphinx.util import import_object, split_docinfo
|
from sphinx.util import import_object, split_docinfo
|
||||||
|
|
||||||
|
|
||||||
class SphinxBaseReader(standalone.Reader):
|
class SphinxBaseReader(standalone.Reader):
|
||||||
"""
|
"""
|
||||||
Add our source parsers
|
Add our source parsers
|
||||||
"""
|
"""
|
||||||
def __init__(self, app, parsers={}, *args, **kwargs):
|
def __init__(self, app, parsers={}, *args, **kwargs):
|
||||||
standalone.Reader.__init__(self, *args, **kwargs)
|
standalone.Reader.__init__(self, *args, **kwargs)
|
||||||
self.parser_map = {}
|
self.parser_map = {}
|
||||||
for suffix, parser_class in parsers.items():
|
for suffix, parser_class in parsers.items():
|
||||||
if isinstance(parser_class, string_types):
|
if isinstance(parser_class, string_types):
|
||||||
parser_class = import_object(parser_class, 'source parser')
|
parser_class = import_object(parser_class, 'source parser')
|
||||||
parser = parser_class()
|
parser = parser_class()
|
||||||
if hasattr(parser, 'set_application'):
|
if hasattr(parser, 'set_application'):
|
||||||
parser.set_application(app)
|
parser.set_application(app)
|
||||||
self.parser_map[suffix] = parser
|
self.parser_map[suffix] = parser
|
||||||
|
|
||||||
def read(self, source, parser, settings):
|
def read(self, source, parser, settings):
|
||||||
self.source = source
|
self.source = source
|
||||||
|
|
||||||
for suffix in self.parser_map:
|
for suffix in self.parser_map:
|
||||||
if source.source_path.endswith(suffix):
|
if source.source_path.endswith(suffix):
|
||||||
self.parser = self.parser_map[suffix]
|
self.parser = self.parser_map[suffix]
|
||||||
break
|
break
|
||||||
|
|
||||||
if not self.parser:
|
if not self.parser:
|
||||||
self.parser = parser
|
self.parser = parser
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
self.input = self.source.read()
|
self.input = self.source.read()
|
||||||
self.parse()
|
self.parse()
|
||||||
return self.document
|
return self.document
|
||||||
|
|
||||||
def get_transforms(self):
|
def get_transforms(self):
|
||||||
return standalone.Reader.get_transforms(self) + self.transforms
|
return standalone.Reader.get_transforms(self) + self.transforms
|
||||||
|
|
||||||
|
|
||||||
class SphinxStandaloneReader(SphinxBaseReader):
|
class SphinxStandaloneReader(SphinxBaseReader):
|
||||||
"""
|
"""
|
||||||
Add our own transforms.
|
Add our own transforms.
|
||||||
"""
|
"""
|
||||||
transforms = [ApplySourceWorkaround, ExtraTranslatableNodes, Locale, CitationReferences,
|
transforms = [ApplySourceWorkaround, ExtraTranslatableNodes, Locale, CitationReferences,
|
||||||
DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks,
|
DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks,
|
||||||
AutoNumbering, SortIds, RemoveTranslatableInline]
|
AutoNumbering, SortIds, RemoveTranslatableInline]
|
||||||
|
|
||||||
|
|
||||||
class SphinxI18nReader(SphinxBaseReader):
|
class SphinxI18nReader(SphinxBaseReader):
|
||||||
"""
|
"""
|
||||||
Replacer for document.reporter.get_source_and_line method.
|
Replacer for document.reporter.get_source_and_line method.
|
||||||
|
|
||||||
reST text lines for translation do not have the original source line number.
|
reST text lines for translation do not have the original source line number.
|
||||||
This class provides the correct line numbers when reporting.
|
This class provides the correct line numbers when reporting.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
transforms = [ApplySourceWorkaround, ExtraTranslatableNodes, CitationReferences,
|
transforms = [ApplySourceWorkaround, ExtraTranslatableNodes, CitationReferences,
|
||||||
DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks,
|
DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks,
|
||||||
AutoNumbering, SortIds, RemoveTranslatableInline]
|
AutoNumbering, SortIds, RemoveTranslatableInline]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
SphinxBaseReader.__init__(self, *args, **kwargs)
|
SphinxBaseReader.__init__(self, *args, **kwargs)
|
||||||
self.lineno = None
|
self.lineno = None
|
||||||
|
|
||||||
def set_lineno_for_reporter(self, lineno):
|
def set_lineno_for_reporter(self, lineno):
|
||||||
self.lineno = lineno
|
self.lineno = lineno
|
||||||
|
|
||||||
def new_document(self):
|
def new_document(self):
|
||||||
document = SphinxBaseReader.new_document(self)
|
document = SphinxBaseReader.new_document(self)
|
||||||
reporter = document.reporter
|
reporter = document.reporter
|
||||||
|
|
||||||
def get_source_and_line(lineno=None):
|
def get_source_and_line(lineno=None):
|
||||||
return reporter.source, self.lineno
|
return reporter.source, self.lineno
|
||||||
|
|
||||||
reporter.get_source_and_line = get_source_and_line
|
reporter.get_source_and_line = get_source_and_line
|
||||||
return document
|
return document
|
||||||
|
|
||||||
|
|
||||||
class SphinxDummyWriter(UnfilteredWriter):
|
class SphinxDummyWriter(UnfilteredWriter):
|
||||||
supported = ('html',) # needed to keep "meta" nodes
|
supported = ('html',) # needed to keep "meta" nodes
|
||||||
|
|
||||||
def translate(self):
|
def translate(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class SphinxFileInput(FileInput):
|
class SphinxFileInput(FileInput):
|
||||||
def __init__(self, app, env, *args, **kwds):
|
def __init__(self, app, env, *args, **kwds):
|
||||||
self.app = app
|
self.app = app
|
||||||
self.env = env
|
self.env = env
|
||||||
kwds['error_handler'] = 'sphinx' # py3: handle error on open.
|
kwds['error_handler'] = 'sphinx' # py3: handle error on open.
|
||||||
FileInput.__init__(self, *args, **kwds)
|
FileInput.__init__(self, *args, **kwds)
|
||||||
|
|
||||||
def decode(self, data):
|
def decode(self, data):
|
||||||
if isinstance(data, text_type): # py3: `data` already decoded.
|
if isinstance(data, text_type): # py3: `data` already decoded.
|
||||||
return data
|
return data
|
||||||
return data.decode(self.encoding, 'sphinx') # py2: decoding
|
return data.decode(self.encoding, 'sphinx') # py2: decoding
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
data = FileInput.read(self)
|
data = FileInput.read(self)
|
||||||
if self.app:
|
if self.app:
|
||||||
arg = [data]
|
arg = [data]
|
||||||
self.app.emit('source-read', self.env.docname, arg)
|
self.app.emit('source-read', self.env.docname, arg)
|
||||||
data = arg[0]
|
data = arg[0]
|
||||||
docinfo, data = split_docinfo(data)
|
docinfo, data = split_docinfo(data)
|
||||||
if self.env.config.rst_epilog:
|
if self.env.config.rst_epilog:
|
||||||
data = data + '\n' + self.env.config.rst_epilog + '\n'
|
data = data + '\n' + self.env.config.rst_epilog + '\n'
|
||||||
if self.env.config.rst_prolog:
|
if self.env.config.rst_prolog:
|
||||||
data = self.env.config.rst_prolog + '\n' + data
|
data = self.env.config.rst_prolog + '\n' + data
|
||||||
return docinfo + data
|
return docinfo + data
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
sphinx.util.images
|
sphinx.util.images
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Image utility functions for Sphinx.
|
Image utility functions for Sphinx.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user