mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Make mode: refactor using a class and add source dir to the makefile
This commit is contained in:
parent
b74759c67d
commit
1653c5d242
18
doc/Makefile
18
doc/Makefile
@ -5,20 +5,14 @@
|
|||||||
SPHINXOPTS =
|
SPHINXOPTS =
|
||||||
SPHINXBUILD = python ../sphinx-build.py
|
SPHINXBUILD = python ../sphinx-build.py
|
||||||
SPHINXPROJ = sphinx
|
SPHINXPROJ = sphinx
|
||||||
|
SOURCEDIR = .
|
||||||
BUILDDIR = _build
|
BUILDDIR = _build
|
||||||
|
|
||||||
# User-friendly check for sphinx-build
|
# Has to be explicit, otherwise we don't get "make" without targets right.
|
||||||
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
|
|
||||||
$(error \
|
|
||||||
The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx \
|
|
||||||
installed, then set the SPHINXBUILD environment variable to point \
|
|
||||||
to the full path of the '$(SPHINXBUILD)' executable. Alternatively you \
|
|
||||||
can add the directory with the executable to your PATH. \
|
|
||||||
If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
|
|
||||||
endif
|
|
||||||
|
|
||||||
help:
|
help:
|
||||||
@$(SPHINXBUILD) -M help "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||||
|
|
||||||
|
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||||
|
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||||
%:
|
%:
|
||||||
@$(SPHINXBUILD) -M $@ "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||||
|
@ -26,15 +26,6 @@ from sphinx.util.console import bold, blue
|
|||||||
|
|
||||||
proj_name = os.getenv('SPHINXPROJ', '<project>')
|
proj_name = os.getenv('SPHINXPROJ', '<project>')
|
||||||
|
|
||||||
def build_clean(builddir, opts):
|
|
||||||
if not path.exists(builddir):
|
|
||||||
return
|
|
||||||
elif not path.isdir(builddir):
|
|
||||||
print "Error: %r is not a directory!" % builddir
|
|
||||||
return 1
|
|
||||||
print "removing everything under %r..." % builddir
|
|
||||||
for item in os.listdir(builddir):
|
|
||||||
shutil.rmtree(path.join(builddir, item))
|
|
||||||
|
|
||||||
BUILDERS = [
|
BUILDERS = [
|
||||||
("", "html", "to make standalone HTML files"),
|
("", "html", "to make standalone HTML files"),
|
||||||
@ -62,179 +53,200 @@ BUILDERS = [
|
|||||||
("", "coverage", "to run coverage check of the documentation (if enabled)"),
|
("", "coverage", "to run coverage check of the documentation (if enabled)"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def build_help(builddir, opts):
|
|
||||||
print bold("Sphinx v%s" % sphinx.__version__)
|
|
||||||
print "Please use `make %s' where %s is one of" % ((blue('target'),)*2)
|
|
||||||
for osname, bname, description in BUILDERS:
|
|
||||||
if not osname or os.name == osname:
|
|
||||||
print ' %s %s' % (blue(bname.ljust(10)), description)
|
|
||||||
|
|
||||||
|
class Make(object):
|
||||||
|
|
||||||
def build_html(builddir, opts):
|
def __init__(self, srcdir, builddir, opts):
|
||||||
if run_generic_build('html', builddir, opts) > 0:
|
self.srcdir = srcdir
|
||||||
return 1
|
self.builddir = builddir
|
||||||
print
|
self.opts = opts
|
||||||
print 'Build finished. The HTML pages are in %s.' % path.join(builddir, 'html')
|
|
||||||
|
|
||||||
def build_dirhtml(builddir, opts):
|
def builddir_join(self, *comps):
|
||||||
if run_generic_build('dirhtml', builddir, opts) > 0:
|
return path.join(self.builddir, *comps)
|
||||||
return 1
|
|
||||||
print
|
|
||||||
print 'Build finished. The HTML pages are in %s.' % path.join(builddir, 'dirhtml')
|
|
||||||
|
|
||||||
def build_singlehtml(builddir, opts):
|
def build_clean(self):
|
||||||
if run_generic_build('singlehtml', builddir, opts) > 0:
|
if not path.exists(self.builddir):
|
||||||
return 1
|
return
|
||||||
print
|
elif not path.isdir(self.builddir):
|
||||||
print 'Build finished. The HTML page is in %s.' % path.join(builddir, 'singlehtml')
|
print "Error: %r is not a directory!" % self.builddir
|
||||||
|
return 1
|
||||||
|
print "Removing everything under %r..." % self.builddir
|
||||||
|
for item in os.listdir(self.builddir):
|
||||||
|
shutil.rmtree(self.builddir_join(item))
|
||||||
|
|
||||||
def build_pickle(builddir, opts):
|
def build_help(self):
|
||||||
if run_generic_build('pickle', builddir, opts) > 0:
|
print bold("Sphinx v%s" % sphinx.__version__)
|
||||||
return 1
|
print "Please use `make %s' where %s is one of" % ((blue('target'),)*2)
|
||||||
print
|
for osname, bname, description in BUILDERS:
|
||||||
print 'Build finished; now you can process the pickle files.'
|
if not osname or os.name == osname:
|
||||||
|
print ' %s %s' % (blue(bname.ljust(10)), description)
|
||||||
|
|
||||||
def build_json(builddir, opts):
|
def build_html(self):
|
||||||
if run_generic_build('json', builddir, opts) > 0:
|
if self.run_generic_build('html') > 0:
|
||||||
return 1
|
return 1
|
||||||
print
|
print
|
||||||
print 'Build finished; now you can process the JSON files.'
|
print 'Build finished. The HTML pages are in %s.' % self.builddir_join('html')
|
||||||
|
|
||||||
def build_htmlhelp(builddir, opts):
|
def build_dirhtml(self):
|
||||||
if run_generic_build('htmlhelp', builddir, opts) > 0:
|
if self.run_generic_build('dirhtml') > 0:
|
||||||
return 1
|
return 1
|
||||||
print
|
print
|
||||||
print ('Build finished; now you can run HTML Help Workshop with the '
|
print 'Build finished. The HTML pages are in %s.' % self.builddir_join('dirhtml')
|
||||||
'.hhp project file in %s.') % path.join(builddir, 'htmlhelp')
|
|
||||||
|
|
||||||
def build_qthelp(builddir, opts):
|
def build_singlehtml(self):
|
||||||
if run_generic_build('qthelp', builddir, opts) > 0:
|
if self.run_generic_build('singlehtml') > 0:
|
||||||
return 1
|
return 1
|
||||||
print
|
print
|
||||||
print ('Build finished; now you can run "qcollectiongenerator" with the '
|
print 'Build finished. The HTML page is in %s.' % self.builddir_join('singlehtml')
|
||||||
'.qhcp project file in %s, like this:') % path.join(builddir, 'qthelp')
|
|
||||||
print '$ qcollectiongenerator %s.qhcp' % path.join(builddir, 'qthelp', proj_name)
|
|
||||||
print 'To view the help file:'
|
|
||||||
print '$ assistant -collectionFile %s.qhc' % path.join(builddir, 'qthelp', proj_name)
|
|
||||||
|
|
||||||
def build_devhelp(builddir, opts):
|
def build_pickle(self):
|
||||||
if run_generic_build('devhelp', builddir, opts) > 0:
|
if self.run_generic_build('pickle') > 0:
|
||||||
return 1
|
return 1
|
||||||
print
|
print
|
||||||
print "Build finished."
|
print 'Build finished; now you can process the pickle files.'
|
||||||
print "To view the help file:"
|
|
||||||
print "$ mkdir -p $HOME/.local/share/devhelp/" + proj_name
|
|
||||||
print "$ ln -s %s $HOME/.local/share/devhelp/%s" % \
|
|
||||||
(path.join(builddir, 'devhelp'), proj_name)
|
|
||||||
print "$ devhelp"
|
|
||||||
|
|
||||||
def build_epub(builddir, opts):
|
def build_json(self):
|
||||||
if run_generic_build('epub', builddir, opts) > 0:
|
if self.run_generic_build('json') > 0:
|
||||||
return 1
|
return 1
|
||||||
print
|
print
|
||||||
print 'Build finished. The ePub file is in %s.' % path.join(builddir, 'epub')
|
print 'Build finished; now you can process the JSON files.'
|
||||||
|
|
||||||
def build_latex(builddir, opts):
|
def build_htmlhelp(self):
|
||||||
if run_generic_build('latex', builddir, opts) > 0:
|
if self.run_generic_build('htmlhelp') > 0:
|
||||||
return 1
|
return 1
|
||||||
print "Build finished; the LaTeX files are in %s." % path.join(builddir, 'latex')
|
print
|
||||||
if os.name == 'posix':
|
print ('Build finished; now you can run HTML Help Workshop with the '
|
||||||
print "Run `make' in that directory to run these through (pdf)latex"
|
'.hhp project file in %s.') % self.builddir_join('htmlhelp')
|
||||||
print "(use `make latexpdf' here to do that automatically)."
|
|
||||||
|
|
||||||
def build_latexpdf(builddir, opts):
|
def build_qthelp(self):
|
||||||
if run_generic_build('latex', builddir, opts) > 0:
|
if self.run_generic_build('qthelp') > 0:
|
||||||
return 1
|
return 1
|
||||||
os.system('make -C %s all-pdf' % path.join(builddir, 'latex'))
|
print
|
||||||
|
print ('Build finished; now you can run "qcollectiongenerator" with the '
|
||||||
|
'.qhcp project file in %s, like this:') % self.builddir_join('qthelp')
|
||||||
|
print '$ qcollectiongenerator %s.qhcp' % self.builddir_join('qthelp', proj_name)
|
||||||
|
print 'To view the help file:'
|
||||||
|
print '$ assistant -collectionFile %s.qhc' % self.builddir_join('qthelp', proj_name)
|
||||||
|
|
||||||
def build_latexpdfja(builddir, opts):
|
def build_devhelp(self):
|
||||||
if run_generic_build('latex', builddir, opts) > 0:
|
if self.run_generic_build('devhelp') > 0:
|
||||||
return 1
|
return 1
|
||||||
os.system('make -C %s all-pdf-ja' % path.join(builddir, 'latex'))
|
print
|
||||||
|
print "Build finished."
|
||||||
|
print "To view the help file:"
|
||||||
|
print "$ mkdir -p $HOME/.local/share/devhelp/" + proj_name
|
||||||
|
print "$ ln -s %s $HOME/.local/share/devhelp/%s" % \
|
||||||
|
(self.builddir_join('devhelp'), proj_name)
|
||||||
|
print "$ devhelp"
|
||||||
|
|
||||||
def build_text(builddir, opts):
|
def build_epub(self):
|
||||||
if run_generic_build('text', builddir, opts) > 0:
|
if self.run_generic_build('epub') > 0:
|
||||||
return 1
|
return 1
|
||||||
print
|
print
|
||||||
print 'Build finished. The text files are in %s.' % path.join(builddir, 'text')
|
print 'Build finished. The ePub file is in %s.' % self.builddir_join('epub')
|
||||||
|
|
||||||
def build_texinfo(builddir, opts):
|
def build_latex(self):
|
||||||
if run_generic_build('texinfo', builddir, opts) > 0:
|
if self.run_generic_build('latex') > 0:
|
||||||
return 1
|
return 1
|
||||||
print "Build finished; the Texinfo files are in %s." % path.join(builddir, 'texinfo')
|
print "Build finished; the LaTeX files are in %s." % self.builddir_join('latex')
|
||||||
if os.name == 'posix':
|
if os.name == 'posix':
|
||||||
print "Run `make' in that directory to run these through makeinfo"
|
print "Run `make' in that directory to run these through (pdf)latex"
|
||||||
print "(use `make info' here to do that automatically)."
|
print "(use `make latexpdf' here to do that automatically)."
|
||||||
|
|
||||||
def build_info(builddir, opts):
|
def build_latexpdf(self):
|
||||||
if run_generic_build('texinfo', builddir, opts) > 0:
|
if self.run_generic_build('latex') > 0:
|
||||||
return 1
|
return 1
|
||||||
os.system('make -C %s info' % path.join(builddir, 'texinfo'))
|
os.system('make -C %s all-pdf' % self.builddir_join('latex'))
|
||||||
|
|
||||||
def build_gettext(builddir, opts):
|
def build_latexpdfja(self):
|
||||||
dtdir = path.join(builddir, 'gettext', '.doctrees')
|
if self.run_generic_build('latex') > 0:
|
||||||
if run_generic_build('gettext', builddir, opts, doctreedir=dtdir) > 0:
|
return 1
|
||||||
return 1
|
os.system('make -C %s all-pdf-ja' % self.builddir_join('latex'))
|
||||||
print
|
|
||||||
print 'Build finished. The message catalogs are in %s.' % path.join(builddir, 'gettext')
|
|
||||||
|
|
||||||
def build_changes(builddir, opts):
|
def build_text(self):
|
||||||
if run_generic_build('changes', builddir, opts) > 0:
|
if self.run_generic_build('text') > 0:
|
||||||
return 1
|
return 1
|
||||||
print
|
print
|
||||||
print 'Build finished. The overview file is in %s.' % path.join(builddir, 'changes')
|
print 'Build finished. The text files are in %s.' % self.builddir_join('text')
|
||||||
|
|
||||||
def build_linkcheck(builddir, opts):
|
def build_texinfo(self):
|
||||||
res = run_generic_build('linkcheck', builddir, opts)
|
if self.run_generic_build('texinfo') > 0:
|
||||||
print
|
return 1
|
||||||
print ('Link check complete; look for any errors in the above output '
|
print "Build finished; the Texinfo files are in %s." % self.builddir_join('texinfo')
|
||||||
'or in %s.') % path.join(builddir, 'linkcheck', 'output.txt')
|
if os.name == 'posix':
|
||||||
return res
|
print "Run `make' in that directory to run these through makeinfo"
|
||||||
|
print "(use `make info' here to do that automatically)."
|
||||||
|
|
||||||
def build_doctest(builddir, opts):
|
def build_info(self):
|
||||||
res = run_generic_build('doctest', builddir, opts)
|
if self.run_generic_build('texinfo') > 0:
|
||||||
print ("Testing of doctests in the sources finished, look at the "
|
return 1
|
||||||
"results in %s." % path.join(builddir, 'doctest', 'output.txt'))
|
os.system('make -C %s info' % self.builddir_join('texinfo'))
|
||||||
return res
|
|
||||||
|
|
||||||
def build_coverage(builddir, opts):
|
def build_gettext(self):
|
||||||
if run_generic_build('coverage', builddir, opts) > 0:
|
dtdir = self.builddir_join('gettext', '.doctrees')
|
||||||
print "Has the coverage extension been enabled?"
|
if self.run_generic_build('gettext', doctreedir=dtdir) > 0:
|
||||||
return 1
|
return 1
|
||||||
print
|
print
|
||||||
print ("Testing of coverage in the sources finished, look at the "
|
print 'Build finished. The message catalogs are in %s.' % self.builddir_join('gettext')
|
||||||
"results in %s." % path.join(builddir, 'coverage'))
|
|
||||||
|
|
||||||
def build_xml(builddir, opts):
|
def build_changes(self):
|
||||||
if run_generic_build('xml', builddir, opts) > 0:
|
if self.run_generic_build('changes') > 0:
|
||||||
return 1
|
return 1
|
||||||
print
|
print
|
||||||
print 'Build finished. The XML files are in %s.' % path.join(builddir, 'xml')
|
print 'Build finished. The overview file is in %s.' % self.builddir_join('changes')
|
||||||
|
|
||||||
def build_pseudoxml(builddir, opts):
|
def build_linkcheck(self):
|
||||||
if run_generic_build('pseudoxml', builddir, opts) > 0:
|
res = self.run_generic_build('linkcheck')
|
||||||
return 1
|
print
|
||||||
print
|
print ('Link check complete; look for any errors in the above output '
|
||||||
print 'Build finished. The pseudo-XML files are in %s.' % path.join(builddir, 'pseudoxml')
|
'or in %s.') % self.builddir_join('linkcheck', 'output.txt')
|
||||||
|
return res
|
||||||
|
|
||||||
|
def build_doctest(self):
|
||||||
|
res = self.run_generic_build('doctest')
|
||||||
|
print ("Testing of doctests in the sources finished, look at the "
|
||||||
|
"results in %s." % self.builddir_join('doctest', 'output.txt'))
|
||||||
|
return res
|
||||||
|
|
||||||
def run_generic_build(builder, builddir, opts, doctreedir=None):
|
def build_coverage(self):
|
||||||
# compatibility with old Makefile
|
if self.run_generic_build('coverage') > 0:
|
||||||
papersize = os.getenv('PAPER', '')
|
print "Has the coverage extension been enabled?"
|
||||||
if papersize in ('a4', 'letter'):
|
return 1
|
||||||
opts.extend(['-D', 'latex_paper_size=' + papersize])
|
print
|
||||||
if doctreedir is None:
|
print ("Testing of coverage in the sources finished, look at the "
|
||||||
doctreedir = path.join(builddir, 'doctrees')
|
"results in %s." % self.builddir_join('coverage'))
|
||||||
return call([sys.executable, sys.argv[0], '-b', builder,
|
|
||||||
'-d', doctreedir, '.', path.join(builddir, builder)] + opts)
|
def build_xml(self):
|
||||||
|
if self.run_generic_build('xml') > 0:
|
||||||
|
return 1
|
||||||
|
print
|
||||||
|
print 'Build finished. The XML files are in %s.' % self.builddir_join('xml')
|
||||||
|
|
||||||
|
def build_pseudoxml(self):
|
||||||
|
if self.run_generic_build('pseudoxml') > 0:
|
||||||
|
return 1
|
||||||
|
print
|
||||||
|
print 'Build finished. The pseudo-XML files are in %s.' % self.builddir_join('pseudoxml')
|
||||||
|
|
||||||
|
def run_generic_build(self, builder, doctreedir=None):
|
||||||
|
# compatibility with old Makefile
|
||||||
|
papersize = os.getenv('PAPER', '')
|
||||||
|
opts = self.opts
|
||||||
|
if papersize in ('a4', 'letter'):
|
||||||
|
opts.extend(['-D', 'latex_paper_size=' + papersize])
|
||||||
|
if doctreedir is None:
|
||||||
|
doctreedir = self.builddir_join('doctrees')
|
||||||
|
return call([sys.executable, sys.argv[0], '-b', builder,
|
||||||
|
'-d', doctreedir, self.srcdir, self.builddir_join(builder)] + opts)
|
||||||
|
|
||||||
|
|
||||||
def run_make_mode(args):
|
def run_make_mode(args):
|
||||||
if len(args) < 2:
|
if len(args) < 3:
|
||||||
print >>sys.stderr, ('Error: at least two arguments (builder, build '
|
print >>sys.stderr, ('Error: at least 3 arguments (builder, source '
|
||||||
'dir) are required.')
|
'dir, build dir) are required.')
|
||||||
return 1
|
return 1
|
||||||
|
make = Make(args[1], args[2], args[3:])
|
||||||
run_method = 'build_' + args[0]
|
run_method = 'build_' + args[0]
|
||||||
if run_method in globals():
|
if hasattr(make, run_method):
|
||||||
return globals()[run_method](args[1], args[2:])
|
return getattr(make, run_method)()
|
||||||
return run_generic_build(args[0], args[1], args[2:])
|
return make.run_generic_build(args[0])
|
||||||
|
@ -839,16 +839,17 @@ if "%%1" == "pseudoxml" (
|
|||||||
|
|
||||||
# This will become the Makefile template for Sphinx 1.5.
|
# This will become the Makefile template for Sphinx 1.5.
|
||||||
MAKEFILE_NEW = u'''\
|
MAKEFILE_NEW = u'''\
|
||||||
# Makefile for Sphinx documentation
|
# Minimal makefile for Sphinx documentation
|
||||||
#
|
#
|
||||||
|
|
||||||
# You can set these variables from the command line.
|
# You can set these variables from the command line.
|
||||||
SPHINXOPTS =
|
SPHINXOPTS =
|
||||||
SPHINXBUILD = sphinx-build
|
SPHINXBUILD = sphinx-build
|
||||||
SPHINXPROJ = %(project_fn)s
|
SPHINXPROJ = %(project_fn)s
|
||||||
|
SOURCEDIR = %(rsrcdir)s
|
||||||
BUILDDIR = %(rbuilddir)s
|
BUILDDIR = %(rbuilddir)s
|
||||||
|
|
||||||
# User-friendly check for sphinx-build
|
# User-friendly check for sphinx-build.
|
||||||
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
|
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
|
||||||
$(error \
|
$(error \
|
||||||
The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx \
|
The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx \
|
||||||
@ -860,11 +861,14 @@ endif
|
|||||||
|
|
||||||
# Has to be explicit, otherwise we don't get "make" without targets right.
|
# Has to be explicit, otherwise we don't get "make" without targets right.
|
||||||
help:
|
help:
|
||||||
\t@$(SPHINXBUILD) -M help "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
\t@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||||
|
|
||||||
# Catch-all target using the new "make mode" option.
|
# You can add custom targets here.
|
||||||
|
|
||||||
|
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||||
|
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||||
%:
|
%:
|
||||||
\t@$(SPHINXBUILD) -M $@ "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
\t@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# This will become the make.bat template for Sphinx 1.5.
|
# This will become the make.bat template for Sphinx 1.5.
|
||||||
|
Loading…
Reference in New Issue
Block a user