Sphinx 用の追加コマンドを含むように拡張setup.py
するには、カスタム コマンドを作成できます。Sphinx apidoc を実行してドキュメント ソースをビルドする小さな例を作成しました。で定義されているソースのプロジェクト名、作成者、バージョン、および場所setup.py
が使用されます (それらが定義されていると仮定します)。
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')])
次に、コマンドをエントリ ポイント グループに登録する必要がありますdistutils.commands
。ここで、コマンドは と呼ばれsphinx
ます。
from setuptools import setup
setup(
# ...
setup_requires = ['sphinx'],
entry_points = {
'distutils.commands': [
'sphinx = example_module:Sphinx'
]
}
)
C ソースがどのように処理されるかはわかりませんが、これで始められます。