move API generation to setup.py

This commit is contained in:
Antoine Beaupré 2015-10-07 19:55:56 -04:00
parent 28cbc6cbd1
commit 4787424a66
2 changed files with 40 additions and 17 deletions

View File

@ -36,7 +36,7 @@ help:
clean:
-rm -rf $(BUILDDIR)/*
html: usage api.rst
html: usage
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
@ -153,18 +153,3 @@ usage/%.rst.inc: ../borg/archiver.py
@borg help $* --usage-only | sed -e 's/^/ /' >> $@
@printf "\nDescription\n~~~~~~~~~~~\n" >> $@
@borg help $* --epilog-only >> $@
api.rst: Makefile
@echo "auto-generating API documentation"
@echo "Borg Backup API documentation" > $@
@echo "=============================" >> $@
@echo "" >> $@
@for mod in ../borg/*.pyx ../borg/*.py; do \
if echo "$$mod" | grep -q "/_"; then \
continue ; \
fi ; \
printf ".. automodule:: "; \
echo "$$mod" | sed "s!\.\./!!;s/\.pyx\?//;s!/!.!"; \
echo " :members:"; \
echo " :undoc-members:"; \
done >> $@

View File

@ -3,6 +3,10 @@ import os
import sys
from glob import glob
from distutils.command.build import build
from distutils.core import Command
from distutils.errors import DistutilsOptionError
min_python = (3, 2)
my_python = sys.version_info
@ -115,8 +119,42 @@ elif not on_rtd:
with open('README.rst', 'r') as fd:
long_description = fd.read()
class build_api(Command):
description = "generate a basic api.rst file based on the modules available"
cmdclass = {'build_ext': build_ext, 'sdist': Sdist}
user_options = [
('output=', 'O', 'output directory'),
]
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
print("auto-generating API documentation")
with open("docs/api.rst", "w") as api:
api.write("""
Borg Backup API documentation"
=============================
""")
for mod in glob('borg/*.py') + glob('borg/*.pyx'):
print("examining module %s" % mod)
if "/_" not in mod:
api.write("""
.. automodule:: %s
:members:
:undoc-members:
""" % mod)
# (function, predicate), see http://docs.python.org/2/distutils/apiref.html#distutils.cmd.Command.sub_commands
build.sub_commands.append(('build_api', None))
cmdclass = {
'build_ext': build_ext,
'build_api': build_api,
'sdist': Sdist
}
ext_modules = []
if not on_rtd: