Commit e0bf525
authored
Extract and re-inject base client sphinx param doc into client classes, for better sphinx doc (#1131)
* Extract and re-inject base client sphinx param doc
Add three helpers to `utils` in order to improve the runtime
docstrings for client classes.
1. `read_sphinx_params` -- a simple `:param:` parser
2. `inject_sphinx_params` -- a `__doc__` rewriter which takes parsed
params and inserts them in place of a special marker comment
3. `inject_sphinx_params_of` -- a decorator version of these which
chains together reading the docstring of one object and
modifying the docstring of another
Then apply these to write
```python
@utils.inject_sphinx_params_of(client.BaseClient)
class FlowsClient(client.BaseClient):
...
```
and so forth. This is applied to all client classes except for the
Auth login clients, which do not inherit all of the parameters of
`BaseClient` -- in particular, we do not allow construction of a
login client with an `app`.
`read_sphinx_params` gets a functools cache, but the rest of the work
is still done dynamically, so there is a little bit of repetition.
This results in improved docstrings for sphinx and for runtime usages
like `help(globus_sdk.TransferClient)`. Static analyzers (e.g., IDEs)
will pick up on the original source string, which will show the marker
comment used to drive this behavior:
```
.. globus-sdk-inject-doc-params
```
* Convert copy-params to custom sphinx directive
- Remove utility functions for adding parsed `:param:` doc to a
runtime docstring
- Add a new `CopyParams` sphinx directive registered under the name
`sdk-sphinx-copy-params`, and use this to implement param
copy/injection functionality as a documentation-time customization.
There are some particulars about how this looks in the Sphinx/docutils
context which drive the implementation to look a little different from
discussed ideas:
1. The source for doc has to be explicit. `:inherit:` or similar ideas
about picking up the current class and class hierarchy aren't
easily implemented in a sphinx plugin. The context of directive
execution isn't populated with easy values for inspection, and
finding the "current object being documented" is much more work
than it is worth. So each usage specifies `BaseClient` as the
source. (required param)
2. We support added parameters as directive contents. Having a custom
directive adjacent to a `:param:` list causes docutils errors which
kill the entire build. Having blank lines between `:param:` lists
causes multiple `PARAMETERS` blocks to get rendered. So we need
adjacency but we can't have _literal_ adjacency. If we put params
into the content area, we can re-emit them from the directive.
2a. Supporting added parameters before and/or after the copied params
with "<YIELD>". Although not strictly necessary, I've tested to
ensure we can add params before or after the generated/copied
params by having a special line in the content of "<YIELD>". The
first time the directive sees this line, it will stop emitting
content, emit the copied params, and then resume.
* Minor variable rename + comment per review1 parent 63b49b1 commit e0bf525
File tree
12 files changed
+156
-2
lines changed- changelog.d
- src/globus_sdk
- services
- auth/client
- compute
- flows
- gcs
- groups
- search
- timers
- transfer
- tests/unit
12 files changed
+156
-2
lines changedLines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
338 | 370 | | |
339 | 371 | | |
340 | 372 | | |
| |||
365 | 397 | | |
366 | 398 | | |
367 | 399 | | |
| 400 | + | |
368 | 401 | | |
369 | 402 | | |
370 | 403 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
353 | 355 | | |
354 | 356 | | |
355 | 357 | | |
| 358 | + | |
| 359 | + | |
356 | 360 | | |
357 | 361 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
833 | 835 | | |
834 | 836 | | |
835 | 837 | | |
836 | | - | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
837 | 841 | | |
838 | 842 | | |
839 | 843 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
0 commit comments