Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish doc refactor to use extdoclink and tabs instead of doc_api_method and to put example usages in tabs #714

Merged
merged 17 commits into from
Apr 12, 2023

Conversation

sirosen
Copy link
Member

@sirosen sirosen commented Apr 12, 2023

Overall, I'm aiming to push us into "the next phase" regarding docstring formatting.

Example Usages

Older method examples are written with a boldface pseudo-header, **Examples**. In all cases, this is converted to a tab containing the examples, as part of the per-method tab-set.

External Links

Prior to this work, we had two ways to produce commonly structured external doc links.
Old: the doc_api_method decorator.
New: the extdoclink directive.

At the end of this series of changes, only the new way survives, and is always used inside of an API Info tab.

Review considerations & other changes

Each commit here is a separately reviewable step in the journey towards this state.
I worked one module at a time, intentionally leaving Transfer for last.
Along the way, the following notable related pieces accrued, in order of appearance:

  • A fix to extdoclink produces links which aren't usable as references (a.k.a. "anonymous"), which fixes doc build failures due to conflicts between link names and method names
  • Scripts to convert examples, doc_api_method decoration, and API method strings to tab-sets are added, run, and then removed (for TransferClient only)
  • We now use pygrep to enforce that .. code-block:: cannot appear at the end of a line (without a following language). This guarantees that blacken-docs can correctly identify these blocks

Changelog

  • Documentation for client methods has been improved to more consistently
    format and display examples and other information

sirosen added 15 commits April 11, 2023 22:55
All remaining methods of the SearchClient which were not already
converted to this method now use the tab-set and tab-item ReST blocks
to document any examples and the API reference info.
API Info doc tabs are now in place for all methods. Where there was
existing tab structure, these are added as the last tab. Where there
were no tabs, tabs have been introduced for this purpose.

This replaces the `_flowdoc` decorator, so that has been removed.
Wherever `doc_api_method` was used within the AuthClient, the tab-set
documentation is now used, and external links are referenced using
extdoclink, just like other services.

In the particular case of get_identities, blacken docs and manual
reformatting were slightly more extensive than in some other examples
being converted to this style, but extraneous changes were avoided.
doc_api_method was only used for oauth2_start_flow, but in this place
we now use the tabs for documentation and the API Info section is
populated with specific and appropriate content.

doc_api_method supported passing in a format string, a behavior which
does not seem fully necessary and is intentionally omitted from
extdoclink.
Where doc_api_method was used, introduce an API Info tab instead.

As with NativeAppAuthClient, the oauth2_start_flow method is a special
case which does not use extdoclink.
For all GCSClient methods, replace the custom decorator (_gcsdoc) with
use of the tabbed doc layout and an API Info tab. The content therein
is populated by the appropriate extdoclink usage.
Links ending with `_` are made into reference targets, whereas those
ending with `__` are not. This "anonymous reference" behavior is part
of the RST specification, not only a sphinx behavior.

When sphinx sees multiple targets with the same name in a document, it
emits a warning, which we turn into an error with `-W`.

The duplicates easily occur with these links, which often match method
names. Using the `__` behavior dodges the problem.
code-block directives with no language specified are not targetted by
blacken-docs automatically. For this reason, we are removing them from
various other clients where they appear. Remove them from GroupsClient
as well, even though blacken-docs makes no changes.
This script converts examples from the bold header style to the tabbed
documentation style. It makes some simple assumptions.
All examples using the bolded header style are converted to use the
tab-set, tab-item style, and to put any pycon blocks into python code
blocks as appropriate.

This was done by first running the example conversion script, and then
a few editor macros.

In addition to these changes, blacken-docs was run and `format()`
calls were converted to f-strings in the changed blocks. A few
formatted blocks exceed the line length limit and therefore have their
docstrings marked with `noqa: E501`.
Add a script which converts the standard API route reference strings
to 'API Info' tabs in the method documentation tab-sets for each
TransferClient method, and run this script.

Additionally, tab-set declarations need to be added where they were
missing.
Write a script to replace uses of doc_api_method decorator with the
extdoclink, prepare the transfer client file by making all of the
doc_api_method calls one line (using editor macros), then apply the
script.
- Remove utils.doc_api_method as it is no longer used anywhere
- Remove each of the client code transformation scripts
Using pre-commit pygrep, enforce that any code-block directive must
take an argument (the language) so that code-blocks always set python
explicitly. As a result, blacken-docs should always detect them
correctly.

Applying the changes as required by the hook allows blacken-docs to
modify one of the relevant blocks.
src/globus_sdk/services/search/client.py Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
src/globus_sdk/_sphinxext.py Show resolved Hide resolved
src/globus_sdk/services/auth/client/native_client.py Outdated Show resolved Hide resolved
src/globus_sdk/services/auth/client/confidential_client.py Outdated Show resolved Hide resolved
src/globus_sdk/services/flows/client.py Outdated Show resolved Hide resolved
src/globus_sdk/services/gcs/client.py Outdated Show resolved Hide resolved
src/globus_sdk/services/search/client.py Outdated Show resolved Hide resolved
src/globus_sdk/services/transfer/client.py Outdated Show resolved Hide resolved
src/globus_sdk/services/transfer/client.py Outdated Show resolved Hide resolved
sirosen and others added 2 commits April 12, 2023 15:13
@sirosen sirosen merged commit 410df62 into globus:main Apr 12, 2023
@sirosen sirosen deleted the finish-doc-refactor branch April 12, 2023 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants