@documented decorator plus unit test plus sphinx.ext.autodoc

New mechanism for marking datasette.utils functions that should be covered by the
documentation, then testing that they have indeed been documented.

Also enabled sphinx.ext.autodoc which can now be used to embed the documented
versions of those functions.

Refs #1176
This commit is contained in:
Simon Willison 2022-02-06 22:30:00 -08:00
commit d9b508ffaa
4 changed files with 43 additions and 4 deletions

View file

@ -12,6 +12,7 @@ import os
import re
import shlex
import tempfile
import typing
import time
import types
import shutil
@ -59,8 +60,17 @@ Column = namedtuple(
"Column", ("cid", "name", "type", "notnull", "default_value", "is_pk", "hidden")
)
functions_marked_as_documented = []
async def await_me_maybe(value):
def documented(fn):
functions_marked_as_documented.append(fn)
return fn
@documented
async def await_me_maybe(value: typing.Any) -> typing.Any:
"If value is callable, call it. If awaitable, await it. Otherwise return it."
if callable(value):
value = value()
if asyncio.iscoroutine(value):
@ -915,7 +925,9 @@ class BadMetadataError(Exception):
pass
def parse_metadata(content):
@documented
def parse_metadata(content: str) -> dict:
"Detects if content is JSON or YAML and parses it appropriately."
# content can be JSON or YAML
try:
return json.loads(content)