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

class folder with matlab_short_links causes fatal error #247

Open
rdzman opened this issue Mar 22, 2024 · 2 comments
Open

class folder with matlab_short_links causes fatal error #247

rdzman opened this issue Mar 22, 2024 · 2 comments

Comments

@rdzman
Copy link
Contributor

rdzman commented Mar 22, 2024

I believe this is a bug.

With matlab_short_links = True I would expect to be able to change this (from this test file) ...

classfolder
-----------

.. autoclass:: target.@ClassFolder.ClassFolder
    :show-inheritance:
    :members:

... to this ...

classfolder
-----------

.. currentmodule:: target

.. autoclass:: @ClassFolder.ClassFolder
    :show-inheritance:
    :members:

... but it results in the following fatal error.

./tests/test_autodoc_short_links.py::test_target Failed: [undefined]sphinxcontrib.mat_types.MatcodeError: error importing '@ClassFolder'
make_app = <function make_app.<locals>.make at 0x1045428e0>
rootdir = PosixPath('/Users/ray/dev/github/matlabdomain/tests')

    @pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python3.6 or higher")
    def test_target(make_app, rootdir):
        srcdir = rootdir / "roots" / "test_autodoc"
        confdict = {"matlab_short_links": True}
        app = make_app(srcdir=srcdir, confoverrides=confdict)
>       app.builder.build_all()

tests/test_autodoc_short_links.py:31: 
cls = <class 'sphinxcontrib.mat_types.MatModuleAnalyzer'>
modname = '@ClassFolder'

    @classmethod
    def for_module(cls, modname):
        if ("module", modname) in cls.cache:
            entry = cls.cache["module", modname]
            if isinstance(entry, MatcodeError):
                raise entry
            return entry
        mod = try_get_module_entity_or_default(modname)
        if isinstance(mod, MatModule):
            obj = cls.for_folder(mod.path, modname)
        elif isinstance(mod, MatClass):
            obj = cls.for_folder(mod.module, modname)
        else:
            err = MatcodeError("error importing %r" % modname)
            cls.cache["module", modname] = err
>           raise err
E           sphinxcontrib.mat_types.MatcodeError: error importing '@ClassFolder'

sphinxcontrib/mat_types.py:1785: MatcodeError
@rdzman
Copy link
Contributor Author

rdzman commented Mar 28, 2024

My workaround at the moment is to continue to prefix the autoclass name with the name of the module, even though I am including a currentmoduledirective. In general, this works just fine.

But it results in another issue in the case where the module name has dashes in it, e.g. my-target instead of just target, which happens to be the case for one of my modules.

In this case, if I use something like ..

classfolder
-----------

.. currentmodule:: my-target

.. autoclass:: my-target.@ClassFolder.ClassFolder
    :show-inheritance:
    :members:

... it results in the following warnings and does not process the documentation for the class. (FWIW, the presence or absence of the currentmodule directive here doesn't seem to have any effect.)

WARNING: [sphinxcontrib-matlabdomain] Invalid signature for mat:autoclass ('my-target.@ClassFolder.ClassFolder')
WARNING: [sphinxcontrib-matlabdomain] don't know which module to import for autodocumenting 'my-target.@ClassFolder.ClassFolder' (try placing a "module" or "currentmodule" directive in the document, or giving an explicit module name)

In general, module names with dashes do not appear to cause problems, except if you try to use them explicitly in an autoclass or autofunc directive.

My workaround for this was to rename my module and replace the dash with an underscore, e.g. my_target.

I just wanted to document this here in the hopes that, when this issue gets fixed, it be done in way that allows module names with dashes to work just fine.

@joeced
Copy link
Collaborator

joeced commented Apr 7, 2024

Hi. Just confirming, this is bug. I tried some initial debugging, without any good results.

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

2 participants