Skip to content

Commit a8cc4b4

Browse files
committed
Fix docs build.
1 parent 0b2215f commit a8cc4b4

File tree

7 files changed

+52
-21
lines changed

7 files changed

+52
-21
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ line_length = 96
2121
[*.rst]
2222
indent_style = space
2323
indent_size = 4
24+
25+
[*.yml]
26+
indent_style = space
27+
indent_size = 2

.readthedocs.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
build:
2+
image: latest
3+
4+
python:
5+
version: 3.8
6+
pip_install: true
7+
extra_requirements:
8+
- docs
9+
- celery
10+
- rq

docs/api.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
API
33
===
44

5+
Jobs
6+
====
7+
58
The main class is ``cacheback.base.Job``. The methods that are intended to be
69
called from client code are:
710

@@ -11,11 +14,13 @@ called from client code are:
1114
It has some class properties than can be used to configure simple behaviour:
1215

1316
.. autoclass:: cacheback.base.Job
17+
:noindex:
1418
:members: lifetime, refresh_timeout, cache_alias, fetch_on_miss, fetch_on_stale_threshold, task_options
1519

1620
There are also several methods intended to be overridden and customised:
1721

1822
.. autoclass:: cacheback.base.Job
23+
:noindex:
1924
:members: key, fetch, expiry, should_missing_item_be_fetched_synchronously, should_stale_item_be_fetched_synchronously, empty, key, prepare_args, prepare_kwargs, timeout, process_result
2025

2126

docs/conf.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@
1919
from django.conf import settings
2020
if not settings.configured:
2121
settings.configure(
22-
DATABASES={
23-
'default': {
24-
'ENGINE': 'django.db.backends.sqlite3',
25-
}
26-
},
22+
DATABASES={ 'default': {'ENGINE': 'django.db.backends.sqlite3'}},
23+
RQ_QUEUES={},
2724
)
2825

2926
# If extensions (or modules to document with autodoc) are in another directory,
@@ -134,7 +131,7 @@
134131
# Add any paths that contain custom static files (such as style sheets) here,
135132
# relative to this directory. They are copied after the builtin static files,
136133
# so a file named "default.css" will overwrite the builtin "default.css".
137-
html_static_path = ['_static']
134+
# html_static_path = ['_static']
138135

139136
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
140137
# using the given strftime format.

docs/index.rst

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ Consider a view for showing a user's tweets:
3232
from myproject.twitter import fetch_tweets
3333

3434
def show_tweets(request, username):
35-
return render(request, 'tweets.html',
36-
{'tweets': fetch_tweets(username)})
35+
return render(
36+
request,
37+
'tweets.html',
38+
{'tweets': fetch_tweets(username)}
39+
)
3740

3841
This works fine but the ``fetch_tweets`` function involves a HTTP round-trip and
3942
is slow.
@@ -49,8 +52,11 @@ Performance can be improved by using Django's `low-level cache API`_:
4952
from myproject.twitter import fetch_tweets
5053

5154
def show_tweets(request, username):
52-
return render(request, 'tweets.html',
53-
{'tweets': fetch_cached_tweets(username)})
55+
return render(
56+
request,
57+
'tweets.html',
58+
{'tweets': fetch_cached_tweets(username)}
59+
)
5460

5561
def fetch_cached_tweets(username):
5662
tweets = cache.get(username)
@@ -83,8 +89,11 @@ cache asynchronously instead of during the request/response cycle:
8389
from myproject.tasks import update_tweets
8490

8591
def show_tweets(request, username):
86-
return render(request, 'tweets.html',
87-
{'tweets': fetch_cached_tweets(username)})
92+
return render(
93+
request,
94+
'tweets.html',
95+
{'tweets': fetch_cached_tweets(username)}
96+
)
8897

8998
def fetch_cached_tweets(username):
9099
item = cache.get(username)
@@ -142,8 +151,11 @@ Here's the same functionality implemented using a django-cacheback decorator:
142151
from cacheback.decorators import cacheback
143152

144153
def show_tweets(request, username):
145-
return render(request, 'tweets.html',
146-
{'tweets': cacheback(60*15, fetch_on_miss=False)(fetch_tweets)(username)})
154+
return render(
155+
request,
156+
'tweets.html',
157+
{'tweets': cacheback(60*15, fetch_on_miss=False)(fetch_tweets)(username)}
158+
)
147159

148160
Here the decorator simply wraps the ``fetch_tweets`` function - nothing else is
149161
needed. Cacheback ships with a flexible Celery task that can run any function
@@ -185,6 +197,7 @@ Contents
185197

186198
.. toctree::
187199
:maxdepth: 2
200+
:glob:
188201

189202
installation
190203
usage

docs/installation.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Installation
44

55
You need to do three things:
66

7-
1. Install django-cacheback
8-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
Install django-cacheback
8+
~~~~~~~~~~~~~~~~~~~~~~~~
99

1010
To install with Celery support, run::
1111

@@ -19,8 +19,8 @@ After installing the package and dependencies, add ``cacheback`` to your ``INSTA
1919
If you want to use RQ as your task queue, you need to set ``CACHEBACK_TASK_QUEUE``
2020
in your settings to ``rq``.
2121

22-
2. Install a message broker
23-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
22+
Install a message broker
23+
~~~~~~~~~~~~~~~~~~~~~~~~
2424

2525
Celery requires a message broker. Use `Celery's tutorial`_ to help set one up.
2626
I recommend rabbitmq.
@@ -32,8 +32,8 @@ up the `django-rq installation guide`_ for more details.
3232
.. _`Celery's tutorial`: http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html
3333
.. _`django-rq installation guide`: https://github.com/ui/django-rq#installation
3434

35-
3. Set up a cache
36-
~~~~~~~~~~~~~~~~~
35+
Set up a cache
36+
~~~~~~~~~~~~~~
3737

3838
You also need to ensure you have `a cache set up`_. Most likely, you'll be using
3939
memcache so your settings will include something like::
@@ -48,7 +48,7 @@ memcache so your settings will include something like::
4848
.. _`a cache set up`: https://docs.djangoproject.com/en/dev/topics/cache/?from=olddocs
4949

5050
Logging
51-
-------
51+
~~~~~~~
5252

5353
You may also want to configure logging handlers for the 'cacheback' named
5454
logger. To set up console logging, use something like::

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ importlib-metadata = {version = "*", python = "<3.8"}
3737
django = ">=2"
3838
celery = {version = ">=4", optional = true}
3939
django-rq = {version = ">=2", optional = true}
40+
Sphinx = {version = ">=3.3.0,<4", optional = true}
4041

4142
[tool.poetry.dev-dependencies]
4243
pytest = ">=6.0"
@@ -53,6 +54,7 @@ django-rq = ">=2"
5354
[tool.poetry.extras]
5455
celery = ["celery"]
5556
rq = ["django-rq"]
57+
docs = ["Sphinx"]
5658

5759
[build-system]
5860
requires = ["poetry>=1.1"]

0 commit comments

Comments
 (0)