Skip to main content

Docstring splicing for python functions 🧬

Project description

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 since the content of your function or class documentation
reside in a single location in the source code, instead of being duplicated within each function body.

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 profound computation. Parameter descriptions follow:
    """

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docsplice-0.1.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

docsplice-0.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file docsplice-0.1.0.tar.gz.

File metadata

  • Download URL: docsplice-0.1.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.12+

File hashes

Hashes for docsplice-0.1.0.tar.gz
Algorithm Hash digest
SHA256 63c754d25629b7c43add5197c1dbd66df73925803a4290b9e32da45b89a86d08
MD5 7fb3ea44933aa01b55c81a339670c2be
BLAKE2b-256 570da769c7beae6bf7bfb55b8825f54fd5eee4ef3562a049f05796a4b33330c2

See more details on using hashes here.

File details

Details for the file docsplice-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: docsplice-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.12+

File hashes

Hashes for docsplice-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fbb3f466319ee3c1d9b1baae8f215f77ea6cae8fb20bd72839fdb04d49c30aa7
MD5 9334f41c384ea2eee4f0f3ff70f4f51e
BLAKE2b-256 fec732122cd2a3dd673a44899732f6ab1d02009a93a098a80ace3d07fa5c5242

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page