Skip to content

decorators for adding api status to class/function docs#991

Open
David-Baddeley wants to merge 1 commit into
python-microscopy:masterfrom
David-Baddeley:apistatus
Open

decorators for adding api status to class/function docs#991
David-Baddeley wants to merge 1 commit into
python-microscopy:masterfrom
David-Baddeley:apistatus

Conversation

@David-Baddeley
Copy link
Copy Markdown
Contributor

In response to #988

Proposed changes:

Currently a bit of a straw-man concept for documenting the API status of various bits of PYME to

a) help writers of 3rd party code determine what is safe to use/call
b) act as mental reminders when maintaining/modifying code when backwards compatibility should be maintained
or there should be a deprecation path.

The decorators will add an API Status section to the class/function docstring

Would be great to get some feedback on whether this is likely to be useful / make sense.

@csoeller, @barentine, @zacsimile

TODOS:

Probably need to change apidoc/napoleon settings to make it recognize the custom docstring section

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 7, 2021

Codecov Report

Merging #991 (abde151) into master (11167ca) will decrease coverage by 0.00%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #991      +/-   ##
==========================================
- Coverage   11.27%   11.26%   -0.01%     
==========================================
  Files         629      630       +1     
  Lines       72338    72348      +10     
==========================================
- Hits         8154     8151       -3     
- Misses      64184    64197      +13     
Impacted Files Coverage Δ
PYME/apistatus.py 0.00% <0.00%> (ø)
PYME/localization/FitFactories/InterpFitR.py 78.18% <0.00%> (-2.73%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 11167ca...abde151. Read the comment docs.

@David-Baddeley
Copy link
Copy Markdown
Contributor Author

proposed usage:

from PYME import apistatus

@apistatus.api
def some_function_we_are_going_to_maintain(...)
    # a function that we expect to be used in 3rd party code / plugins

@apistatus.internal
def _my_magic_function(...)
   # something that we do not expect to (ever) be called from external code
  # NOTE: a leading underscore will always imply @apistatus.internal, whether annotated or not
  # but is used for things that are private to a specific module/class, even within PYME. The purpose of
  # the decorator is actually for classes/functions which might represent an internal API of sorts - 
  # i.e. public within PYME, but not recommended for external use.

@David-Baddeley
Copy link
Copy Markdown
Contributor Author

On the super-long time scale TODO - add a flag to the class/method which alters how APIDoc parses/formats it.

@csoeller
Copy link
Copy Markdown
Contributor

csoeller commented Apr 8, 2021

This seems like a good approach. Its presence in the code will already signal to anybody who seriously works on code what the current/intended status is - as this generally needs looking into the source code anyway. If it eventually shows up in docs good, too, but probably less essential then in the code base. Would also remind any core developer touching certain interfaces may require extra care.

@zacsimile
Copy link
Copy Markdown
Member

I think this is a reasonable middle-ground between writing clear documentation and saying, "it's in the code, good luck". Documentation would eliminate the need for these decorators, but we probably won't document everything anytime soon.

We should definitely make sure the meaning of these flags is in the online docs.

@David-Baddeley
Copy link
Copy Markdown
Contributor Author

@zacsimile - Documentation would not strictly remove the need for the decorators.

  • The alternative of manually putting an API status section in each docstring would result in a lot of extra work, and would be error prone and/or not done.
  • High level documentation (as might be needed) is not directly tied to the functions in question and might not track.
  • People are not necessarily going to remember to read the API summary when modifying functions - to have a flag that will be immediately visible when editing a function should be very useful
  • the decorator approach can be extended to a) automatically collect and summarize all functions that form part of the API and b) potentially introduce C/I checks on modifications to API functions.

@zacsimile
Copy link
Copy Markdown
Member

I think this is worth merging. Can we also add a decorators.rst file describing this and put it under "API Documentation" in hacking.rst?

@David-Baddeley
Copy link
Copy Markdown
Contributor Author

Major issue with this at present is how sphinx/numpydoc treats docstring sections which don't match it's expectations ...

@David-Baddeley
Copy link
Copy Markdown
Contributor Author

looks like sphinx-doc/sphinx#8658 might have a solution ...

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.

3 participants