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!
- Fork it!
- Create your feature branch
git checkout -b feature/rad
- Commit your changes
git commit -am 'Add something rad'
- Push to the branch
git push origin feature/rad
- Create a new Pull Request
Contact
- e-mail: hannes@saao.ac.za
License
- see LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file docsplice-0.2.0.tar.gz
.
File metadata
- Download URL: docsplice-0.2.0.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8085c4f231a0374774c3c7eb76ff1caf4413dd1fee8dc6cac7fb84179ba696a4 |
|
MD5 | 4064e73a3bf76a071f31dc3a0373450a |
|
BLAKE2b-256 | d1c1cbf82947abfde90c12ff68672afe6957f1512374346ffaff4244d9550e35 |
File details
Details for the file docsplice-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: docsplice-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b478794747fa1d1eb8ca80da3fdce4bdaff3ded7e1de7a1a8ec46596b7f6cf05 |
|
MD5 | 1a31b5de0113446ff401aa737db24715 |
|
BLAKE2b-256 | 8f1bf1943c6f4e05ce7c95e4102146ab20471a5ebc48011ed6d9efbf6f2c57d6 |