sphinx-autobuild icon indicating copy to clipboard operation
sphinx-autobuild copied to clipboard

Interaction with autodoc plugin not working ?

Open henridb opened this issue 1 year ago • 13 comments

I'm using the autodoc sphinx plugin, so in order to work on the documentation from the docstrings in my code I would expect the following command to work:

sphinx-autobuild docs build --watch src

It seems to partially work, in the sense that editing a source file and saving indeed triggers a rebuild, but the output does not change. From my experimentation, it seems like the code is somehow cached, and this it's always the version existing at the first launch of the above mentioned command that gets built.

I haven't found a solution so far, is this a bug ? a configuration problem ?

henridb avatar Feb 07 '24 09:02 henridb

By digging some more, the problem might come from the fact that we are not exiting the python interpreter between each build, meaning that my package gets imported once, and then each subsequent import does nothing. This might be solved by using importlib's reload function. I'm still digging :)

henridb avatar Feb 07 '24 09:02 henridb

@henridb - any luck debugging this? I'm seeing the same

aakhavanQC avatar Mar 08 '24 16:03 aakhavanQC

See https://github.com/sphinx-doc/sphinx-autobuild#relevant-sphinx-bugs. I guess #142 should be reverted/amended since it sounds like rebuilds aren't detecting rescans of source code.

Can you confirm what version of Sphinx you're using?

pradyunsg avatar Mar 09 '24 14:03 pradyunsg

See https://github.com/sphinx-doc/sphinx-autobuild#relevant-sphinx-bugs. I guess #142 should be reverted/amended since it sounds like rebuilds aren't detecting rescans of source code.

Can you confirm what version of Sphinx you're using?

I'm on 7.2.6 which appears to be the latest. And autobuild 2024.02.04. I did see the note in the readme, but the issue isn't that the changes in the source code aren't detected. If I make a change to the file, the rebuild runs, but the outputs don't change, even if I disable incremental builds. I'm guessing the reporter is right that because the interpreter lives between rebuilds, it's not actually re-importing the updated source code file.

aakhavanQC avatar Mar 11 '24 16:03 aakhavanQC

@henridb - any luck debugging this? I'm seeing the same

Nop, I sorry. In the end I gave up and put the sphinx build on a key building on my IDE. It was the easiest and it's sufficient for my purpose. But if ever this get fixed (or if someone is ready to guide me through the steps to contribute to this repo :) ), I would be happy to come back to this tool!

henridb avatar Mar 11 '24 17:03 henridb

I'm guessing the reporter is right that because the interpreter lives between rebuilds, it's not actually re-importing the updated source code file.

Hmm... It doesn't -- sphinx-build is invoked as a separate subprocess.

pradyunsg avatar Mar 15 '24 02:03 pradyunsg

I'm guessing the reporter is right that because the interpreter lives between rebuilds, it's not actually re-importing the updated source code file.

Hmm... It doesn't -- sphinx-build is invoked as a separate subprocess.

Is there a way to show exactly what command is being invoked? Then I can run that separately to see what happens.

aakhavanQC avatar Mar 18 '24 17:03 aakhavanQC

Did some more digging; the issue isn't with autobuild. It runs sphinx-build -v which doesn't detect the changes in the file. Seems to be fixed by https://github.com/sphinx-doc/sphinx/pull/11939 which has been merged but not yet released.

aakhavanQC avatar Mar 26 '24 21:03 aakhavanQC

@pradyunsg - there is definitely a sphinx-autobuild specific issue here. I installed sphinx from github, so the latest code, and I'm seeing the following:

  1. rm -rf docs/_build
  2. sphinx-build doc docs/_build doc builds correctly
  3. change source code file
  4. sphinx-build doc docs/_build docs update correctly
  5. sphinx-autobuild docs docs/_build --watch src
  6. change source code file docs update correctly
  7. change source code file again docs do not update
  8. exit sphinx-autobuild
  9. sphinx-build doc docs/_build docs do not update
  10. change source code file again
  11. sphinx-build doc docs/_build docs update correctly

Key takeaways:

  • sphinx-build correctly updates the docs every time source code is changed
  • sphinx-autobuild correctly updates the docs the first time
  • after the first change (or the second build, possibly), sphinx-autobuild corrupts the docs in such a way that sphinx-build no longer updates the docs on source code changes

I can reproduce this consistently

aakhavanQC avatar Apr 01 '24 19:04 aakhavanQC

Until there is a solution, the workaround I found for this is:

find source/ ../mymodule/ -name "*.rst" -o -name "*.py" | entr make html

I can launch a local server with my IDE (vscode) from the build folder that does the reloading automatically.

dshemnv avatar Apr 11 '24 08:04 dshemnv

I'm guessing the reporter is right that because the interpreter lives between rebuilds, it's not actually re-importing the updated source code file.

Hmm... It doesn't -- sphinx-build is invoked as a separate subprocess.

Sure? .. If I interpret the source code correctly; the pre-build tasks are executed in a separate subprocess ..

https://github.com/sphinx-doc/sphinx-autobuild/blob/674264ecf1ea64b8276d80f809cd679150a2646c/sphinx_autobuild/build.py#L22-L26

.. but not the sphinx build itself, the sphinx build is in-process (sphinx.cmd.build.build_main) :

https://github.com/sphinx-doc/sphinx-autobuild/blob/674264ecf1ea64b8276d80f809cd679150a2646c/sphinx_autobuild/build.py#L5-L6

https://github.com/sphinx-doc/sphinx-autobuild/blob/674264ecf1ea64b8276d80f809cd679150a2646c/sphinx_autobuild/build.py#L36-L40

return42 avatar May 30 '24 07:05 return42

.. but not the sphinx build itself, the sphinx build is in-process (sphinx.cmd.build.build_main) :

Ah, looks like a change made directly on main that I didn't realise was made. I'm gonna defer to @AA-Turner on this, since it might just be a case of Sphinx's internals holding state that's causing issues here (which is part of why the project was using subprocesses earlier, even though Sphinx has a -m sphinx which could've been invoked via runpy.run_module earlier).

pradyunsg avatar May 30 '24 10:05 pradyunsg

Ah, looks like a change made directly on main that I didn't realise was made.

Not the only issue committed in the last few month .. I send https://github.com/sphinx-doc/sphinx-autobuild/pull/164 to fix two issues I have found.


Update: https://github.com/sphinx-doc/sphinx-autobuild/issues/158 might also related.

return42 avatar May 30 '24 10:05 return42

should be closed by https://github.com/sphinx-doc/sphinx-autobuild/pull/164

return42 avatar Sep 03 '24 07:09 return42