To extend setup.py
so it contains an extra command for Sphinx, you could create a custom command. I've cooked up a small example that runs Sphinx apidoc and then builds the doc sources. The project name, author, version and location of the sources defined in the setup.py
are used (assuming they are defined).
class Sphinx(Command):
user_options = []
description = 'sphinx'
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
# metadata contains information supplied in setup()
metadata = self.distribution.metadata
# package_dir may be None, in that case use the current directory.
src_dir = (self.distribution.package_dir or {'': ''})['']
src_dir = os.path.join(os.getcwd(), src_dir)
# Run sphinx by calling the main method, '--full' also adds a conf.py
sphinx.apidoc.main(
['', '--full', '-H', metadata.name, '-A', metadata.author,
'-V', metadata.version, '-R', metadata.version,
'-o', os.path.join('doc', 'source'), src_dir])
# build the doc sources
sphinx.main(['', os.path.join('doc', 'source'),
os.path.join('doc', 'build')])
Then the command needs to be registered to the entry point group distutils.commands
. Here the command is called sphinx
.
from setuptools import setup
setup(
# ...
setup_requires = ['sphinx'],
entry_points = {
'distutils.commands': [
'sphinx = example_module:Sphinx'
]
}
)
I don't know how C sources are handled, but this'll get you started.