Git Product home page Git Product logo

pyment's Introduction

pyment

Create, update or convert docstrings in existing Python files, managing several styles.

Description

This Python (2.7+/3+, or 2.6 if installed argparser) program intends to help Python programmers to enhance inside code documentation using docstrings. It is useful for code not well documented, or code without docstrings, or some not yet or partially documented code, or a mix of all of this :-) It can be helpful also to haromize or change a project docstring style format.

It will parse one or several python scripts and retrieve existing docstrings. Then, for all found functions/methods/classes, it will generate formated docstrings with parameters, default values,...

At the end, patches are generated for each file. Then, man can apply the patches to the initial scripts. An option allow to update the files directly without generating patches. It is also possible to generate the python file with the new docstrings, or to retrieve only the docstrings...

Currently, the managed styles in input/output are javadoc, one variant of reST (re-Structured Text, used by Sphinx), numpydoc, google docstrings, groups (other grouped style).

You can also configure some settings via the command line or a configuration file.

To get further informations please refer to the documentation.

The tool, at the time, offer to generate patches or get a list of the new docstrings (created or converted).

You can contact the developer dadel and speak about the project on IRC Freenode's channel #pyment.

Start quickly

  • get and install:
$ git clone https://github.com/dadadel/pyment.git  # or [email protected]:dadadel/pyment.git
$ cd pyment
$ python setup.py install
  • run from the command line:
$ pyment  myfile.py    # will generate a patch
$ pyment -w myfile.py  # will overwrite the file

or

$ pyment  my/folder/
  • get help:
$ pyment -h
  • run from a script:
import os
from pyment import PyComment

filename = 'test.py'

c = PyComment(filename)
c.proceed()
c.diff_to_file(os.path.basename(filename) + ".patch")
for s in c.get_output_docs():
    print(s)

Example

Here is a full example using Pyment to generate a patch and then apply the patch.

Let's consider a file test.py with following content:

def func(param1=True, param2='default val'):
    '''Description of func with docstring groups style.

    Params:
        param1 - descr of param1 that has True for default value.
        param2 - descr of param2

    Returns:
        some value

    Raises:
        keyError: raises key exception
        TypeError: raises type exception

    '''
    pass

class A:
    def method(self, param1, param2=None):
        pass

Now let's use Pyment:

$ pyment test.py

Using Pyment without any argument will autodetect the docstrings formats and generate a patch using the reStructured Text format. So the previous command has generated the file test.py.patch with following content:

# Patch generated by Pyment v0.2.0

--- a/test.py
+++ b/test.py
@@ -1,20 +1,22 @@
 def func(param1=True, param2='default val'):
-    '''Description of func with docstring groups style.
+    """Description of func with docstring groups style.

-    Params: 
-        param1 - descr of param1 that has True for default value.
-        param2 - descr of param2
+    :param param1: descr of param1 that has True for default value
+    :param param2: descr of param2 (Default value = 'default val')
+    :returns: some value
+    :raises keyError: raises key exception
+    :raises TypeError: raises type exception

-    Returns:
-        some value
-
-    Raises:
-        keyError: raises key exception
-        TypeError: raises type exception
-
-    '''
+    """
     pass

 class A:
+    """ """
     def method(self, param1, param2=None):
+        """
+
+        :param param1: 
+        :param param2:  (Default value = None)
+
+        """
         pass

Let's finally apply the patch with the following command:

$ patch -p1 < test.py.patch

Now the original test.py was updated and its content is now:

def func(param1=True, param2='default val'):
    """Description of func with docstring groups style.

    :param param1: descr of param1 that has True for default value
    :param param2: descr of param2 (Default value = 'default val')
    :returns: some value
    :raises keyError: raises key exception
    :raises TypeError: raises type exception

    """
    pass

class A:
    """ """
    def method(self, param1, param2=None):
        """

        :param param1: 
        :param param2:  (Default value = None)

        """
        pass

Also refer to the files example.py.patch or example_numpy.py.patch to see some other results that can be obtained processing the file example.py

pyment's People

Contributors

dadadel avatar acatton avatar eastein avatar inirudebwoy avatar rbignon avatar eventh avatar jankatins avatar emantor avatar

Watchers

James Cloos avatar tplinux avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.