sphinx-doc / sphinx-autobuild

Watch a Sphinx directory and rebuild the documentation when a change is detected. Also includes a hot-reload web server.
MIT License
552 stars 83 forks source link

sphinx-autobuild `cwd` doesn't match shpinx-build #170

Closed dimaqq closed 2 months ago

dimaqq commented 3 months ago

My directory structure:

some_git_repo/
some_git_repo/pyproject.toml
some_git_repo/docs/
some_git_repo/docs/conf.py
some_git_repo/docs/index.rst
some_git_repo/docs/local_sphinx_hacks.py

When I run sphinx-build -W --keep-going docs/ docs/_build/html (from some_git_repo) the current working directory is set to some_git_repo/docs.

When I run sphinx-autobuild docs/ docs/_build/html --watch docs --port 8000 (from some_git_repo), the current directory is set to something else.

This matters in my case, because docs/conf.py makes assumptions about working dir, in my case it includes code like:

import sys
sys.path.append('./')
import local_sphinx_hacks

I wish that there was parity in the execution environment between sphinx-autobuild and sphinx-build, that is for the command from this project to be a drop-in replacement.

Yes I know I can fix my conf.py, I'm only pointing out that there's friction here.

dimaqq commented 2 months ago

For now, I'm working around it this way.

If the vanilla command is

sphinx-build -W --keep-going docs/ docs/_build/html

then it can be rewritten as

cd docs; sphinx-build -W --keep-going ./ ./_build/html

and then live docs can be ran with

cd docs; sphinx-autobuild ./ ./_build/html --watch . --port 8000

AA-Turner commented 2 months ago

Does https://pypi.org/project/sphinx-autobuild/2024.9.3/ fix this?

A

dimaqq commented 2 months ago

Yep, fixed!