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

Relative Path should use doc2path to be compatible with readthedocs style #61

Open
maurerle opened this issue Aug 7, 2024 · 0 comments

Comments

@maurerle
Copy link

maurerle commented Aug 7, 2024

Summary

Builds have to be run from one specific directory, making it impossible to support both python -m sphinx -T -b html -d _build/doctrees -D language=en . $output from docs/source as well as make html from docs folder

Details

Currently, I am building my docs with something like this:

make -C docs html

This works with a directory structure like:

├── mypackage
│   ├── main.py
│   ├── cli.py
├── docs
│   ├── Makefile
│   ├── source
│   │   ├── conf.py
│   │   ├── index.rst
│   │   ├── cli.rst

and the cli.rst contains:

.. argparse::
   :filename: ../mypackage/cli.py
   :func: create_parser
   :prog: mypackage

This works fine, as the ../mypackage/cli.py path is relative to the docs dir which is used as a build dir by make.

The Problem

However, when running a readthedocs build, this does not work fine, as the build is created there using:
cd docs/source
python -m sphinx -T -b html -d _build/doctrees -D language=en . $OUTPUTDIR
which starts the build from the source folder directly.

So we need to change :filename: ../mypackage/cli.py to :filename: ../../mypackage/cli.py to fix this.

Solution

I checked how nbsphinx-link is doing this - as this project does work in both ways:
https://github.com/vidartf/nbsphinx-link/blob/f1682a8b5bfd884bfed7ef7dfaf0810c6ae8a543/nbsphinx_link/__init__.py
I found that there is a doc2path api in sphinx which might correctly translate the pathes to be relative to the calling file in both ways:
https://www.sphinx-doc.org/en/master/extdev/envapi.html

This would probably have the drawback, that sphinx-argparse should move to a "argparse is relative to the .rst file - not to the build dir of the docs" approach which would break existing configs..?

maurerle added a commit to assume-framework/assume that referenced this issue Aug 7, 2024
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

1 participant