Giter Club home page Giter Club logo

alphadoc's Introduction

alphadoc

PyPI version ISSUES PULL REQUESTS PyPI - Downloads

Automatic docstring generator and style guide that supports a number of specified conventions for documentation in Python.

Features

  • Auto-generates docstrings with a customizable template for functions.
  • Support for common and widely used docstrings formats such as Numpy, Google, ReStructured Text and Epytext (Javadoc)

Installation

Using pip:

$ pip install alphadoc

Demo

Usage

alphadoc takes your filename and format type as arguments

$ alphadoc <filename> -d <doc_format>

See alphadoc --help for more command-line switches and options!

Options :

Usage: alphadoc [OPTIONS] FILENAME

  Automatic docstring generator and style guide that  supports a
  number of specified conventions for formatting  as well as
  documentation in Python.

Options:
  -d, --doc_format TEXT  Specified format for docstrings from Options-
                         ReST : For ReStructured Text (default); Epytext
                         :  For Epytext (Javadoc); Google : For Google-
                         Style ; Numpydoc : For Numpydoc

  --help                 Show this message and exit.

Example :

Before alphadoc

import ast
import sys

def top_level_functions(body):
    return (f for f in body if isinstance(f, ast.FunctionDef))

def parse_ast(filename):
    with open(filename, "rt") as file:
        return ast.parse(file.read(), filename=filename)

def get_func(filename):
    tree = parse_ast(filename)
    func_list = []
    for func in top_level_functions(tree.body):
        func_list.append(func.name)
    return func_list

After alphadoc

Docstring format:

  • ReStructured Text (default)
import ast
import sys

def top_level_functions(body):
    """
        This is reST style.

        :param param1: this is a first param
        :param param2: this is a second param
        :returns: this is a description of what is returned
        :raises keyError: raises an exception
    """
    return (f for f in body if isinstance(f, ast.FunctionDef))

def parse_ast(filename):
    """
        This is reST style.

        :param param1: this is a first param
        :param param2: this is a second param
        :returns: this is a description of what is returned
        :raises keyError: raises an exception
    """
    with open(filename, "rt") as file:
        return ast.parse(file.read(), filename=filename)

def get_func(filename):
    """
        This is reST style.

        :param param1: this is a first param
        :param param2: this is a second param
        :returns: this is a description of what is returned
        :raises keyError: raises an exception
    """
    tree = parse_ast(filename)
    func_list = []
    for func in top_level_functions(tree.body):
        func_list.append(func.name)
    return func_list
  • Epytext (Javadoc)
import ast
import sys

def top_level_functions(body):
    """
        This is javadoc style.

        @param param1: this is a first param
        @param param2: this is a second param
        @return: this is a description of what is returned
        @raise keyError: raises an exception
    """
    return (f for f in body if isinstance(f, ast.FunctionDef))

def parse_ast(filename):
    """
        This is javadoc style.

        @param param1: this is a first param
        @param param2: this is a second param
        @return: this is a description of what is returned
        @raise keyError: raises an exception
    """
    with open(filename, "rt") as file:
        return ast.parse(file.read(), filename=filename)

def get_func(filename):
    """
        This is javadoc style.

        @param param1: this is a first param
        @param param2: this is a second param
        @return: this is a description of what is returned
        @raise keyError: raises an exception
    """
    tree = parse_ast(filename)
    func_list = []
    for func in top_level_functions(tree.body):
        func_list.append(func.name)
    return func_list
  • Google
import ast
import sys

def top_level_functions(body):
    """
            This is an example of Google style.
            
            Args:
            param1: This is the first param.
            param2: This is a second param.

            Returns:
            This is a description of what is returned.

            Raises:
            KeyError: Raises an exception.
    """
    return (f for f in body if isinstance(f, ast.FunctionDef))

def parse_ast(filename):
    """
            This is an example of Google style.
            
            Args:
            param1: This is the first param.
            param2: This is a second param.

            Returns:
            This is a description of what is returned.

            Raises:
            KeyError: Raises an exception.
    """
    with open(filename, "rt") as file:
        return ast.parse(file.read(), filename=filename)

def get_func(filename):
    """
            This is an example of Google style.
            
            Args:
            param1: This is the first param.
            param2: This is a second param.

            Returns:
            This is a description of what is returned.

            Raises:
            KeyError: Raises an exception.
    """
    tree = parse_ast(filename)
    func_list = []
    for func in top_level_functions(tree.body):
        func_list.append(func.name)
    return func_list
  • Numpydoc
import ast
import sys

def top_level_functions(body):
    """
        Numpydoc description of a kind
        of very exhautive numpydoc format docstring.

        Parameters
        ----------
        first : array_like
            the 1st param name `first`
        second :
            the 2nd param
        third : {'value', 'other'}, optional
            the 3rd param, by default 'value'

        Returns
        -------
        string
            a value in a string

        Raises
        ------
        KeyError
            when a key error
        OtherError
            when an other error
    """
    return (f for f in body if isinstance(f, ast.FunctionDef))

def parse_ast(filename):
    """
        Numpydoc description of a kind
        of very exhautive numpydoc format docstring.

        Parameters
        ----------
        first : array_like
            the 1st param name `first`
        second :
            the 2nd param
        third : {'value', 'other'}, optional
            the 3rd param, by default 'value'

        Returns
        -------
        string
            a value in a string

        Raises
        ------
        KeyError
            when a key error
        OtherError
            when an other error
    """
    with open(filename, "rt") as file:
        return ast.parse(file.read(), filename=filename)

def get_func(filename):
    """
        Numpydoc description of a kind
        of very exhautive numpydoc format docstring.

        Parameters
        ----------
        first : array_like
            the 1st param name `first`
        second :
            the 2nd param
        third : {'value', 'other'}, optional
            the 3rd param, by default 'value'

        Returns
        -------
        string
            a value in a string

        Raises
        ------
        KeyError
            when a key error
        OtherError
            when an other error
    """
    tree = parse_ast(filename)
    func_list = []
    for func in top_level_functions(tree.body):
        func_list.append(func.name)
    return func_list

References

http://daouzli.com/blog/docstring.html

Contributing

alphadoc is fully Open-Source and open for contributions! We request you to respect our contribution guidelines as defined in our CODE_OF_CONDUCT.md and CONTRIBUTING.md

Contributors

alphadoc's People

Contributors

akrish4 avatar eamspoker avatar muthuannamalai12 avatar samir-0711 avatar tusharnankani avatar v2dha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

alphadoc's Issues

Add Issue Template

Would like to add issue templates to these project that will basically explain the type of issue and its description.

PR Template

I can add a pr template, which will have a few checklists and options like uploading screenshots and describing the pr, which will give a better understanding of pr for the maintainer.

ISSUE TEMPLATE

I would like to add issue templates , which will have 3 templates namely bug , feature and proposal templates
It would help the maintainers to understand about what the issue is about
kindly do assign me

Style Cleanup

Using the settings from #3, add a command that cleans up the code in a certain file automatically based on the user's settings. This includes:

  • Detecting the language of the file from the extension

  • Getting the user's settings and cleaning up the code

Set up a basic directory for the cli and python cli function

I have set up a basic directory for the cli if you'll go through it I have commented the necessary things.

  • src folder is the main directory of the cli application in which all the python files are there
  • setup.py contains the setup configuration for the package to be built and published
  • requirements.txt contains all the necessary packages that will be required by the python cli

Testing
Test the package if it works or not by running the following commands in the locally
python setup.py install
python setup.py sdist bdist_wheel
pip install -e .
python-cli

The output would be -

Capture

It invokes the main.py present in the src folder along with the classmodule.py and func.module.py in case we might need to invoke a class or function.

Just test this once if it works just comment on this issue!

Automatically update the contributors in readme

Is there a way to automatically update the contributors in the readme with emoji associated with the type of contribution for instance by looking at the label like documentation or enhancement.

User Settings

Be able to let the user change the settings for the style cleanup. Maybe let the user choose from preset templates.

E.g. where they want the brackets after an if statement:
if () {
or
if ()
{

Add CODE_OF_CONDUCT

Hello there,
I would like to add CODE_OF_CONDUCT file for this repo as a part of DWOC. Kindly assign me this issue.
THANK YOU

Integrate Welcome and Greeting Bot

I would like to contribute to this amazing project
I can add a config file and integrate the bot so that whenever a new user opens a issue or pr , the bot will comment and greet the user with a proper message

Let me know if you are interested

Kindly do assign me
Kindly do add the DWOC and Level label

Commenting Template

Create a command for the CLI that creates templates for comments before every method declaration.

Template should include:

  • Name

  • Function

  • Parameters

  • What the function returns

  • Additional information (this might change based on the language)

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.