Skip to content

Add sphinx-matlab-apidoc#334

Draft
jasonnicholson wants to merge 2 commits intosphinx-contrib:masterfrom
jasonnicholson:add-sphinx-matlab-apidoc
Draft

Add sphinx-matlab-apidoc#334
jasonnicholson wants to merge 2 commits intosphinx-contrib:masterfrom
jasonnicholson:add-sphinx-matlab-apidoc

Conversation

@jasonnicholson
Copy link
Copy Markdown
Contributor

@jasonnicholson jasonnicholson commented Jan 5, 2026

This will add a function that will automatically create rst files for a MATLAB set of source files. This what I expect the API to look like: sphinx-matlab-apidoc.

Main uses:

  1. Ease the burden of generating rst files for a library.
  2. Apply this tool to many libraries with little effort to try and find parsing bugs.

This PR is here now for awareness. It's not ready.

What's coming after this PR is merged is testing against fairly large open source MATLAB projects, looking for parsing failures.

refactor: upgraded identification of file to use tree-sitter parser
Comment thread pyproject.toml
omit = [
'*/_build/*'
'*/_build/*',
'sphinxcontrib\__init__.py'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed? I may be missing something.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can update your pytest config so that it produces coverage for the things you want. I moved the pytest config to pyproject.toml below. If you want HTML coverage for the current active python version and installed Sphinx, you call pytest --cov-report=html. The HTML coverage will get generated. Ignoring the init.py is what allows you get coverage for the whole folder sphinxcontrib sanely.

[tool.pytest.ini_options]
addopts = "-ra --strict-config --strict-markers --show-capture=all --showlocals -s -vv --cov=sphinxcontrib --cov=tests --cov-report=term"
doctest_optionflags = "NORMALIZE_WHITESPACE ELLIPSIS"
junit_family = "xunit2"
log_cli_level = "INFO"
xfail_strict = true

[tool.coverage.run]
branch = true
omit = [
    '*/_build/*',
    'sphinxcontrib/__init__.py',
]

Similar to sphinx-apidoc but specifically designed for MATLAB projects.
Generates RST files per namespace and limits to 50 code files per page.

:copyright: Copyright 2025 by the sphinxcontrib-matlabdomain team.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:copyright: Copyright 2025 by the sphinxcontrib-matlabdomain team.
:copyright: Copyright by the sphinxcontrib-matlabdomain team.

Copy link
Copy Markdown
Collaborator

@Remi-Gau Remi-Gau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not had a look in detail but we are going to need some mention of this in the doc somewhere to improve discoverability.

return ".".join(parts)


def detect_item_type(file_path: Path) -> str:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three notes on this function:

  • I don't love the code duplication with mat_types.py. This makes maintainability worse when inevitably Mathworks chooses to change/add some syntax we want to support.
  • Why return a string? I know/hope this is probably interned and performance isn't really a question but it feels like we should have an enum for this. This may be part of a different refactor though.
  • tree-sitter is blazing fast but I don't love the extra IO and CPU operations of loading and parsing each file twice if you use this.

@jasonnicholson
Copy link
Copy Markdown
Contributor Author

Hi @remi and @apozharski . This isn't ready for review. If you have feedback on the idea, I will take that. The details on the code will likely age.

@jasonnicholson
Copy link
Copy Markdown
Contributor Author

Not had a look in detail but we are going to need some mention of this in the doc somewhere to improve discoverability.

Did you click the link? I have a whole new site to bring in.

@apozharski
Copy link
Copy Markdown
Collaborator

Hi @remi and @apozharski . This isn't ready for review. If you have feedback on the idea, I will take that. The details on the code will likely age.

I like the idea in general, I was just jotting down some thoughts I had on the details while I was here :)

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

Successfully merging this pull request may close these issues.

3 participants