Skip to content

autogenerate docstrings for Process subclasses (process interface) #3

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

Closed
benbovy opened this issue Jul 13, 2017 · 3 comments
Closed
Milestone

Comments

@benbovy
Copy link
Member

benbovy commented Jul 13, 2017

Each Process subclass defines an interface which consists of a set of Variable objects (or similar) defined as class attributes.

For more introspection and for documentation purpose (e.g., sphinx autodoc), it would be nice to describe a process interface in the class docstring as an Attributes section, following the numpy doc style.

This can be done automatically using the ProcessBase metaclass. This would avoid writing the same things twice, as information like description or allowed dimensions is already defined in the Variableobjects.

For example

>>> class StackedGrid(Process):
...    """A 2-d stacked grid."""
...    x = Variable('node', description='x coordinate labels')
...    y = Variable('node', description='y coordinate labels')

It would give

>>> print(StackedGrid.__doc__)
StackedGrid
    
    A 2-d stacked grid.

    Attributes
    ----------
    x : Variable
        x coordinate labels.
    y : Variable
        y coordinate labels.

The auto-generate function might also be smart enough so that it provides meaningful documentation text from variable attributes, e.g.,

  • allowed_dims=() -> scalar
  • allowed_dims=('node') -> 1-d array with dimension 'node'
  • default value is 2
  • ...

An issue with this feature is that it would not strictly following the numpy guidelines:

An Attributes section, located below the Parameters section, may be used to describe non-method attributes of the class

It is not really the case here. There is some magic happening when a Process subclass is created (using the metaclass): the defined Variable objects are actually not accessible as class attributes, although when a Process subclass is instantiated it supports back attribute-like access for these objects.

@benbovy
Copy link
Member Author

benbovy commented Jul 14, 2017

Alternatively, using a decorator would be more explicit, e.g.,

@autodoc_vars
class StackedGrid(Process):
    """A 2-d stacked grid.

    {{attributes_section}}
    """
    x = Variable('node', description='x coordinate labels')
    y = Variable('node', description='y coordinate labels')

@benbovy
Copy link
Member Author

benbovy commented Oct 1, 2019

Reusing the process decorator is the best option.

@xs.process(autodoc=True)
class StackedGrid:
    """A 2-d stacked grid.

    {{attributes_section}}
    """
    x = xs.variable('node', description='x coordinate labels')
    y = xs.variable('node', description='y coordinate labels')

@benbovy
Copy link
Member Author

benbovy commented Jan 10, 2020

Closed in #67

@benbovy benbovy closed this as completed Jan 10, 2020
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

No branches or pull requests

1 participant