नहीं एक पूर्ण जवाब है, और अधिक या कम एक प्रारंभिक बिंदु:
autodoc
अजगर निर्देशों को ऑटो निर्देशों अनुवाद करता है। तो अनुवादित पायथन निर्देश प्राप्त करने के लिए कोई ऑटोडोक ईवेंट का उपयोग कर सकता है।
उदाहरण के लिए यदि आप निम्नलिखित है 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)
आप दे देंगे :
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
autodoc
रूप
हालांकि किसी भी स्थिति में, जब अनुवाद पूरा हो गया है, तो आगे की प्रक्रिया के autodoc द्वारा किया यहाँ docstrings करने के लिए अनुकूलित किया जाना है उत्सर्जन करता है।
ऑटोोडोक द्वारा उत्पन्न आरएसटी फ़ाइलों का उपयोग करने के बारे में क्या गलत है (इसलिए केवल ऑटोडायरेक्टिव कोई पूर्ण पीई-डोमेन परिभाषाएं) और उन्हें विस्तारित करें? – bmu
आईपैड्रेस में पहले से ही व्यापक डॉकस्ट्रिंग हैं, इसलिए मैं उन्हें कॉपी और पेस्ट नहीं करना चाहता हूं और बाकी दस्तावेज़ों के लिए उन्हें हाथ से दोबारा सुधारना चाहता हूं। – ncoghlan
तो आपको उन्हें कॉपी क्यों करना है? आप ऑटो निर्देशों के बीच अपना अतिरिक्त दस्तावेज लिख सकते हैं और स्फिंक्स को इसका अनुवाद करने दें, कॉपी करने की कोई आवश्यकता नहीं है। क्षमा करें शायद मैं आपको नहीं समझता (या आपका प्रश्न)। – bmu