Giter VIP home page Giter VIP logo

docsplice's Introduction

DocSplice

Docstring splicing for python functions ๐Ÿงฌ

This project allows you to splice docstrings for python functions in a convenient way using a functional decorator. This enables you to more easily create consistent documentation for your API without needing to duplicate docstring sections for functions that have the same parameter descriptions or other related content. This will ease the maintenance burden for your package documentation.

Install

pip install docsplice

Use

Pulling parameters from multiple sources

import docsplice as doc


def fun1(a):
    """
    Do something with a number.

    Parameters
    ----------
    a : int
        The number.
    """
    
def fun2(b=0):
    """
    Another function that does something with an integer.
    
    Parameters
    ----------
    b : int, optional
        Another number! By default 0.
    """

@doc.splice({'Parameters[a]': fun1,
             'Parameters[b] as n=7': fun2}) 
def combined(a, n=7):
    """
    Some profound computation. Parameter descriptions follow:
    """

The Parameters section in the docstring for combined has been created by the splice decorator. Inspecting the object in an interactive terminal reveals that the docstring has been filled:

combined??
Signature: combined(a, n=7)
Docstring:
Some profound computation. Parameter descriptions follow:

Parameters
----------
a : int
    The number.
n : int, optional
    Another number! By default 7.
Source:   
@doc.splice({'Parameters[a]': fun1,
             'Parameters[b] as n=7': fun2}) 
def combined(a, n=7):
    """
    Some significant text.
    """

For more examples see Documentation

Test

The test suite contains further examples of how DocSplice can be used. Testing is done with pytest:

pytest docsplice

Contribute

Contributions are welcome!

  1. Fork it!
  2. Create your feature branch
    git checkout -b feature/rad
  3. Commit your changes
    git commit -am 'Add something rad'
  4. Push to the branch
    git push origin feature/rad
  5. Create a new Pull Request

Contact

License

docsplice's People

Contributors

astromancer avatar sourcery-ai-bot avatar

Watchers

 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.