I have written a epytext to reST markup converter, and now I want to convert all the docstrings in my entire library from epytext to reST format.
Is there a smart way to read the all the docstrings in a module and write back the replacements?
ps: ast module perhaps?
Pyment is a tool that can convert Python docstrings and create missing ones skeletons. It can manage Google, Epydoc (javadoc style), Numpydoc, reStructuredText (reST, Sphinx default) docstring formats.
It accepts a single file or a folder (exploring also sub-folders). For each file, it will recognize each docstring format and convert it to the desired one. At the end, a patch will be generated to apply to the file.
Type the following (you can use a virtualenv):
$ git clone https://github.com/dadadel/pyment.git
$ cd pyment
$ python setup.py install
You can convert your project to Sphinx format (reST), which is the default output format, by doing:
$ pyment /my/folder/project
EDIT:
$ pip install git+https://github.com/dadadel/pyment.git
It might be an overkill for this simple usage, but I'd look into using the machinery of 2to3 to do the editing. You just need to write a custom fixer. It's not well-documented, but Developer's Guide to Python 3.0: Python 2.6 and Migrating From 2 to 3: More about 2to3 and Implement Custom Fixers gives enough detail to get started...
Epydoc seems to contain a to_rst()
method which might help you actually translate the docstrings. Don't know if it's any good...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With