kayobe/tools/sphinx8

40 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Sphinx documentation style checker.
This is a very thin wrapper around doc8, that adds support for sphinx-specific
RST directives.
NOTE: We require sphinx>1.5 in order to avoid automatically registering all
directives when any of the directives modules are imported.
"""
import sys
from unittest import mock
import doc8.main
import sphinx.directives
import sphinx.directives.code
import sphinx.directives.patches
from docutils.parsers.rst import directives as docutils_directives
def main():
# NOTE: Registering sphinx.directives.other causes a failure in parsing
# later.
# Sphinx expects an 'app' argument to these functions. Use a mock since we
# don't need to use the application object.
app = mock.Mock()
sphinx.directives.setup(app)
sphinx.directives.code.setup(app)
sphinx.directives.patches.setup(app)
# NOTE(wszumski): Disable broken literal include directive, please see:
# https://github.com/twolfson/restructuredtext-lint/issues/29
del docutils_directives._directives["literalinclude"]
return doc8.main.main()
if __name__ == "__main__":
sys.exit(main())