ない完全な答えは、多かれ少なかれ出発点:
autodoc
はPythonのディレクティブに自動ディレクティブを変換します。 したがって、autodocイベントを使用して翻訳されたpythonディレクティブを取得できます。例えば
あなたがmymodule.py
を以下している場合:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This is my module.
"""
def my_test_func(a, b=1):
"""This is my test function"""
return a + b
class MyClass(object):
"""This is my class"""
def __init__(x, y='test'):
"""The init of my class"""
self.x = float(x)
self.y = y
def my_method(self, z):
"""This is my method.
:param z: a number
:type z: float, int
:returns: the sum of self.x and z
:rtype: float
"""
return self.x + z
sphinx-apidoc
は
mymodule Module
===============
.. automodule:: mymodule
:members:
:undoc-members:
:show-inheritance:
次の拡張(またはconf.py
に加えて)を作成します:
NAMES = []
DIRECTIVES = {}
def get_rst(app, what, name, obj, options, signature,
return_annotation):
doc_indent = ' '
directive_indent = ''
if what in ['method', 'attribute']:
doc_indent += ' '
directive_indent += ' '
directive = '%s.. py:%s:: %s' % (directive_indent, what, name)
if signature: # modules, attributes, ... don't have a signature
directive += signature
NAMES.append(name)
rst = directive + '\n\n' + doc_indent + obj.__doc__ + '\n'
DIRECTIVES[name] = rst
def write_new_docs(app, exception):
txt = ['My module documentation']
txt.append('-----------------------\n')
for name in NAMES:
txt.append(DIRECTIVES[name])
print '\n'.join(txt)
with open('../doc_new/generated.rst', 'w') as outfile:
outfile.write('\n'.join(txt))
def setup(app):
app.connect('autodoc-process-signature', get_rst)
app.connect('build-finished', write_new_docs)
はあなたを与えるだろう:
しかし、翻訳が完了すると、autodoc
はイベントが発生しないので、autodocで行われる処理はここではdocstringsに適合させる必要があります。
出典
2012-05-02 21:43:28
bmu
autodocによって生成された最初のファイルを使用することについては何が間違っていますか(つまり、オートディレクティブは完全なpy-domain定義のみです) – bmu
ipaddressには既に豊富なドキュメントストリングがありますので、コピーして貼り付けて残りのドキュメントを手作業で再フォーマットする必要はありません。 – ncoghlan
なぜコピーしなければならないのですか?あなたは自動ディレクティブの間にあなたの追加の文書を書くことができ、それをスフィンクスが翻訳し、コピーする必要はありません。申し訳ありません、おそらく私はあなた(またはあなたの質問)を理解していません。 – bmu