Skip to content

Commit

Permalink
Merge pull request sphinx-doc#4077 from stephenfin/move-sphinx-build-…
Browse files Browse the repository at this point in the history
…to-module

sphinx-build: Move code out of 'sphinx.__init__'
  • Loading branch information
tk0miya authored Oct 2, 2017
2 parents a87ca91 + 1f5ed02 commit fda530b
Show file tree
Hide file tree
Showing 9 changed files with 808 additions and 767 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ def sub_commands(self):
include_package_data=True,
entry_points={
'console_scripts': [
'sphinx-build = sphinx:main',
'sphinx-quickstart = sphinx.quickstart:main',
'sphinx-build = sphinx.cmd.build:main',
'sphinx-quickstart = sphinx.cmd.quickstart:main',
'sphinx-apidoc = sphinx.ext.apidoc:main',
'sphinx-autogen = sphinx.ext.autosummary.generate:main',
],
Expand Down
2 changes: 1 addition & 1 deletion sphinx-quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
import sys

if __name__ == '__main__':
from sphinx.quickstart import main
from sphinx.cmd.quickstart import main
sys.exit(main(sys.argv[1:]))
76 changes: 15 additions & 61 deletions sphinx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
from __future__ import absolute_import

import os
import sys
import warnings
from os import path

from .cmd import build
from .deprecation import RemovedInNextVersionWarning

if False:
# For type annotation
from typing import List # NOQA
from .deprecation import RemovedInSphinx20Warning

# by default, all DeprecationWarning under sphinx package will be emit.
# Users can avoid this by using environment variable: PYTHONWARNINGS=
Expand Down Expand Up @@ -63,62 +60,19 @@
pass


def main(argv=sys.argv[1:]):
# type: (List[str]) -> int
if sys.argv[1:2] == ['-M']:
return make_main(argv)
else:
return build_main(argv)


def build_main(argv=sys.argv[1:]):
# type: (List[str]) -> int
"""Sphinx build "main" command-line entry."""
if (sys.version_info[:3] < (2, 7, 0) or
(3, 0, 0) <= sys.version_info[:3] < (3, 4, 0)):
sys.stderr.write('Error: Sphinx requires at least Python 2.7 or 3.4 to run.\n')
return 1
try:
from sphinx import cmdline
except ImportError:
err = sys.exc_info()[1]
errstr = str(err)
if errstr.lower().startswith('no module named'):
whichmod = errstr[16:]
hint = ''
if whichmod.startswith('docutils'):
whichmod = 'Docutils library'
elif whichmod.startswith('jinja'):
whichmod = 'Jinja2 library'
elif whichmod == 'roman':
whichmod = 'roman module (which is distributed with Docutils)'
hint = ('This can happen if you upgraded docutils using\n'
'easy_install without uninstalling the old version'
'first.\n')
else:
whichmod += ' module'
sys.stderr.write('Error: The %s cannot be found. '
'Did you install Sphinx and its dependencies '
'correctly?\n' % whichmod)
if hint:
sys.stderr.write(hint)
return 1
raise

import sphinx.util.docutils
if sphinx.util.docutils.__version_info__ < (0, 10):
sys.stderr.write('Error: Sphinx requires at least Docutils 0.10 to '
'run.\n')
return 1
return cmdline.main(argv) # type: ignore


def make_main(argv=sys.argv[1:]):
# type: (List[str]) -> int
"""Sphinx build "make mode" entry."""
from sphinx import make_mode
return make_mode.run_make_mode(argv[1:]) # type: ignore
def main(*args, **kwargs):
warnings.warn(
'`sphinx.main()` has moved to `sphinx.cmd.build.main()`.',
RemovedInSphinx20Warning,
stacklevel=2,
)
build.main(*args, **kwargs)


if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
warnings.warn(
'`sphinx` has moved to `sphinx.build`.',
RemovedInSphinx20Warning,
stacklevel=2,
)
build.main()
10 changes: 10 additions & 0 deletions sphinx/cmd/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
"""
sphinx.cmd
~~~~~~~~~~
Modules for command line executables.
:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
42 changes: 42 additions & 0 deletions sphinx/cmd/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
"""
sphinx.cmd.build
~~~~~~~~~~~~~~~~
Build documentation from a provided source.
:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""

import sys

if False:
# For type annotation
from typing import List # NOQA


def build_main(argv=sys.argv[1:]):
# type: (List[str]) -> int
"""Sphinx build "main" command-line entry."""
from sphinx import cmdline
return cmdline.main(argv) # type: ignore


def make_main(argv=sys.argv[1:]):
# type: (List[str]) -> int
"""Sphinx build "make mode" entry."""
from sphinx import make_mode
return make_mode.run_make_mode(argv[1:]) # type: ignore


def main(argv=sys.argv[1:]):
# type: (List[str]) -> int
if sys.argv[1:2] == ['-M']:
return make_main(argv)
else:
return build_main(argv)


if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
Loading

0 comments on commit fda530b

Please sign in to comment.