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

Toctrees for classes and methods using sphinx autosummary #1393

Merged
merged 8 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/source/_templates/_static/css/ignite_theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,21 @@ div.container a.header-logo
line-height: 1;
}

/* automatically generated toctree tables */

article.pytorch-article table.longtable.docutils.align-default colgroup {
display: none;
}

article.pytorch-article table.longtable.docutils.align-default tbody td:first-child {
width: 30%;
}

article.pytorch-article table.longtable.docutils.align-default tbody td {
padding: 0.25rem;
}

article.pytorch-article table.longtable.docutils.align-default tbody td p {
margin-block-start: 0.1em;
margin-block-end: 0.1em;
}
95 changes: 95 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,98 @@

# replaces pending_xref node with desc_type for type annotations
sphinx.domains.python.type_to_xref = lambda t, e=None: addnodes.desc_type("", nodes.Text(t))

# -- Autosummary patch to get list of a classes, funcs automatically ----------

from importlib import import_module
from inspect import getmembers, isclass, isfunction
import sphinx.ext.autosummary
from sphinx.ext.autosummary import Autosummary
from docutils.parsers.rst import directives
from docutils.statemachine import StringList


class BetterAutosummary(Autosummary):
"""Autosummary with autolisting for modules.

By default it tries to import all public names (__all__),
otherwise import all classes and/or functions in a module.

Options:
- :autolist: option to get list of classes and functions from currentmodule.
- :autolist-classes: option to get list of classes from currentmodule.
- :autolist-functions: option to get list of functions from currentmodule.

Example Usage:

.. currentmodule:: ignite.metrics

.. autosummary::
:nosignatures:
:autolist:
"""

# Add new option
_option_spec = Autosummary.option_spec.copy()
_option_spec.update(
{
"autolist": directives.unchanged,
"autolist-classes": directives.unchanged,
"autolist-functions": directives.unchanged,
}
)
option_spec = _option_spec

def run(self):
for auto in ("autolist", "autolist-classes", "autolist-functions"):
if auto in self.options:
# Get current module name
module_name = self.env.ref_context.get("py:module")
# Import module
module = import_module(module_name)

# Get public names (if possible)
try:
names = getattr(module, "__all__")
except AttributeError:
# Get classes defined in the module
cls_names = [
name[0]
for name in getmembers(module, isclass)
if name[-1].__module__ == module_name and not (name[0].startswith("_"))
]
# Get functions defined in the module
fn_names = [
name[0]
for name in getmembers(module, isfunction)
if (name[-1].__module__ == module_name) and not (name[0].startswith("_"))
]
names = cls_names + fn_names
# It may happen that module doesn't have any defined class or func
if not names:
names = [name[0] for name in getmembers(module)]

if auto == "autolist":
# Get list of all classes and functions inside module
names = [
name for name in names if (isclass(getattr(module, name)) or isfunction(getattr(module, name)))
]
else:
if auto == "autolist-classes":
# Get only classes
check = isclass
elif auto == "autolist-functions":
# Get only functions
check = isfunction
else:
raise NotImplementedError

names = [name for name in names if check(getattr(module, name))]

# Update content
self.content = StringList(names)
return super().run()


# Patch original Autosummary
sphinx.ext.autosummary.Autosummary = BetterAutosummary
11 changes: 11 additions & 0 deletions docs/source/contrib/engines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ Contribution module of engines and helper tools

.. currentmodule:: ignite.contrib.engines

.. currentmodule:: ignite.contrib.engines.tbptt

.. autosummary::
:nosignatures:
:autolist:

.. currentmodule:: ignite.contrib.engines.common

.. autosummary::
:nosignatures:
:autolist:

Truncated Backpropagation Throught Time
---------------------------------------
Expand Down
66 changes: 66 additions & 0 deletions docs/source/contrib/handlers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,54 @@ Contribution module of handlers
param_scheduler
---------------

.. currentmodule:: ignite.contrib.handlers.param_scheduler

.. autosummary::
:nosignatures:
:autolist:

.. automodule:: ignite.contrib.handlers.param_scheduler
:members:


lr_finder
---------

.. currentmodule:: ignite.contrib.handlers.lr_finder

.. autosummary::
:nosignatures:
:autolist:

.. automodule:: ignite.contrib.handlers.lr_finder
:members:


time_profilers
---------------

.. currentmodule:: ignite.contrib.handlers.time_profilers

.. autosummary::
:nosignatures:
:autolist:


.. automodule:: ignite.contrib.handlers.time_profilers
:members:


tensorboard_logger
------------------

See `tensorboardX mnist example <https://github.com/pytorch/ignite/blob/master/examples/contrib/mnist/mnist_with_tensorboard_logger.py>`_
and `CycleGAN and EfficientNet notebooks <https://github.com/pytorch/ignite/tree/master/examples/notebooks>`_ for detailed usage.

.. currentmodule:: ignite.contrib.handlers.tensorboard_logger

.. autosummary::
:nosignatures:
:autolist:

.. automodule:: ignite.contrib.handlers.tensorboard_logger
:members:
Expand All @@ -41,6 +67,12 @@ visdom_logger
See `visdom mnist example <https://github.com/pytorch/ignite/blob/master/examples/contrib/mnist/mnist_with_visdom_logger.py>`_
for detailed usage.

.. currentmodule:: ignite.contrib.handlers.visdom_logger

.. autosummary::
:nosignatures:
:autolist:

.. automodule:: ignite.contrib.handlers.visdom_logger
:members:
:inherited-members:
Expand All @@ -52,6 +84,11 @@ neptune_logger
See `neptune mnist example <https://github.com/pytorch/ignite/blob/master/examples/contrib/mnist/mnist_with_neptune_logger.py>`_
for detailed usage.

.. currentmodule:: ignite.contrib.handlers.neptune_logger

.. autosummary::
:nosignatures:
:autolist:

.. automodule:: ignite.contrib.handlers.neptune_logger
:members:
Expand All @@ -61,6 +98,12 @@ for detailed usage.
mlflow_logger
-------------

.. currentmodule:: ignite.contrib.handlers.mlflow_logger

.. autosummary::
:nosignatures:
:autolist:

.. automodule:: ignite.contrib.handlers.mlflow_logger
:members:
:inherited-members:
Expand All @@ -72,13 +115,24 @@ tqdm_logger
See `tqdm mnist example <https://github.com/pytorch/ignite/blob/master/examples/contrib/mnist/mnist_with_tqdm_logger.py>`_
for detailed usage.

.. currentmodule:: ignite.contrib.handlers.tqdm_logger

.. autosummary::
:nosignatures:
:autolist:

.. automodule:: ignite.contrib.handlers.tqdm_logger
:members:

polyaxon_logger
---------------

.. currentmodule:: ignite.contrib.handlers.polyaxon_logger

.. autosummary::
:nosignatures:
:autolist:

.. automodule:: ignite.contrib.handlers.polyaxon_logger
:members:
:inherited-members:
Expand All @@ -89,6 +143,12 @@ wandb_logger
See `wandb mnist example <https://github.com/pytorch/ignite/blob/master/examples/contrib/mnist/mnist_with_wandb_logger.py>`_
for detailed usage.

.. currentmodule:: ignite.contrib.handlers.wandb_logger

.. autosummary::
:nosignatures:
:autolist:

.. automodule:: ignite.contrib.handlers.wandb_logger
:members:
:inherited-members:
Expand All @@ -99,6 +159,12 @@ trains_logger
See `trains mnist example <https://github.com/pytorch/ignite/blob/master/examples/contrib/mnist/mnist_with_trains_logger.py>`_
for detailed usage.

.. currentmodule:: ignite.contrib.handlers.trains_logger

.. autosummary::
:nosignatures:
:autolist:

.. automodule:: ignite.contrib.handlers.trains_logger
:members:
:inherited-members:
Expand Down
24 changes: 9 additions & 15 deletions docs/source/contrib/metrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Contribution module of metrics

.. currentmodule:: ignite.contrib.metrics

.. autosummary::
:nosignatures:
:autolist:

.. automodule:: ignite.contrib.metrics
:members:
:imported-members:
Expand All @@ -26,21 +30,11 @@ metrics useful for regression tasks. Definitions of metrics are based on `Botchk

Complete list of metrics:

- :class:`~ignite.contrib.metrics.regression.CanberraMetric`
- :class:`~ignite.contrib.metrics.regression.FractionalAbsoluteError`
- :class:`~ignite.contrib.metrics.regression.FractionalBias`
- :class:`~ignite.contrib.metrics.regression.GeometricMeanAbsoluteError`
- :class:`~ignite.contrib.metrics.regression.GeometricMeanRelativeAbsoluteError`
- :class:`~ignite.contrib.metrics.regression.ManhattanDistance`
- :class:`~ignite.contrib.metrics.regression.MaximumAbsoluteError`
- :class:`~ignite.contrib.metrics.regression.MeanAbsoluteRelativeError`
- :class:`~ignite.contrib.metrics.regression.MeanError`
- :class:`~ignite.contrib.metrics.regression.MeanNormalizedBias`
- :class:`~ignite.contrib.metrics.regression.MedianAbsoluteError`
- :class:`~ignite.contrib.metrics.regression.MedianAbsolutePercentageError`
- :class:`~ignite.contrib.metrics.regression.MedianRelativeAbsoluteError`
- :class:`~ignite.contrib.metrics.regression.R2Score`
- :class:`~ignite.contrib.metrics.regression.WaveHedgesDistance`
.. currentmodule:: ignite.contrib.metrics.regression

.. autosummary::
:nosignatures:
:autolist:


.. autoclass:: CanberraMetric
Expand Down
12 changes: 12 additions & 0 deletions docs/source/distributed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ ignite.distributed.auto

.. currentmodule:: ignite.distributed.auto

.. autosummary::
:nosignatures:
:autolist:

.. automodule:: ignite.distributed.auto
:members:

Expand All @@ -70,6 +74,10 @@ ignite.distributed.launcher

.. currentmodule:: ignite.distributed.launcher

.. autosummary::
:nosignatures:
:autolist:

.. automodule:: ignite.distributed.launcher
:members:

Expand All @@ -82,6 +90,10 @@ group or spawn multiple processes.

.. currentmodule:: ignite.distributed.utils

.. autosummary::
:nosignatures:
:autolist:

.. automodule:: ignite.distributed.utils
:members:

Expand Down
20 changes: 15 additions & 5 deletions docs/source/engine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ ignite.engine

Main module of the library containing:

- :class:`~ignite.engine.engine.Engine` - abstraction that loops provided data, executes a processing function and returns a result
- :class:`~ignite.engine.events.Events` - events triggered by the :class:`~ignite.engine.engine.Engine` during execution
- :class:`~ignite.engine.events.State` - object to pass internal and user-defined data between event handlers
.. currentmodule:: ignite.engine.engine

.. autosummary::
:nosignatures:
:autolist:

.. currentmodule:: ignite.engine.events

.. autosummary::
:nosignatures:
:autolist:

and helper methods:

- :meth:`~ignite.engine.create_supervised_trainer` - creates single model/optimizer/criterion supervised trainer
- :meth:`~ignite.engine.create_supervised_evaluator` - creates single model supervised evaluation engine
.. currentmodule:: ignite.engine

.. autosummary::
:nosignatures:
:autolist-functions:

More details about those structures can be found in :doc:`concepts`.

Expand Down
4 changes: 4 additions & 0 deletions docs/source/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ ignite.exceptions

.. currentmodule:: ignite.exceptions

.. autosummary::
:nosignatures:
:autolist:

.. autoclass:: NotComputableError
Loading