From bedf46b877c597a93672db5946d4fce4777a215f Mon Sep 17 00:00:00 2001 From: Pavel Korshunov <pavel.korshunov@idiap.ch> Date: Sun, 23 Oct 2016 14:12:04 +0200 Subject: [PATCH] Added nitpicky to sphinx and fixed warnings --- bob/bio/base/algorithm/BIC.py | 5 ++-- bob/bio/base/algorithm/__init__.py | 8 ++++++ bob/bio/base/database/__init__.py | 6 +++++ bob/bio/base/database/database.py | 36 +++++++++++++-------------- bob/bio/base/database/file.py | 10 +++++--- bob/bio/base/extractor/__init__.py | 4 +++ bob/bio/base/preprocessor/__init__.py | 4 +++ doc/conf.py | 20 ++++++++++++++- doc/nitpick-exceptions.txt | 3 +++ 9 files changed, 71 insertions(+), 25 deletions(-) create mode 100644 doc/nitpick-exceptions.txt diff --git a/bob/bio/base/algorithm/BIC.py b/bob/bio/base/algorithm/BIC.py index d1add235..2348e5cd 100644 --- a/bob/bio/base/algorithm/BIC.py +++ b/bob/bio/base/algorithm/BIC.py @@ -8,7 +8,7 @@ import bob.learn.linear import numpy import math -from .Algorithm import Algorithm +from bob.bio.base.algorithm import Algorithm from .. import utils import logging @@ -255,7 +255,8 @@ class BIC(Algorithm): Computes the BIC score between the model and the probe. First, the ``comparison_function`` is used to create the comparison vectors between all model features and the probe feature. - Then, a BIC score is computed for each comparison vector, and the BIC scores are fused using the :py:func:`model_fusion_function` defined in the :py:class:`Algorithm` base class. + Then, a BIC score is computed for each comparison vector, and the BIC scores are fused using + the `model_fusion_function` defined in the :py:class:`bob.bio.base.algorithm.Algorithm` base class. **Parameters:** diff --git a/bob/bio/base/algorithm/__init__.py b/bob/bio/base/algorithm/__init__.py index 015cf9e6..7e8b8411 100644 --- a/bob/bio/base/algorithm/__init__.py +++ b/bob/bio/base/algorithm/__init__.py @@ -5,5 +5,13 @@ from .LDA import LDA from .PLDA import PLDA from .BIC import BIC +# to fix sphinx warnings of not being able to find classes, when path is shortened +Algorithm.__module__ = "bob.bio.base.algorithm" +Distance.__module__ = "bob.bio.base.algorithm" +PCA.__module__ = "bob.bio.base.algorithm" +LDA.__module__ = "bob.bio.base.algorithm" +PLDA.__module__ = "bob.bio.base.algorithm" +BIC.__module__ = "bob.bio.base.algorithm" + # gets sphinx autodoc done right - don't remove it __all__ = [_ for _ in dir() if not _.startswith('_')] diff --git a/bob/bio/base/database/__init__.py b/bob/bio/base/database/__init__.py index bb901085..3c4f8673 100644 --- a/bob/bio/base/database/__init__.py +++ b/bob/bio/base/database/__init__.py @@ -3,5 +3,11 @@ from .file import BioFileSet from .database import BioDatabase from .database import ZTBioDatabase +# to fix sphinx warnings of not being able to find classes, when path is shortened +BioFile.__module__ = "bob.bio.base.database" +BioFileSet.__module__ = "bob.bio.base.database" +BioDatabase.__module__ = "bob.bio.base.database" +ZTBioDatabase.__module__ = "bob.bio.base.database" + # gets sphinx autodoc done right - don't remove it __all__ = [_ for _ in dir() if not _.startswith('_')] diff --git a/bob/bio/base/database/database.py b/bob/bio/base/database/database.py index 8e6f76f8..b445f991 100644 --- a/bob/bio/base/database/database.py +++ b/bob/bio/base/database/database.py @@ -65,7 +65,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)): This flag is used to avoid re-computation of models when running on the different protocols of the same database. kwargs : ``key=value`` pairs - The arguments of the :py:class:`Database` base class constructor. + The arguments of the `Database` base class constructor. """ def __init__( @@ -215,12 +215,12 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)): **Parameters:** - files : [:py:class:`BioFile`] + files : [:py:class:`bob.bio.base.database.BioFile`] The list of files to be uniquified and sorted. **Returns:** - sorted : [:py:class:`BioFile`] + sorted : [:py:class:`bob.bio.base.database.BioFile`] The sorted list of files, with duplicate `BioFile.id`\s being removed. """ # sort files using their sort function @@ -243,12 +243,12 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)): **Parameters:** - files : :py:class:`BioFile` + files : :py:class:`bob.bio.base.database.BioFile` A list of files that should be split up by `BioFile.client_id`. **Returns:** - files_by_client : [[:py:class:`BioFile`]] + files_by_client : [[:py:class:`bob.bio.base.database.BioFile`]] The list of lists of files, where each sub-list groups the files with the same `BioFile.client_id` """ client_files = {} @@ -269,7 +269,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)): **Parameters:** - file : :py:class:`BioFile` + file : :py:class:`bob.bio.base.database.BioFile` The file for which annotations should be returned. **Returns:** @@ -294,7 +294,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)): **Parameters:** - files : [:py:class:`BioFile`] + files : [:py:class:`bob.bio.base.database.BioFile`] The list of file object to retrieve the file names for. directory : str @@ -324,7 +324,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)): **Parameters:** - files : [:py:class:`BioFile`] + files : [:py:class:`bob.bio.base.database.BioFile`] The list of file object to retrieve the original data file names for. **Returns:** @@ -414,7 +414,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)): Keyword parameters: - file : :py:class:`BioFile` or a derivative + file : :py:class:`bob.bio.base.database.BioFile` or a derivative The File objects for which the file name should be retrieved Return value : str @@ -445,7 +445,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)): **Returns:** - files : [:py:class:`BioFile`] + files : [:py:class:`bob.bio.base.database.BioFile`] The sorted and unique list of all files of the database. """ return self.sort(self.objects(protocol=self.protocol, groups=groups, **self.all_files_options)) @@ -468,7 +468,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)): **Returns:** - files : [:py:class:`BioFile`] or [[:py:class:`BioFile`]] + files : [:py:class:`bob.bio.base.database.BioFile`] or [[:py:class:`bob.bio.base.database.BioFile`]] The (arranged) list of files used for the training of the given step. """ if step is None: @@ -503,7 +503,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)): **Returns:** - files : [:py:class:`BioFile`] + files : [:py:class:`bob.bio.base.database.BioFile`] The sorted and unique list of test files of the database. """ return self.sort(self.objects(protocol=self.protocol, groups=groups, **self.all_files_options)) @@ -552,7 +552,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)): **Returns:** - files : [:py:class:`BioFile`] + files : [:py:class:`bob.bio.base.database.BioFile`] The list of files used for to probe the model with the given model id. """ if model_id is not None: @@ -606,7 +606,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)): **Returns:** - files : [:py:class:`BioFileSet`] or something similar + files : [:py:class:`bob.bio.base.database.BioFileSet`] or something similar The list of file sets used to probe the model with the given model id.""" if model_id is not None: file_sets = self.object_sets(protocol=self.protocol, groups=group, model_ids=(model_id,), purposes='probe', @@ -715,7 +715,7 @@ class ZTBioDatabase(BioDatabase): **Returns:** - files : [:py:class:`BioFile`] + files : [:py:class:`bob.bio.base.database.BioFile`] The sorted and unique list of all files of the database. """ files = self.objects(protocol=self.protocol, groups=groups, **self.all_files_options) @@ -777,7 +777,7 @@ class ZTBioDatabase(BioDatabase): **Returns:** - files : [:py:class:`BioFile`] + files : [:py:class:`bob.bio.base.database.BioFile`] The sorted list of files used for to enroll the model with the given model id. """ return self.sort(self.tobjects(protocol=self.protocol, groups=group, model_ids=(t_model_id,))) @@ -795,7 +795,7 @@ class ZTBioDatabase(BioDatabase): **Returns:** - files : [:py:class:`BioFile`] + files : [:py:class:`bob.bio.base.database.BioFile`] The unique list of files used to compute the Z-norm. """ return self.sort(self.zobjects(protocol=self.protocol, groups=group, **self.z_probe_options)) @@ -813,7 +813,7 @@ class ZTBioDatabase(BioDatabase): **Returns:** - files : [:py:class:`BioFileSet`] + files : [:py:class:`bob.bio.base.database.BioFileSet`] The unique list of file sets used to compute the Z-norm. """ raise NotImplementedError("Please implement this function in derived classes") diff --git a/bob/bio/base/database/file.py b/bob/bio/base/database/file.py index d196203e..7fecf51a 100644 --- a/bob/bio/base/database/file.py +++ b/bob/bio/base/database/file.py @@ -18,7 +18,7 @@ class BioFile(bob.db.base.File): The id of the client this file belongs to. Its type depends on your implementation. If you use an SQL database, this should be an SQL type like Integer or String. - For path and file_id, please refer to :py:class:`bob.db.base.file.File` constructor + For path and file_id, please refer to :py:class:`bob.db.base.File` constructor """ bob.db.base.File.__init__(self, path, file_id) @@ -30,19 +30,22 @@ class BioFile(bob.db.base.File): class BioFileSet(BioFile): """This class defines the minimum interface of a set of database files that needs to be exported. Use this class, whenever the database provides several files that belong to the same probe. - Each file set has an id, and a list of associated files, which are of type :py:class:`BioFile` of the same client. + Each file set has an id, and a list of associated files, which are of + type :py:class:`bob.bio.base.database.BioFile` of the same client. The file set id can be anything hashable, but needs to be unique all over the database. **Parameters:** file_set_id : str or int A unique ID that identifies the file set. - files : [:py:class:`BioFile`] + files : [:py:class:`bob.bio.base.database.BioFile`] A non-empty list of BioFile objects that should be stored inside this file. All files of that list need to have the same client ID. """ def __init__(self, file_set_id, files, path=None): + """The list of :py:class:`bob.bio.base.database.BioFile` objects stored in this file set""" + # don't accept empty file lists assert len(files), "Cannot create an empty BioFileSet" @@ -55,7 +58,6 @@ class BioFileSet(BioFile): # The list of files contained in this set self.files = files - """The list of :py:class:`BioFile` objects stored in this file set""" def __lt__(self, other): """Defines an order between file sets by using the order of the file set ids.""" diff --git a/bob/bio/base/extractor/__init__.py b/bob/bio/base/extractor/__init__.py index bb58f93f..deae933a 100644 --- a/bob/bio/base/extractor/__init__.py +++ b/bob/bio/base/extractor/__init__.py @@ -1,5 +1,9 @@ from .Extractor import Extractor from .Linearize import Linearize +# to fix sphinx warnings of not being able to find classes, when path is shortened +Extractor.__module__ = "bob.bio.base.extractor" +Linearize.__module__ = "bob.bio.base.extractor" + # gets sphinx autodoc done right - don't remove it __all__ = [_ for _ in dir() if not _.startswith('_')] diff --git a/bob/bio/base/preprocessor/__init__.py b/bob/bio/base/preprocessor/__init__.py index 37dd71f9..fb7b2eb6 100644 --- a/bob/bio/base/preprocessor/__init__.py +++ b/bob/bio/base/preprocessor/__init__.py @@ -1,5 +1,9 @@ from .Preprocessor import Preprocessor from .Filename import Filename +# to fix sphinx warnings of not being able to find classes, when path is shortened +Preprocessor.__module__ = "bob.bio.base.preprocessor" +Filename.__module__ = "bob.bio.base.preprocessor" + # gets sphinx autodoc done right - don't remove it __all__ = [_ for _ in dir() if not _.startswith('_')] diff --git a/doc/conf.py b/doc/conf.py index ce755618..4bb13316 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -30,9 +30,27 @@ extensions = [ import sphinx if sphinx.__version__ >= "1.4.1": extensions.append('sphinx.ext.imgmath') + imgmath_image_format = 'svg' else: extensions.append('sphinx.ext.pngmath') +# Be picky about warnings +nitpicky = True +# Ignores stuff we can't easily resolve on other project's sphinx manuals +nitpick_ignore = [] +# Allows the user to override warnings from a separate file +if os.path.exists('nitpick-exceptions.txt'): + for line in open('nitpick-exceptions.txt'): + if line.strip() == "" or line.startswith("#"): + continue + dtype, target = line.split(None, 1) + target = target.strip() + try: # python 2.x + target = unicode(target) + except NameError: + pass + nitpick_ignore.append((dtype, target)) + # Always includes todos todo_include_todos = True @@ -217,7 +235,7 @@ autodoc_default_flags = [ # For inter-documentation mapping: from bob.extension.utils import link_documentation, load_requirements -sphinx_requirements = "./extra-intersphinx.txt" +sphinx_requirements = "extra-intersphinx.txt" if os.path.exists(sphinx_requirements): intersphinx_mapping = link_documentation(additional_packages=load_requirements(sphinx_requirements)) else: diff --git a/doc/nitpick-exceptions.txt b/doc/nitpick-exceptions.txt new file mode 100644 index 00000000..f48a0c26 --- /dev/null +++ b/doc/nitpick-exceptions.txt @@ -0,0 +1,3 @@ +py:class bob.bio.video.preprocessor.Video +py:class bob.db.base.database.Database +py:class bob.db.base.file.File \ No newline at end of file -- GitLab