değil tam cevap, az ya da çok bir başlangıç noktasıdır:
autodoc
piton direktiflerine oto direktiflerini çevirir. Bu nedenle, çevrilmiş python yönergelerini almak için autodoc olaylarını kullanabilirsiniz. Örneğin
Eğer
mymodule.py
aşağıdaki varsa:
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)
size verecektir:
#!/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:
aşağıdaki uzantıyı (veya conf.py
eklenmesini) yaratacak :
Ancak
My module documentation
-----------------------
.. py:module:: mymodule
This is my module.
.. py:class:: mymodule.MyClass(x, y='test')
This is my class
.. py:method:: mymodule.MyClass.my_method(z)
This is my method.
:param z: a number
:type z: float, int
:returns: the sum of self.x and z
:rtype: float
.. py:function:: mymodule.my_test_func(a, b=1)
This is my test function
hiçbir olay, çeviri tamamlandığında, AutoDoc tarafından yapılan Yani ileri işleme burada Docstringler adapte edilmelidir yayar.
Autodoc tarafından oluşturulan rst dosyalarını kullanmayla ilgili yanlış olan (bu nedenle yalnızca tam yol bilgisi tanımları olmayan autodirectives) ve bunları genişletmek nedir? – bmu
ipaddress'in zaten geniş doküman dizeleri var, bu yüzden onları kopyalayıp yapıştırmak ve geri kalan dokümanlar için el ile yeniden biçimlendirmek zorunda kalmak istemiyorum. – ncoghlan
Peki neden bunları kopyalamak zorundasınız? Otomatik yönergelerin arasına ek belgelerinizi yazabilir ve sfenksin kopyalanmasını gerektirmeyebilir. Üzgünüz, belki seni (veya sorunuzu) anlamıyorum. – bmu