Skip to content

Commit ef61c81

Browse files
docs: Use Zensical support for mkdocs-autoapi to auto-generate API documentation (#222)
- https://github.com/zensical/zensical/releases/tag/v0.0.66 - https://mkdocs-autoapi.readthedocs.io/en/latest/usage/#controlling-output Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
1 parent f81583f commit ef61c81

11 files changed

Lines changed: 77 additions & 109 deletions

File tree

‎.github/workflows/docs.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ jobs:
4040
- name: Build documentation
4141
run: uvx --with tox-uv tox -e docs
4242

43+
- name: Check for uncommitted autogenerated docs
44+
run: git diff --exit-code docs
45+
4346
- name: Upload documentation as artifact
4447
id: deployment
4548
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0

‎backoff/__init__.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Function decoration for backoff and retry
2+
Function decoration for backoff and retry.
33
44
This module provides function decorators which can be used to wrap a
55
function such that it will be retried until some condition is met. It
@@ -8,8 +8,8 @@
88
APIs. Somewhat more generally, it may also be of use for dynamically
99
polling resources for externally generated content.
1010
11-
For examples and full documentation see the README at
12-
https://github.com/python-backoff/backoff
11+
For examples and full documentation, see
12+
[the official documentation](https://backoff.readthedocs.io/en/latest/).
1313
"""
1414

1515
from backoff._common import Attempt

‎backoff/_decorator.py‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,14 @@ def retry_context(
307307
Unlike `on_exception`, this doesn't wrap a whole function; it lets a
308308
caller retry an arbitrary block of code:
309309
310-
for attempt in backoff.retry_context(ValueError, backoff.expo):
311-
with attempt:
312-
do_something()
310+
```python
311+
for attempt in backoff.retry_context(
312+
ValueError,
313+
backoff.expo,
314+
):
315+
with attempt:
316+
do_something()
317+
```
313318
314319
Each `attempt` is a context manager: exceptions matching `exception`
315320
are caught, and the loop either sleeps and retries or lets the
@@ -403,9 +408,14 @@ def aretry_context(
403408
) -> AsyncGenerator[Attempt, None]:
404409
"""Async counterpart to `retry_context`, for use with `async for`.
405410
406-
async for attempt in backoff.aretry_context(ValueError, backoff.expo):
407-
with attempt:
408-
await do_something()
411+
```python
412+
async for attempt in backoff.aretry_context(
413+
ValueError,
414+
backoff.expo,
415+
):
416+
with attempt:
417+
await do_something()
418+
```
409419
410420
`giveup` and the handlers may be sync or async callables. See
411421
`retry_context` for the full argument reference.

‎backoff/_wait_gen.py‎

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,14 @@ def decay(
3838
decay_factor: float = 1,
3939
min_value: float | None = None,
4040
) -> Generator[float, Any, None]:
41-
"""Generator for exponential decay[1]:
41+
"""Generator for [exponential decay](https://en.wikipedia.org/wiki/Exponential_decay).
4242
4343
Args:
4444
initial_value: initial quantity
4545
decay_factor: exponential decay constant.
4646
min_value: The minimum value to yield. Once the value in the
4747
true exponential sequence is lower than this, the value
4848
of min_value will forever after be yielded.
49-
50-
[1] https://en.wikipedia.org/wiki/Exponential_decay
5149
"""
5250
# Advance past initial .send() call
5351
yield 0
@@ -106,23 +104,39 @@ def runtime(*, value: Callable[[Any], float]) -> Generator[float, Any, None]:
106104
Useful for honoring a server-specified retry delay, e.g. an HTTP
107105
`Retry-After` header, rather than a fixed wait sequence:
108106
109-
# with on_predicate, `value` receives the return value
110-
@backoff.on_predicate(
111-
backoff.runtime,
112-
predicate=lambda r: r.status_code == 429,
113-
value=lambda r: int(r.headers.get("Retry-After", 1)),
114-
)
115-
def get_page():
116-
return requests.get(url)
117-
118-
# with on_exception, `value` receives the raised exception
119-
@backoff.on_exception(
120-
backoff.runtime,
121-
RetryableError,
122-
value=lambda e: e.wait_seconds,
107+
```python
108+
# with on_predicate, `value` receives the return value
109+
@backoff.on_predicate(
110+
backoff.runtime,
111+
predicate=lambda r: (
112+
r.status_code
113+
== 429
114+
),
115+
value=lambda r: (
116+
int(
117+
r.headers.get(
118+
"Retry-After",
119+
1,
120+
)
121+
)
122+
),
123+
)
124+
def get_page():
125+
return requests.get(
126+
url
123127
)
124-
def get_page():
125-
...
128+
129+
130+
# with on_exception, `value` receives the raised exception
131+
@backoff.on_exception(
132+
backoff.runtime,
133+
RetryableError,
134+
value=lambda e: (
135+
e.wait_seconds
136+
),
137+
)
138+
def get_page(): ...
139+
```
126140
127141
Args:
128142
value: a callable which takes as input the decorated

‎docs/api/backoff/index.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::: backoff

‎docs/api/reference.md‎

Lines changed: 0 additions & 74 deletions
This file was deleted.

‎docs/api/summary.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- [backoff](backoff/index.md)

‎docs/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ This will retry the function with exponential backoff whenever a `RequestExcepti
5656
- [Getting Started Guide](getting-started.md) - Detailed tutorial
5757
- [User Guide](user-guide/decorators.md) - Complete reference
5858
- [Examples](examples.md) - Real-world patterns
59-
- [API Reference](api/reference.md) - Full API documentation
59+
- [API Reference](api/backoff/index.md) - Full API documentation
6060

6161
## Project Links
6262

‎pyproject.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ dev = [
4343
]
4444
docs = [
4545
"mkdocstrings[python]~=1.0.2",
46-
"zensical==0.0.57",
46+
"zensical==0.0.66",
4747
]
4848
lint = [
4949
"ruff>=0.16.0",
@@ -68,10 +68,10 @@ typing = [
6868
]
6969

7070
[tool.hatch.build.targets.sdist]
71-
include = ["backoff", "tests"]
71+
include = ["/backoff", "/docs", "/tests"]
7272

7373
[tool.hatch.build.targets.wheel]
74-
include = ["backoff"]
74+
include = ["/backoff"]
7575

7676
[tool.tox]
7777
requires = [ "tox>=4.61", "tox-uv" ]

‎requirements/docs.requirements.txt‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ mkdocstrings-python==2.0.7
5151
packaging==26.3
5252
# via mkdocs
5353
pathspec==1.1.1
54-
# via mkdocs
54+
# via
55+
# mkdocs
56+
# zensical
5557
platformdirs==4.11.4
5658
# via mkdocs-get-deps
5759
pygments==2.21.0
@@ -77,5 +79,5 @@ tomli==2.4.1
7779
# via zensical
7880
watchdog==6.0.0
7981
# via mkdocs
80-
zensical==0.0.57
82+
zensical==0.0.66
8183
# via python-backoff (pyproject.toml:docs)

0 commit comments

Comments
 (0)