2

I'm trying to document a module I'm maintaining, and I'm finding it very difficult to get my enum classes documented properly. For instance, here's one that I'd like to document properly (source):

class QOSLevel(Enum):
    '''Quality of service levels'''

    #: 500ms (fastest available)
    EXPRESS = '0'                  

    #: 750ms                       
    REAL_TIME = '1'                

    #: 1000ms                      
    FAST = '2'                     

    #: 1500ms                      
    MODERATE = '3'                 

    #: 3000ms                      
    SLOW = '4'                     

    #: 5000ms                      
    DELAYED = '5'                  

My documentation for this is here (source):

.. autoclass:: tda.streaming.StreamClient.QOSLevel 
  :members:                                        
  :undoc-members:                                  
  :member-order: bysource                          

The output looks like this:

enter image description here

Two things are immediately wrong here:

  • First off, the documentation strings I set are not rendering. I've attempted to follow some advice I've received before that worked for generic attributes, but it seems enums are somehow handled differently?

  • Secondly, it seems the :member-order: bysource directive is being ignored. I tried setting this both here and in conf.py, and neither place seems to allow the fields to be emitted in the proper order.

I'm using sphinx v3.0.4 for what it's worth. You can try to replicate the error by copy-pasting the following into your terminal:

git clone https://github.com/alexgolec/tda-api.git
cd tda-api
git checkout remotes/origin/autodoc-bysource-not-working
virtualenv -v virtualenv
source virtualenv/bin/activate
pip install -r requirements.txt
make -f Makefile.sphinx html
open docs-build/html/streaming.html  # Only works on Mac OS    
bad_coder
  • 11,289
  • 20
  • 44
  • 72
alexgolec
  • 26,898
  • 33
  • 107
  • 159
  • 2
    The problem is that the `QOSLevel` class is nested inside the `StreamClient` class. This works: `.. autoclass:: tda.streaming::StreamClient.QOSLevel` (note the colons). See https://stackoverflow.com/q/27337534/407651. – mzjn May 28 '20 at 20:22
  • 1
    This is it! Feel free to upgrade this comment to an answer and I'll accept it. – alexgolec May 28 '20 at 22:18

1 Answers1

3

The problem is that the QOSLevel class is nested inside the StreamClient class. The following works (note the colons):

.. autoclass:: tda.streaming::StreamClient.QOSLevel

See How to document nested classes with Sphinx's autodoc?.

mzjn
  • 48,958
  • 13
  • 128
  • 248