Skip to content

Commit aa922f1

Browse files
authored
Improve documentation for typed dicts (#441)
1 parent 2a6418e commit aa922f1

5 files changed

Lines changed: 59 additions & 9 deletions

File tree

docs/source/conf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"sphinx_click.ext",
7575
"sphinx_automodapi.automodapi",
7676
"sphinx_automodapi.smart_resolver",
77+
"sphinx_toolbox.more_autodoc.autotypeddict",
7778
]
7879

7980
# generate autosummary pages
@@ -258,3 +259,7 @@
258259

259260
# Output SVG inheritance diagrams
260261
graphviz_output_format = "svg"
262+
263+
# sphinx_autodoc_typehints configuration
264+
always_document_param_types = True
265+
autodoc_typehints = "description"

docs/source/usage.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
Usage
2-
=====
1+
Reference
2+
=========
33

4-
.. automodule:: pyobo
5-
:members:
4+
.. automodapi:: pyobo
5+
:no-heading:
6+
7+
.. automodapi:: pyobo.constants
8+
:no-heading:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ docs = [
102102
"sphinx-rtd-theme>=3.0",
103103
"sphinx-click",
104104
"sphinx_automodapi",
105+
"sphinx_toolbox",
105106
]
106107
lint = [
107108
"ruff",

src/pyobo/constants.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,21 @@
1414

1515
__all__ = [
1616
"DATABASE_DIRECTORY",
17+
"DEFAULT_PREFIX_MAP",
18+
"ONTOLOGY_GETTERS",
19+
"PROVENANCE_PREFIXES",
1720
"RAW_DIRECTORY",
1821
"SPECIES_REMAPPING",
22+
"DatabaseKwargs",
23+
"GetOntologyKwargs",
24+
"IterHelperHelperDict",
25+
"LookupKwargs",
26+
"OntologyFormat",
27+
"OntologyPathPack",
28+
"SlimGetOntologyKwargs",
29+
"check_should_cache",
30+
"check_should_force",
31+
"check_should_use_tqdm",
1932
]
2033

2134
logger = logging.getLogger(__name__)
@@ -96,6 +109,8 @@
96109

97110
NCBITAXON_PREFIX = "ncbitaxon"
98111
DATE_FORMAT = "%d:%m:%Y %H:%M"
112+
113+
#: Prefixes for resources that are considered as provenance
99114
PROVENANCE_PREFIXES = {
100115
"pubmed",
101116
"pmc",
@@ -117,13 +132,21 @@
117132
class DatabaseKwargs(TypedDict):
118133
"""Keyword arguments for database CLI functions."""
119134

135+
#: Should strict identifier parsing be enabled?
120136
strict: bool
137+
#: Should re-download and re-processing be forced?
121138
force: bool
139+
#: Should re-processing be forced?
122140
force_process: bool
123-
skip_pyobo: bool
141+
142+
#: Should a progress bar be used?
143+
use_tqdm: bool
144+
#: Skip all prefixes lexicographically sorted below the given prefix
124145
skip_below: str | None
146+
#: If true, skips prefixes that are ontologized as sources in PyOBO
147+
skip_pyobo: bool
148+
#: An enumerated set of prefixes to skip
125149
skip_set: set[str] | None
126-
use_tqdm: bool
127150

128151

129152
class SlimGetOntologyKwargs(TypedDict):
@@ -134,8 +157,11 @@ class SlimGetOntologyKwargs(TypedDict):
134157
only a single ontology is requested.
135158
"""
136159

160+
#: Should strict identifier parsing be enabled?
137161
strict: NotRequired[bool]
162+
#: Should re-download and re-processing be forced?
138163
force: NotRequired[bool]
164+
#: Should re-processing be forced?
139165
force_process: NotRequired[bool]
140166

141167

@@ -145,8 +171,11 @@ class GetOntologyKwargs(SlimGetOntologyKwargs):
145171
This dictionary doesn't contain ``prefix`` since this is always explicitly handled.
146172
"""
147173

174+
#: The version of the ontology to get
148175
version: NotRequired[str | None]
176+
#: Should the cache be used?
149177
cache: NotRequired[bool]
178+
#: Should a progress bar be used?
150179
use_tqdm: NotRequired[bool]
151180

152181

@@ -186,12 +215,17 @@ class IterHelperHelperDict(SlimGetOntologyKwargs):
186215
:func:`pyobo.get_ontology` in each iteration.
187216
"""
188217

218+
#: Should a progress bar be used?
189219
use_tqdm: bool
220+
#: Skip all prefixes lexicographically sorted below the given prefix
190221
skip_below: str | None
222+
#: If true, skips prefixes that are ontologized as sources in PyOBO
191223
skip_pyobo: bool
224+
#: An enumerated set of prefixes to skip
192225
skip_set: set[str] | None
193226

194227

228+
#: The ontology format
195229
OntologyFormat: TypeAlias = Literal["obo", "owl", "json", "rdf"]
196230

197231
#: from table 2 of the Functional OWL syntax definition
@@ -207,7 +241,9 @@ class IterHelperHelperDict(SlimGetOntologyKwargs):
207241
class OntologyPathPack(NamedTuple):
208242
"""A format and path tuple."""
209243

244+
#: The ontology format
210245
format: OntologyFormat
246+
#: The path to the ontology file
211247
path: Path
212248

213249

src/pyobo/getters.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@
4545
from .version import get_git_hash, get_version
4646

4747
__all__ = [
48+
"REQUIRES_NO_ROBOT_CHECK",
49+
"SKIP",
4850
"NoBuildError",
51+
"UnhandledFormatError",
52+
"db_output_helper",
4953
"get_ontology",
54+
"iter_helper",
55+
"iter_helper_helper",
5056
]
5157

5258
logger = logging.getLogger(__name__)
@@ -112,8 +118,6 @@ def get_ontology(
112118
113119
:returns: An OBO object
114120
115-
:raises OnlyOWLError: If the OBO foundry only has an OWL document for this resource.
116-
117121
Alternate usage if you have a custom url
118122
119123
.. code-block:: python
@@ -220,7 +224,8 @@ def _ensure_ontology_path(
220224
return None
221225

222226

223-
SKIP = {
227+
#: A dictioanry of prefixes to skip during full build with reasons as values
228+
SKIP: dict[str, str] = {
224229
"ncbigene": "too big, refs acquired from other dbs",
225230
"pubchem.compound": "top big, can't deal with this now",
226231
"gaz": "Gazetteer is irrelevant for biology",

0 commit comments

Comments
 (0)