sphinx-contrib / matlabdomain

A Sphinx extension for documenting Matlab code
http://sphinxcontrib-matlabdomain.readthedocs.io/
Other
70 stars 46 forks source link

Interpret `matlab_src_dir` relative to the sphinx source directory. #224

Closed stibus closed 11 months ago

stibus commented 11 months ago

Instead of having an absolute path for matlab_src_dir in conf.py interpret the supplied value as path relative to the sphinx source directory. This enables the use of matlabdomain with, e.g., sphinx-multiversion which relies on running sphinx-build on different versions checked out to temporary folders. Thanks to os.path.join() it is still possible to provide an absolute path, though.

This solves https://github.com/Holzhaus/sphinx-multiversion/issues/108 which I found while looking for a solution.

joeced commented 11 months ago

Thanks for the contribution and sorry for the late reply. Would you have time to add a test, for instance with new test directory in test/roots that uses a relative path.

stibus commented 11 months ago

Hi @joeced,

I'm not sure what the expectation about that test is. Basically one just needs to replace matlab_src_dir = os.path.abspath("..") with matlab_src_dir = ".." in tests/test_docs/conf.py. Maybe you just want to update existing tests.

But I have seen that my code would fail if matlab_src_dir was empty, so I adjusted the code to test this before constructing the path.

joeced commented 11 months ago

I'll accept the PR now and prepare a new release.

joeced commented 11 months ago

Included in the new version 0.21.0. I changed it from being relative to configuration directory, rather than the source directory. In most cases it's the same, but I think it is easier to the user to be relative to conf.py. Once again, thanks for the contribution, very much appreciated.

stibus commented 11 months ago

Hi @joeced. Unfortunately, making the path relative to the config directory again breaks compatibility with sphinx-multiversion. It is one of those cases where config and source directory are different. sphinx-multiversion works with a single configuration but calls sphinx-build using a temporary source directory for each version. For this to work matlab_src_dir must be relative to the source directory. Otherwise, the documentation is built from the most recent version only.

joeced commented 11 months ago

Fixed in version 0.21.2

stibus commented 11 months ago

Thanks for the fix! I can confirm it works as expected in my project. You may want to mention in the documentation that users may still specify an absolute path.

joeced commented 11 months ago

Thanks for testing it. The documentation mentions both the option of absolute and relative paths.