Skip to content

ViewingDocstring

ovis-hpc edited this page Feb 3, 2019 · 22 revisions

SOS and numSOS python classes have docstring documentation.

For example, DataSource.py contains the following:

class DataSource(object):

DEF_LIMIT     = 4096
DEF_COL_WIDTH = 16

"""Implements a generic analysis Transform data source.

A DataSource  is a  generic interface to  a container.  An program
does  not instantiate  the  DataSource, rather  it instantiates  a
SosDataSource or CsvDataSource. A SosDataSource is backed by a SOS
Container, and a CsvDataSource is backed by a text file.

The get_results() method of a DataSource returns data as a
DataSet. A DataSet encapsulates on or more named data series. See
the DataSet class for more information.

"""
def __init__(self):
    self.window = self.DEF_LIMIT
    self.col_width = self.DEF_COL_WIDTH
    self.last_result = None

...

def show(self, limit=None, file=sys.stdout, reset=True):
    """Output the data specified by the select() method

    The data is output to the sys.stdout or can be overridden with
    the 'file' keyword parameter. This is a utility function that
    makes it easy for developers to test their select() arguments
    and visually inspec the data returned.

    Keyword Parameters:

    limit -- Specifies the maximum number of rows to print. The
             default is DataSource.DEFAULT_LIMIT.

    file  -- A Python FILE object to output data to. Default is
             sys.stdout.

    reset -- Restart the query at 1st matching row.

    """

    if limit is None:
        limit = self.window
    last_name = None
    for col in self.get_columns():
        if last_name != col.schema_name:
            last_name = col.schema_name
            name = last_name
...

Such documentation can be displayed within ipython. Given a DataSet instance called 'src', some useful options:

Displaying documentation for a module:

In [52]: help(Sos)
Help on module sosdb.Sos in sosdb:

NAME
    sosdb.Sos

FILE
    /home/XXX/BuildSos/lib/python2.7/site-packages/sosdb/Sos.so

CLASSES
    __builtin__.object
        python.Sos.AttrJoinIter
        python.Sos.ColSpec
        python.Sos.Filter
        ...
        python.Sos.SosObject
            python.Sos.Attr
           ...
           python.Sos.Schema
           ...

    exceptions.NameError(exceptions.StandardError)
        python.Sos.ObjAttrError

    class Attr(SosObject)
     |  Method resolution order:
     |      Attr
     |      SosObject
     |      __builtin__.object
     |  
     |  Methods defined here:
     |  
     |  __eq__(...)
     |      x.__eq__(y) <==> x==y
     |  

Displaying documentation for a class within a module:

In [65]: help(SosDataSource)
Help on class SosDataSource in module numsos.DataSource:

class SosDataSource(DataSource)
 |  Implements a SOS DB analysis Transform data source.
 |  
 |  Method resolution order:
 |      SosDataSource
 |      DataSource
 |      __builtin__.object
 |  
 |  Methods defined here:
 |  
 |  __init__(self)
 |  
 |  col_by_name(self, name)
 |  
 |  config(self, **kwargs)
 |      Configure the SOS data source
 |      
 |      Keyword Arguments:
 |      path      - The path to the Sos container
 |      cont      - A Sos.Container handle

Determining available functions:

In [45]: %psearch src.s*
src.schema
src.select
src.set_col_width
src.set_window
src.show
...  

Viewing docstring for a function:

In [48]: help(src.show)
Help on method show in module numsos.DataSource:

show(self, limit=None, file=<open file '<stdout>', mode 'w'>, reset=True) method of numsos.DataSource.SosDataSource instance  
Output the data specified by the select() method

The data is output to the sys.stdout or can be overridden with
the 'file' keyword parameter. This is a utility function that
makes it easy for developers to test their select() arguments
and visually inspec the data returned.

Keyword Parameters:

limit -- Specifies the maximum number of rows to print. The
         default is DataSource.DEFAULT_LIMIT.

file  -- A Python FILE object to output data to. Default is
         sys.stdout.

reset -- Restart the query at 1st matching row.

Question mark queries display forms of docstring or help as well:

In [66]: SosDataSource?
Init signature: SosDataSource(self)
Docstring:     
Implements a SOS DB analysis Transform data source.
    
File:           /home/XXX/BuildSos/lib/python2.7/site-packages/numsos/DataSource.py
Type:           type


In [50]: src.show?
Signature: src.show(limit=None, file=<open file '<stdout>', mode 'w' at 0x7fb914fe8150>, reset=True)
Docstring:
Output the data specified by the select() method

The data is output to the sys.stdout or can be overridden with
the 'file' keyword parameter. This is a utility function that
makes it easy for developers to test their select() arguments
and visually inspec the data returned.

Keyword Parameters:

limit -- Specifies the maximum number of rows to print. The
     default is DataSource.DEFAULT_LIMIT.

file  -- A Python FILE object to output data to. Default is
     sys.stdout.

reset -- Restart the query at 1st matching row.
File:      /home/XXX/BuildSos/lib/python2.7/site-packages/numsos/DataSource.py
Type:      instancemethod

Main

Basic

Data Computations

Reference Docs

Other

Clone this wiki locally