Add your description here
Project description
papertrail
Motivation
- Documentation can get out of date quickly
- Sometimes its harder to explain what a function does in plain english than it is to just show what the input and outputs would be:
- e.g:
- "Multiply the value strings by the amount that is the key".
- vs
f({"a": 1, "b": 2, "c": 4}) == ['a', 'bb', 'cccc']
- e.g:
- Tests are the best form of documentation because they complain when they go out of sync
- Doctests are an interesting way of writing tests however they can be fiddly and harder to set up than proper testing frameworks
- Resorting to only using doctests means missing out on features like fixtures and parameterisation
- Having some tests that are written in tests and some that are in doctests means keeping track of two places as the "source of truth"
Installation
uv add papertrail
Example
Use the example function to capture an example from a test to add to the docstring.
Wrap the example around the function before the equality operation and the function result will be captured and added to the docstring of the function. This only happens if the tests pass!
from papertrail import example
def test_add():
assert example(add, 2, 3) == 5
This has captured the example and now once the tests are finished the docstring of the function will be updated like this:
def add(a: int, b: int) -> int:
"""Papertrail examples:
>>> add(2, 3) == 5
True
::
"""
return a + b
You can use it with parametrized tests too:
@pytest.mark.parametrize(
("args", "kwargs", "expected_result"),
[
pytest.param((2, 2), {}, 0),
pytest.param((2,), {"b": 3}, -1),
],
)
def test_func_b(args, kwargs, expected_result):
assert example(func_b, *args, **kwargs) == expected_result
This captures all the cases and adds them to the functions docstring:
def func_b(a: float, b: float) -> float:
"""Simple docstring
Args:
a (float)
b (float)
Returns:
float
Papertrail examples:
>>> func_b(3, 4) == -1
True
::
"""
return a - b
Repo map
├── .github
│ └── workflows
│ ├── ci_tests.yaml
│ └── publish.yaml
├── docs
│ └── source
│ └── conf.py
├── src
│ └── papertrail
│ ├── adapters
│ │ ├── __init__.py
│ │ └── io_funcs.py # The IO functions for the IO adapters
│ ├── core
│ │ ├── collection
│ │ │ ├── __init__.py
│ │ │ ├── example.py # User entrypoint `example` and it's inner class `Example`
│ │ │ ├── record.py
│ │ │ └── recorder.py
│ │ ├── transformation
│ │ │ ├── __init__.py
│ │ │ ├── ast_editing.py
│ │ │ ├── format_examples.py
│ │ │ └── transform.py # Updates the the docstrings for all the funcs in the files in the example cache.
│ │ ├── __init__.py
│ │ └── logger.py
│ ├── __init__.py
│ └── __main__.py # the pytest hook for sessionfinish
├── tests
│ ├── _mock_data
│ │ ├── mock_src
│ │ │ ├── __init__.py
│ │ │ ├── mod_a.py
│ │ │ └── mod_b.py
│ │ └── tests
│ │ ├── __init__.py
│ │ ├── conftest.py
│ │ ├── test_mod_a.py
│ │ └── test_mod_b.py
│ ├── core
│ │ ├── collection
│ │ │ ├── __init__.py
│ │ │ ├── test_example.py
│ │ │ ├── test_record.py
│ │ │ └── test_recorder.py
│ │ └── transformation
│ │ ├── __init__.py
│ │ ├── test_ast_editing.py
│ │ └── test_format_examples.py
│ └── test_main.py
├── .pre-commit-config.yaml
├── README.md
├── pyproject.toml
├── ruff.toml
└── uv.lock
(generated with repo-mapper-rs)
::
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file papertrail-0.1.0.tar.gz.
File metadata
- Download URL: papertrail-0.1.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2aed2379a65d91037883e85b57f6c54401725aae1d7c3ee7d66a8d9ed1f5dbc
|
|
| MD5 |
d5769ccf607a3779e31c795743e38f4d
|
|
| BLAKE2b-256 |
68d7304f3941b4c6592e2331e74bf6210cf890c0eb049c5a8892b30784dc43e0
|
Provenance
The following attestation bundles were made for papertrail-0.1.0.tar.gz:
Publisher:
publish.yaml on second-ed/papertrail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
papertrail-0.1.0.tar.gz -
Subject digest:
e2aed2379a65d91037883e85b57f6c54401725aae1d7c3ee7d66a8d9ed1f5dbc - Sigstore transparency entry: 908747576
- Sigstore integration time:
-
Permalink:
second-ed/papertrail@95104efbca2dc4e86107231ebabf19ecc4f4f0d3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/second-ed
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@95104efbca2dc4e86107231ebabf19ecc4f4f0d3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file papertrail-0.1.0-py3-none-any.whl.
File metadata
- Download URL: papertrail-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a796ca4c67d6d6aaf122e91e4ba3f8f61db8298cccc1c49c35e793e39856fb85
|
|
| MD5 |
4d92a09860b9fbd3ccf89ee5bdc9e462
|
|
| BLAKE2b-256 |
f6d341a2c211a34b2deda1e9e9e26731c0905417ce01f58b708383ee880b9942
|
Provenance
The following attestation bundles were made for papertrail-0.1.0-py3-none-any.whl:
Publisher:
publish.yaml on second-ed/papertrail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
papertrail-0.1.0-py3-none-any.whl -
Subject digest:
a796ca4c67d6d6aaf122e91e4ba3f8f61db8298cccc1c49c35e793e39856fb85 - Sigstore transparency entry: 908747593
- Sigstore integration time:
-
Permalink:
second-ed/papertrail@95104efbca2dc4e86107231ebabf19ecc4f4f0d3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/second-ed
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@95104efbca2dc4e86107231ebabf19ecc4f4f0d3 -
Trigger Event:
release
-
Statement type: