Quick Reference
Essential commands and workflows for development. Bookmark this page!
Common Commands
Setup
# Clone repository
git clone https://github.com/sphinx-contrib/matlabdomain.git
cd matlabdomain
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # Linux/macOS
.venv\Scripts\activate # Windows
# Install dependencies
pip install -r dev-requirements.txt # For development
pip install -r rtd-requirements.txt # For docs
# Install pre-commit hooks
pre-commit install
Testing
# Run tests
pytest
# Verbose output
pytest -v
# Stop on first failure
pytest -x
# Run specific test file
pytest tests/test_parse_mfile.py
# Run specific test
pytest tests/test_parse_mfile.py::test_function_name
# Run with coverage (terminal summary with missing lines, branch-aware)
pytest --cov=sphinxcontrib --cov-report=term-missing --cov-branch
# Run with coverage (terminal summary, branch-aware)
pytest --cov=sphinxcontrib --cov-report=term --cov-branch
# Coverage (HTML report)
pytest --cov=sphinxcontrib --cov-report=html --cov-branch
# Run slow integration tests
pytest -m slow test_slow/
Code Quality
# Run all pre-commit checks
pre-commit run --all-files
# Lint and format
ruff check .
ruff format .
# Type check (if mypy configured)
mypy sphinxcontrib/
Documentation
# Build HTML docs
cd docs && make html
# Clean build
cd docs && make clean && make html
# View docs (Linux)
xdg-open docs/_build/html/index.html
# View docs (macOS)
open docs/_build/html/index.html
# View docs (Windows)
start docs/_build/html/index.html
# Live preview with sphinx-autobuild
cd docs && make livehtml
Git Workflow
# Create feature branch
git checkout -b feature/my-feature
# Make changes, then
git add .
git commit -m "feat: add new feature"
# Push to GitHub
git push origin feature/my-feature
Key Files Reference
Source Code
File |
Purpose |
|---|---|
|
Main domain implementation, roles, directives |
|
MATLAB type definitions (Class, Function, etc.) |
|
Autodoc documenters for extracting docs |
|
Autodoc directive implementations |
|
AST parser using tree-sitter |
|
Syntax highlighting lexer |
Configuration
File |
Purpose |
|---|---|
|
Project metadata, tool configs (ruff, pytest, etc.) |
|
Package installation configuration |
|
pytest configuration |
|
Testing across multiple Python/Sphinx versions |
|
Pre-commit hook configuration |
|
Sphinx documentation configuration |
Dependencies
File |
Purpose |
|---|---|
|
Development dependencies (pytest, ruff, etc.) |
|
ReadTheDocs build requirements |
|
Package dependencies (install_requires) |
Common Workflows
Adding a New Feature
Create branch:
git checkout -b feature/my-featureWrite code in
sphinxcontrib/Add tests in
tests/test_myfeature.pyRun tests:
pytestUpdate documentation in
docs/Update
CHANGES.rstCommit:
git commit -m "feat: description"Push and create PR
Fixing a Bug
Create branch:
git checkout -b fix/issue-descriptionWrite failing test that reproduces the bug
Fix the bug in
sphinxcontrib/Verify test passes:
pytestUpdate
CHANGES.rstCommit:
git commit -m "fix: description"Push and create PR
Adding Documentation
Create
.rstfile in appropriatedocs/subdirectoryAdd to
toctreein parent pageWrite content in reStructuredText
Build:
cd docs && make htmlReview in browser
Commit and push
Reviewing a PR
Checkout PR branch:
git fetch origin && git checkout pr-branchInstall:
pip install -e .Run tests:
pytestBuild docs:
cd docs && make htmlReview code changes
Test manually if needed
Leave feedback on GitHub
Important Configuration Settings
conf.py (Sphinx)
# Essential MATLAB configuration
extensions = ['sphinxcontrib.matlab', 'sphinx.ext.autodoc']
matlab_src_dir = '/path/to/matlab/src'
primary_domain = 'mat'
# Optional enhancements
matlab_short_links = True
matlab_auto_link = 'basic'
matlab_show_property_default_values = True
pyproject.toml
[tool.ruff]
line-length = 88
target-version = "py38"
[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = "test_*.py"
Troubleshooting Quick Fixes
Tests Failing
# Clean and reinstall
pip uninstall sphinxcontrib-matlabdomain
pip install -e .
pytest
Import Errors
# Verify environment
which python
pip list | grep sphinx
# Reinstall in editable mode
pip install -e .
Pre-commit Failing
# Update hooks
pre-commit autoupdate
# Run manually
pre-commit run --all-files
Documentation Not Building
# Clean build
cd docs
make clean
make html
CI Failing on GitHub
Check
.github/workflows/python-package.ymlRun same commands locally
Ensure all tests pass locally first
Useful Links
Repository: https://github.com/sphinx-contrib/matlabdomain
Issues: https://github.com/sphinx-contrib/matlabdomain/issues
Documentation: https://sphinxcontrib-matlabdomain.readthedocs.io/
Sphinx Docs: https://www.sphinx-doc.org/
Code Snippets
Testing a MATLAB Function
from sphinxcontrib.mat_types import MatFunction
# Parse a MATLAB file
func = MatFunction.from_file("path/to/function.m")
print(func.name)
print(func.args)
print(func.docstring)
Creating a Test
import pytest
from sphinxcontrib.mat_types import MatClass
def test_class_parsing():
cls = MatClass.from_file("MyClass.m")
assert cls.name == "MyClass"
assert len(cls.methods) > 0
Debugging Sphinx Build
# In conf.py, add logging
import logging
logging.basicConfig(level=logging.DEBUG)
Environment Variables
Useful environment variables:
# Set MATLAB source directory
export MATLAB_SRC_DIR=/path/to/matlab
# Python debugging
export PYTHONVERBOSE=1
# Pytest options
export PYTEST_ADDOPTS="-v --tb=short"
See Also
Architecture - Understand the codebase
Contributing - Full contribution guide
Testing - Testing details
Known Issues - Current bugs and limitations