Giter Site home page Giter Site logo

sphinx-contrib / matlabdomain Goto Github PK

View Code? Open in Web Editor NEW
62.0 8.0 43.0 965 KB

A Sphinx extension for documenting Matlab code

License: Other

Python 83.86% MATLAB 10.99% Makefile 2.28% Batchfile 2.85% M 0.03%
sphinxcontrib matlab python sphinx sphinx-extension

matlabdomain's Introduction

Github Actions github-action-badge

sphinxcontrib-matlabdomain -- Sphinx domain for auto-documenting MATLAB

This extension provides a Sphinx domain for automatically generating doumentation from MATLAB source files. It is modelled after the Python autodoc.

The extension allows you to have your documentation and source files together and use the powerful Sphinx documentation tool. All your MATLAB file help text can be automatically included in the your documentation and output as for instance HTML.

The extension works really well with sphinx.ext.napoleon.

Recent Changes.

Usage

The Python package must be installed with:

pip install sphinxcontrib-matlabdomain

In general, the usage is the same as for documenting Python code. The package is tested with Python >= 3.8 and Sphinx >= 4.5.0.

For a Python 2 compatible version the package must be installed with:

pip install sphinxcontrib-matlabdomain==0.11.8

Configuration

In your Sphinx conf.py file add sphinxcontrib.matlab to the list of extensions.

extensions = ['sphinxcontrib.matlab', 'sphinx.ext.autodoc']

For convenience the primary domain can be set to mat with.:

primary_domain = "mat"

Additional Configuration

matlab_src_dir
In order for the Sphinx MATLAB domain to auto-document MATLAB source code, set the config value of matlab_src_dir to an absolute path or a path relative to the source directory. Currently only one MATLAB path can be specified, but that folder and all the subfolders in that tree will be searched.
matlab_short_links

Shorten all class, package and functions to the minimum length. This assumes that everything is in the path as we would expect it in MATLAB. This will resemble a more MATLAB-like presentation. If it is True is forces matlab_keep_package_prefix = False. Further, it allows for much shorter and cleaner references. Example, given a path to classes like target.subfolder.ClassFoo and [email protected]

  • With False:

    :class:`target.subfolder.ClassFoo`
    
    :class:`[email protected]`
    
  • With True:

    :class:`ClassFoo`
    
    :class:`ClassFolder`
    

Default is False. Added in Version 0.19.0.

matlab_auto_link

Automatically convert the names of known entities (e.g. classes, functions, properties, methods) to links. Valid values are "basic" and "all".

  • "basic" - Auto-links (1) known classes, functions, properties, or methods that appear in docstring lines that begin with "See also" and any subsequent lines before the next blank line (unknown names are wrapped in double-backquotes), and (2) property and method names that appear in lists under "<MyClass> Properties:" and "<MyClass> Methods:" headings in class docstrings.
  • "all" - Auto-links everything included with "basic", plus all known classes and functions everywhere else they appear in any docstring, any fully qualified (including class name) property or method names, any names ending with "()" within class, property, or method docstrings that match a method of the corresponding class, and any property or method names in their own docstrings. Note that a non-breaking space before or after a name will prevent auto-linking.

Default is None. Added in Version 0.20.0.

matlab_show_property_default_value
Show property default values in the rendered document. Default is False, which is what MathWorks does in their documentation. Added in Version 0.16.0.
matlab_class_signature
Shows the constructor argument list in the class signature if True. Default is False. Added in Version 0.20.0.
matlab_keep_package_prefix
Determines if the MATLAB package prefix + is displayed in the generated documentation. Default is False. When False, packages are still referred to in ReST using +pakage.+subpkg.func but the output will be pakage.subpkg.func(). Forced to False if matlab_short_links is True. Added in Version 0.11.0.
matlab_src_encoding
The encoding of the MATLAB files. By default, the files will be read as utf-8 and parsing errors will be replaced using ? chars. Added in Version 0.9.0.

If you want the closest to MATLAB documentation style, use matlab_short_links = True and matlab_auto_link = "basic" or matlab_auto_link = "all" in your conf.py file.

Roles and Directives

Please see Sphinx Domains and sphinx.ext.autodoc for documentation on the use of roles and directives. MATLAB code can be documented using the following roles and directives:

Directive MATLAB object
.. module:: foldername folders, packages and namespaces
.. currentmodule:: foldername
  • set folder but do not link
.. automodule:: foldername
  • auto-document
:mod:`foldername`
  • reference
.. function:: funcname function definition and signature
.. autofunction:: funcname()
  • auto-document
:func:`funcname`
  • reference
.. script:: scriptname script definition
.. autoscript:: scriptname
  • auto-document
:scpt:`scriptname`
  • reference
.. class:: classname() class definition and optional signature
.. autoclass:: classname
  • auto-document
:class:`classname`
  • reference
.. method:: methname() method definition and signature
.. automethod:: methname
  • auto-document
:meth:`methname`
  • reference
.. staticmethod:: statmethname() static method definition and signature
.. automethod:: statmethname
  • auto-document
:meth:`methname`
  • reference
.. attribute:: attrname property definition
.. autoattribute:: attrname
  • auto-document
:attr:`attrname`
  • reference
.. application:: appname application definition
.. autoapplication:: appname
  • auto-document
:app:`appname`
  • reference

Several options are available for auto-directives.

  • :members: auto-document public members
  • :show-inheritance: list bases
  • :undoc-members: document members without docstrings
  • :annotation: specifies attribute annotation instead of default

There are also several config values that can be set in conf.py that will affect auto-docementation.

  • autoclass_content can be set to class, both or init, which determines which docstring is used for classes. The constructor docstring is used when this is set to init.
  • autodoc_member_order can be set to alphabetical, groupwise or bysource.
  • autodoc_default_flags can be set to a list of options to apply. Use the no-flag directive option to disable this config value once.

Note

The module roles and directives create a psuedo namespace for MATLAB objects, similar to a package. They represent the path to the folder containing the MATLAB object. If no module is specified then Sphinx will assume that the object is a built-in.

Example: given the following MATLAB source in folder test_data:

classdef MyHandleClass < handle & my.super.Class
    % a handle class
    %
    % :param x: a variable

    %% some comments
    properties
        x % a property

        % Multiple lines before a
        % property can also be used
        y
    end
    methods
        function h = MyHandleClass(x)
            h.x = x
        end
        function x = get.x(obj)
        % how is this displayed?
            x = obj.x
        end
    end
    methods (Static)
        function w = my_static_function(z)
        % A static function in :class:`MyHandleClass`.
        %
        % :param z: input z
        % :returns: w

            w = z
        end
    end
end

Use the following to document:

Test Data
=========
This is the test data module.

.. automodule:: test_data

:mod:`test_data` is a really cool module.

My Handle Class
---------------
This is the handle class definition.

.. autoclass:: MyHandleClass
    :show-inheritance:
    :members:

In version 0.19.0 the .. automodule:: directive can also take a . as argument, which allows you to document classes or functions in the root of matlab_src_dir.

Module Index

Since version 0.10.0 the MATLAB Module Index should be linked to with:

`MATLAB Module Index <mat-modindex.html>`_

Older versions, used the Python Module Index, which was linked to with:

:ref:`modindex`

Documenting Python and MATLAB sources together

Since version 0.10.0 MATLAB and Python sources can be (auto-)documented in the same Sphinx documentation. For this to work, do not set the primary domain.

Instead use the mat: prefix before the desired directives:

.. automodule:: func
.. autofunction:: func.main

.. mat:automodule:: matsrc
.. mat:autofunction:: matsrc.func

Online Demo

Warning

The online demo is highly outdated!

The test docs in the repository are online here: http://bwanamarko.alwaysdata.net/matlabdomain/

Note

Sphinx style markup are used to document parameters, types, returns and exceptions. There must be a blank comment line before and after the parameter descriptions.

Users

Citation

matlabdomain's People

Contributors

boeddeker avatar cleobis avatar cvergari avatar denisrosset avatar dstansby avatar dullin avatar effigies avatar florianjacob avatar ganimed avatar h0r5e avatar ilent2 avatar jcewidex avatar joeced avatar luhuhis avatar mhbl3 avatar mikofski avatar nno avatar pekarygergelyr avatar ptitrex avatar rdzman avatar stibus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

matlabdomain's Issues

Exception Comments must be indeneted after make html

Originally reported by: IshmaelBelghazi (Bitbucket: IshmaelBelghazi, GitHub: IshmaelBelghazi)


Full Traceback:

#!python

# Sphinx version: 1.3.1
# Python version: 2.7.9 (CPython)
# Docutils version: 0.12 release
# Jinja2 version: 2.7.3
# Last messages:
#   Running Sphinx v1.3.1
#   loading pickled environment...
#   done
#   building [mo]: targets for 0 po files that are out of date
#   building [html]: targets for 0 source files that are out of date
#   updating environment:
#   [config changed] 2 added, 0 changed, 0 removed
#   reading sources... [ 50%] api
# Loaded extensions:
#   sphinx.ext.autodoc (1.3.1) from /home/ishmael/.local/lib/python2.7/site-packages/sphinx/ext/autodoc.pyc
#   sphinx.ext.intersphinx (1.3.1) from /home/ishmael/.local/lib/python2.7/site-packages/sphinx/ext/intersphinx.pyc
#   sphinxcontrib.matlab (unknown version) from /home/ishmael/.local/lib/python2.7/site-packages/sphinxcontrib/matlab.pyc
#   sphinx.ext.doctest (1.3.1) from /home/ishmael/.local/lib/python2.7/site-packages/sphinx/ext/doctest.pyc
#   sphinx.ext.mathjax (1.3.1) from /home/ishmael/.local/lib/python2.7/site-packages/sphinx/ext/mathjax.pyc
#   sphinx.ext.viewcode (1.3.1) from /home/ishmael/.local/lib/python2.7/site-packages/sphinx/ext/viewcode.pyc
#   sphinx.ext.coverage (1.3.1) from /home/ishmael/.local/lib/python2.7/site-packages/sphinx/ext/coverage.pyc
#   alabaster (0.7.6) from /home/ishmael/.local/lib/python2.7/site-packages/alabaster/__init__.pyc
#   sphinx.ext.todo (1.3.1) from /home/ishmael/.local/lib/python2.7/site-packages/sphinx/ext/todo.pyc
#   sphinx.ext.ifconfig (1.3.1) from /home/ishmael/.local/lib/python2.7/site-packages/sphinx/ext/ifconfig.pyc
Traceback (most recent call last):
  File "/home/ishmael/.local/lib/python2.7/site-packages/sphinx/cmdline.py", line 245, in main
    app.build(opts.force_all, filenames)
  File "/home/ishmael/.local/lib/python2.7/site-packages/sphinx/application.py", line 264, in build
    self.builder.build_update()
  File "/home/ishmael/.local/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 245, in build_update
    'out of date' % len(to_build))
  File "/home/ishmael/.local/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 259, in build
    self.doctreedir, self.app))
  File "/home/ishmael/.local/lib/python2.7/site-packages/sphinx/environment.py", line 618, in update
    self._read_serial(docnames, app)
  File "/home/ishmael/.local/lib/python2.7/site-packages/sphinx/environment.py", line 638, in _read_serial
    self.read_doc(docname, app)
  File "/home/ishmael/.local/lib/python2.7/site-packages/sphinx/environment.py", line 791, in read_doc
    pub.publish()
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/core.py", line 217, in publish
    self.settings)
  File "/home/ishmael/.local/lib/python2.7/site-packages/sphinx/environment.py", line 126, in read
    self.parse()
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/readers/__init__.py", line 78, in parse
    self.parser.parse(self.input, document)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/parsers/rst/__init__.py", line 172, in parse
    self.statemachine.run(inputlines, document, inliner=self.inliner)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 170, in run
    input_source=document['source'])
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/statemachine.py", line 239, in run
    context, state, transitions)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/statemachine.py", line 460, in check_line
    return method(match, context, next_state)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2726, in underline
    self.section(title, source, style, lineno - 1, messages)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 327, in section
    self.new_subsection(title, lineno, messages)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 395, in new_subsection
    node=section_node, match_titles=True)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 282, in nested_parse
    node=node, match_titles=match_titles)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/statemachine.py", line 239, in run
    context, state, transitions)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/statemachine.py", line 460, in check_line
    return method(match, context, next_state)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2726, in underline
    self.section(title, source, style, lineno - 1, messages)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 327, in section
    self.new_subsection(title, lineno, messages)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 395, in new_subsection
    node=section_node, match_titles=True)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 282, in nested_parse
    node=node, match_titles=match_titles)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/statemachine.py", line 239, in run
    context, state, transitions)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/statemachine.py", line 460, in check_line
    return method(match, context, next_state)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2299, in explicit_markup
    nodelist, blank_finish = self.explicit_construct(match)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2311, in explicit_construct
    return method(self, expmatch)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2054, in directive
    directive_class, match, type_name, option_presets)
  File "/home/ishmael/.local/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2103, in run_directive
    result = directive_instance.run()
  File "/home/ishmael/.local/lib/python2.7/site-packages/sphinx/ext/autodoc.py", line 1467, in run
    documenter.generate(more_content=self.content)
  File "/home/ishmael/.local/lib/python2.7/site-packages/sphinxcontrib/mat_documenters.py", line 419, in generate
    self.analyzer.find_attr_docs()
  File "/home/ishmael/.local/lib/python2.7/site-packages/sphinxcontrib/mat_types.py", line 1091, in find_attr_docs
    for k, v in mod.safe_getmembers():
  File "/home/ishmael/.local/lib/python2.7/site-packages/sphinxcontrib/mat_types.py", line 229, in safe_getmembers
    value = self.getter(key, None)
  File "/home/ishmael/.local/lib/python2.7/site-packages/sphinxcontrib/mat_types.py", line 283, in getter
    attr = MatObject.matlabify('.'.join([self.package, name]))
  File "/home/ishmael/.local/lib/python2.7/site-packages/sphinxcontrib/mat_types.py", line 133, in matlabify
    return MatObject.parse_mfile(mfile, name, path)  # parse mfile
  File "/home/ishmael/.local/lib/python2.7/site-packages/sphinxcontrib/mat_types.py", line 184, in parse_mfile
    return MatClass(name, modname, tks)
  File "/home/ishmael/.local/lib/python2.7/site-packages/sphinxcontrib/mat_types.py", line 659, in __init__
    raise Exception('Comments must be indented.')
Exception: Comments must be indented.


Sphinx 1.3 does not provide (unused) sphinx.util.{pycompat,autodoc} modules

Originally reported by: nick oosterhof (Bitbucket: nnoo, GitHub: Unknown)


Using Sphinx 1.3b2 with the sphinxcontrib-matlabdomain module, sphinx-build raises an exception because it is unable to execute

from sphinx.util.pycompat import base_exception, class_types

in the file matlabdomain/sphinxcontrib/mat_documenters.py

Since "base_exception" and "class_types" are not used anywhere in this module, the line can be removed.

(Thanks to @bwanamarko for help in confirming this issue and confirming that the import statement can be removed safely)


CRLF in function signature causes: "Test data can not be parsed: TypeError: Expected a whitespace after function keyword."

Originally reported by: Lukas Drude (Bitbucket: lukas_drude, GitHub: Unknown)


I am working with Kubuntu 14.04 and hg revision: 1557:04a335dec66c

I installed everything as follows:

#!bash
sudo pip2 install sphinx
hg clone https://bitbucket.org/bwanamarko/sphinxcontrib-matlabdomain .
cd matlabdomain/
sudo python setup.py install
cd tests

When I run

#!bash

python2 test_mat_types.py

, I get:

#!python
test_ellipsis_after_equals
__main__

    test function with ellipsis after equals
    
        <test-mode>
[MATLAB-domain] matlabify test_data from
        /home/lukas/hgSphinx/matlabdomain/tests/test_data.
        <test-mode>
[MATLAB-domain] matlabify test_data.test_submodule from
        /home/lukas/hgSphinx/matlabdomain/tests/test_data/test_submodule.
        <test-mode>
[MATLAB-domain] attr test_submodule imported from mod <MatModule: "test_data">.
        <test-mode>
[MATLAB-domain] WARNING Attribute "f_no_args" was not found in <MatModule: "test_submodule">.
Traceback (most recent call last):
  File "test_mat_types.py", line 121, in <module>
    f2 = test_no_args()
  File "test_mat_types.py", line 35, in test_no_args
    ok_(isinstance(f, doc.MatFunction))
  File "/usr/lib/python2.7/dist-packages/nose/tools/trivial.py", line 22, in ok_
    raise AssertionError(msg)
AssertionError: None

When I do:

#!bash

cd test_docs/
make html

, I get:

#!python
phinx-build -b html -d _build/doctrees   . _build/html
Running Sphinx v1.2.3
loading pickled environment... not yet created
building [html]: targets for 1 source files that are out of date
updating environment: 1 added, 0 changed, 0 removed
reading sources... [100%] index                                                                                                        
Exception occurred:
  File "/usr/local/lib/python2.7/dist-packages/sphinxcontrib_matlabdomain-0.2.5dev_20141010-py2.7.egg/sphinxcontrib/mat_types.py", line 421, in __init__
    raise TypeError('Expected a whitespace after function keyword.')
TypeError: Expected a whitespace after function keyword.
The full traceback has been saved in /tmp/sphinx-err-ssiAS4.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://bitbucket.org/birkenfeld/sphinx/issues/>. Thanks!
make: *** [html] Fehler 1

This bug may be related to Issue #26.


Python-like string detection collides with Matlab transpose

Originally reported by: Lukas Drude (Bitbucket: lukas_drude, GitHub: Unknown)


Matlab uses

#!matlab

.'

to indicate a transposition of a vector.

Sphinx seems to handle this as the beginning of a string when written within a class definition:

#!matlab

classdef MinimalExample
    methods
        function checkSizeOfOutput(this)
            % Working
            a = [1 2].';%'
            b = (a');
            
            % Broken
            a = [1 2].';
            b = (a');
            
            % Working
            a = [1 2].';
            b = (a';
        end
    end
end

The first example is working because the apostrophe in the comment seems to close the accidentally detected beginning of a string.

The second one does not work, because the first parenthesis is within the accidentally detected string. Thus, the closing parenthesis results in an error.

The third example is not valid Matlab code but does not cause a Sphinx-error, because the opening parenthesis is again of the accidentally detected string.

When the code is not within a class, all three cases work fine.


Some definition of attributes for the "properties" or "methods" blocks causes Sphinx to crash

Originally reported by: Anonymous


For instance, using quotes to select the access qualifier, or using a cell-array of metaclasses.

When trying to document the following class:

#!matlab

classdef ClassWithMethodAttributes
    methods (Access = 'private')
        function test3(this)
            disp('test3');
        end
    end
end

The following exception is raised:

Exception occurred:
  File "C:\Appli\Python\2.7\lib\site-packages\sphinxcontrib\mat_types.py", line 806, in attributes
    raise Exception(errmsg)
Exception: Unexpected attribute: "'".

The complete error log is in the attachments.


Cannot import safe_repr

Originally reported by: Anonymous


I am using sphinx to generate code for a matlab document, however I cannot build anything due to an error on the beginning of build;

Could not import extension sphinxcontrib.matlab (exception: cannot import name safe_repr)
make: *** [html] Error 1

I am unsure why this error is appearing as the call seems valid in the extension.


regex that replaces ellipsis fails if empty args or empty retv

Originally reported by: Mark Mikofski (Bitbucket: bwanamarko, GitHub: Unknown)


Currently regex looks like ths

pattern = """(?P<p1>function[ \t]+)  # "function" + 1 or more space/tabs
             (?P<p2>\[?\w+[ \t]*
                 (?:,[ \t]*
                     (?:...\n[ \t]*)?
                 \w+)*\]?)  # return values
             (?P<p3>[ \t]*=?[ \t]*)  # equal sign
             (?P<p4>\w+)  # name of function
             (?P<p5>\(\w+
                 (?:,[ \t]*
                     (?:...\n[ \t]*)?
                 \w+)*\))"""  # args

This always expects at least one character in the args parentheses and ditto for retv.

Change the first retv and arg greedy symbol from + to *, 0 or more, ditto for comma.

This also solves problem of ellipsis before any args!


End of docstring

Originally reported by: Sandor Toth (Bitbucket: tothsa, GitHub: Unknown)


In Matlab the docstring ends at the first line without % symbol. For example:

#!Matlab

function testfun(a,b)
% this is the docstring
% this is still docstring

% this is code comment
return a+b

However using sphinxcontrib-matlabdomain with autodoc, the last comment is also added to the docstring.


Problem with non ascii characters

Originally reported by: Carlos Zelayeta (Bitbucket: Calu85, GitHub: Calu85)


I am trying to use Spanish characters in the documentation of my code, but they are not rendered correctly in the html generated by sphinx using matlabdomain.

For example, if I write the folowing:

#!octave

     function particulas=avanzar(particulas,npart,dt)
     % Cambia ubicación de partículas.

I get, in the html:
Cambia ubicación de partículas

My source code files are codified in utf, and I have already set source_encoding = 'utf-8' in the conf.py.

Could you check that unicode is used everywhere in matlabdomain?

Many thanks.


The definition of an abstract method causes Sphinx to crash

Originally reported by: Anonymous


When trying to document the following class:

#!matlab

classdef(Abstract) AbstractClass
    methods(Abstract)
        value = test1(this);
    end
end

Sphinx raises the following exception:

Exception occurred:
  File "C:\Appli\Python\2.7\lib\site-packages\sphinxcontrib\mat_types.py", line 417, in __init__
    raise TypeError('Object is not a function. Expected a function.')
TypeError: Object is not a function. Expected a function.

The complete error log is in the attachments.


An end of line comment directly at the end of a function declaration causes Sphinx to crash

Originally reported by: Anonymous


When trying to document the following class:

#!matlab

classdef ClassWithEndOfLineComment
    methods
        % No spaces between the end of line and the comment causes Sphinx to crash
        function test(this)% This crash
        end
        
        function test2(this) % This doesn't
        end
    end
end

Sphinx raises the following exception:

Exception occurred:
  File "C:\Appli\Python\2.7\lib\site-packages\sphinxcontrib\mat_types.py", line 470, in __init__
    raise TypeError('Expected a whitespace after input args.')
TypeError: Expected a whitespace after input args.

The complete error log is in the attachments.


mat_types error when using the word "function" in code body

Originally reported by: David Kelley (Bitbucket: dakelley, GitHub: dakelley)


If you try to use the word "function" in the body of a function you get an indexing error in mat_types at line 350. This turns out to be necessary in a project that I'm working on because the functions function returns a structure with a field named "function".

I'd recommend adding the following as a test in MyClass.m that does something like this:

d = @(x) x + 2;
e = functions(d);
f = e.function;

As a workaround, I've started using

e.(['f' 'unction'])

whenever I need to get that field.


Can't import module

Originally reported by: Luke Chang (Bitbucket: ljchang, GitHub: ljchang)


I'm having the exact same issue as reported in this stackoverflow post:

http://stackoverflow.com/questions/26520845/fails-to-import-module-when-using-matlabdomain

The suggestion by Mark Mikofski to add a path in the conf.py file to the matlab root directory unfortunately, didn't resolve the issue for me.

matlab_src_dir = os.path.abspath('..')

Just wanted to check to see if anyone else is having this problem and if there are any other suggestions.

Using:
Python==2.7.9
Sphinx==1.3b2
sphinxcontrib-matlabdomain==0.2.6

I appreciate the help!


Matlab function without input

Originally reported by: Sandor Toth (Bitbucket: tothsa, GitHub: Unknown)


In Matlab function without input can have a simple header such as

#!Matlab

function pi = pival
% calculates the value of pi

pi = 3.1415;

In Matlab no brackets after the name of the function are necessary, however the missing brackets crashing sphinx. I know there is an easy fix, just adding the empty brackets after the name of the function. But it took me a long time to debug my Matlab documentation.


Omitting the parentheses when declaring a method without arguments causes Sphinx to crash

Originally reported by: Anonymous


When trying to document the class:

#!matlab

classdef ClassWithoutParentheses
    methods(Static)
        function test1
            disp('test1');
        end
    end
end

The following exception is raised:

Exception occurred:
  File "C:\Appli\Python\2.7\lib\site-packages\sphinxcontrib\mat_types.py", line 421, in __init__
    raise TypeError('Expected a whitespace after function keyword.')
TypeError: Expected a whitespace after function keyword.

The complete error log can be found in the attachments.


Python 3.4 compatibility

Originally reported by: erxnmedia (Bitbucket: erxnmedia, GitHub: erxnmedia)


With, WinPython-64bit-3.4.3.1, Sphinx 1.6, Sphinx-Matlabdomain 0.28, I get this:

Extension error:
Could not import extension sphinxcontrib.matlab (exception: No module named 'mat_documenters')

I think the code may need to be passed through 2to3.exe to make it Python 3 compatible, I will try that and see what happens.


Automodule of a Matlab package

Originally reported by: Anonymous


Sphinx displays a warning when trying to automodule a Matlab package.

If I add the line

.. automodule:: +myPackage

Sphinx displays:

WARNING: invalid signature for automodule (u'+myPackage')
WARNING: don't know which module to import for autodocumenting u'+myPackage' (try placing a "module" or "currentmodule" directive in the document, or giving an explicit module name)

error occurred while including matlab unit-tests

Originally reported by: Janek Ebbers (Bitbucket: ebbers, GitHub: ebbers)


I created an documentation directory example with the subdirectory functions including two matlab-functions fibonacci.m and hanoi.m.
I ran "sphinx-quickstart" from directory example and used the following settings:

  • Project name: Example
  • Author name(s): JE
  • Project version: 0.0.1
  • autodoc: automatically insert docstrings from modules (y/n) [n]: y
  • other settings: default

I added the lines 14-18

#!python

Own stuff
=========

.. automodule:: functions
    :members:

in the file index.rst and the lines 22,23,35,36

#!python

sys.path.insert(0, os.path.abspath(os.path.join('.', '.')))
matlab_src_dir = os.path.abspath('.')
#!python

extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.viewcode',
    'sphinxcontrib.matlab',
]

in the file conf.py.

When I do

#!python

make html

the examples are correctly translated.

When I add the matlab-unit-test TestFibonacci.m in the subdirectory functions

#!matlab

classdef TestFibonacci < matlab.unittest.TestCase
    
    methods(Test)
        
        function compareFirstThreeElementsToExpected(tc)
            %%  
            f = fibonacci(3, 0);
            expected = [1; 1; 2];
            
            verifyEqual(tc, f, expected)
        end
        
    end
end

and do

#!python

make html

again, I get

#!python

sphinx-build -b html -d _build/doctrees   . _build/html
Running Sphinx v1.2.3
loading pickled environment... not yet created
building [html]: targets for 1 source files that are out of date
updating environment: 1 added, 0 changed, 0 removed
reading sources... [100%] index                                                                                                                             
Exception occurred:
  File "/usr/local/lib/python2.7/dist-packages/sphinxcontrib/mat_types.py", line 806, in attributes
    raise Exception(errmsg)
Exception: Unexpected attribute: "Test".
The full traceback has been saved in /tmp/sphinx-err-kRPi_j.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://bitbucket.org/birkenfeld/sphinx/issues/>. Thanks!
make: *** [html] Fehler 1

This error occurs when using a method keyword such as "Test".

More possible keywords can be found here: http://stackoverflow.com/questions/26710767/which-methods-keywords-i-e-testmethodsetup-can-occur-in-matlab


warn on bad matlab style

Originally reported by: Mark Mikofski (Bitbucket: bwanamarko, GitHub: Unknown)


  1. used builtin as name, EG: (Token.Name.Builtin, 'gamma')
  2. bad indentation
  3. arrays spread over multiple lines without continuation dots
  4. semicolons in properties
  5. tabs instead of spaces
  6. filename function/classdef mismatch
  7. spaces before signature
  8. classdef docstring not indented
  9. empty properties or methods block
  10. function with no args

add Lukas Drude to AUTHORS

make new MATLAB specific member options to filter autodoc of members

Originally reported by: Mark Mikofski (Bitbucket: bwanamarko, GitHub: Unknown)


add dependent members boolean option:

.. autoclass:: MyMATLABClass
    :dependent-members:

recycle private-members option

.. autoclass:: MyMATLABClass
    :private-members:

add new member-access option which takes private, protected, or list of meta classes

.. autoclass:: MyMATLABClass
    :member-access: private

.. autoclass:: MyMATLABClass
    :member-access: protected

.. autoclass:: MyMATLABClass
    :member-access: my_mod.MyClass, foo.Bar

speed up reading MATLAB source

Originally reported by: Mark Mikofski (Bitbucket: bwanamarko, GitHub: Unknown)


Currently only modules are cached in sys.modules, but classdefs are not.

The way Documenter imports objects is by importing the module, then walks its namespace calling the getter method for each path. EG: for pkg.mod.cls.attr it would import pkg then use pkg.getter('mod') to get mod, etc. If a class is encountered it is lexed using Pygments.

This means that a class might be lexed multiple times which is time consuming.

  1. profile a build to see where bottlenecks are
  2. in matlabify, check if modname is in sys.modules before calling MatModule
  3. after a class or function is firts parsed, attach it to it's MatModule using setattr() which is already in sys.modules so that it can be called using getattr()
  4. in MatModules getter method, check if the class or function is an attr using hasattr(), then don't reparse but just return the already parsed object.

incompatibility with numref ?

Originally reported by: Françoise Pinsard (Bitbucket: pinsardfr, GitHub: pinsardfr)


Hi

Using Sphinx 1.3.1, when I add 'sphinxcontrib.matlab' to extension in a conf.py
where numfig = True, I have the message

ERROR: Unknown interpreted text role "numref".

I installed sphinxcontrib-matlabdomain (0.2.7) using pip.

numref has been added in 1.3 see http://sphinx-doc.org/markup/inline.html?highlight=numref

My primary_domain is now the default one (:py:) and my next version will be "None"
because I will mix python and matlab documentation

Regards


Problem when documenting multiple Matlab classes

Originally reported by: Sandor Toth (Bitbucket: tothsa, GitHub: Unknown)


I tried to document a larger Matlab project using Sphinx and the sphinxcontrib-matlabdomain package. It works fine for a single folder that stores all .m files. However my project contains multiple classes stored in separate folders such as:

   project
    |-- matfiles
    |    |-- @class1
    |    |    |-- class1.m
    |    |    |-- method1.m
    |    |    |-- method2.m
    |    |    +-- method1.m
    |    |-- @class2
    |    |    |-- class2.m
    |    |    |-- methodA.m
    |    |    |-- methodB.m
    |    |    +-- methodC.m
    |    +-- function
    |         |-- fun1.m
    |         |-- fun2.m
    |         +-- fun3.m
    +-- doc
         |-- conf.py
         +-- index.rst

I adde the following lines to conf.py:

matlab_src_dir = os.path.abspath('..')
extensions = [
    'sphinx.ext.autodoc',
    'sphinxcontrib.matlab',
]
primary_domain = 'mat'

And I added the following lines to index.rst:

.. module:: matfiles

.. automethod:: class1.method1

I got the following error:

Exception occurred:
  File "/Library/Python/2.7/site-packages/sphinxcontrib/mat_documenters.py", line 788, in import_object
    if self.object.attrs.get('Static'):
AttributeError: 'NoneType' object has no attribute 'attrs'
The full traceback has been saved in /var/folders/70/g0lr37wn60gbbymnsks_t5vm0000gn/T/sphinx-err-uD8qpe.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
| reading sources... [100%] index

So my question is, is there a way to document multi class Matlab projects where class methods are saved in a folder with name @Class?


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.