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

Interaction with autodoc plugin not working ? #148

Open
henridb opened this issue Feb 7, 2024 · 13 comments
Open

Interaction with autodoc plugin not working ? #148

henridb opened this issue Feb 7, 2024 · 13 comments
Labels

Comments

@henridb
Copy link

henridb commented Feb 7, 2024

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
Copy link
Author

henridb commented Feb 7, 2024

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 :)

@aakhavanQC
Copy link

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

@pradyunsg
Copy link
Collaborator

pradyunsg commented Mar 9, 2024

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?

@aakhavanQC
Copy link

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.

@henridb
Copy link
Author

henridb commented Mar 11, 2024

@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!

@pradyunsg
Copy link
Collaborator

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.

@aakhavanQC
Copy link

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
Copy link

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 sphinx-doc/sphinx#11939 which has been merged but not yet released.

@aakhavanQC
Copy link

@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

@dshemnv
Copy link

dshemnv commented Apr 11, 2024

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.

@return42
Copy link

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 ..

try:
for command in self.pre_build_commands:
show(context="pre-build", command=command)
subprocess.run(command, check=True)
except subprocess.CalledProcessError as e:

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

# This isn't public API, but we want to avoid a subprocess call
from sphinx.cmd.build import build_main

# NOTE:
# sphinx.cmd.build.build_main is not considered to be public API,
# but as this is a first-party project, we can cheat a little bit.
if return_code := build_main(self.sphinx_args):
print(f"Sphinx exited with exit code: {return_code}")

@pradyunsg
Copy link
Collaborator

.. 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).

return42 added a commit to return42/sphinx-autobuild that referenced this issue May 30, 2024
To update changes to the doc strings (autodoc) in the source code in the HTML
output, the sphinx-build must not run in the same process as the server /
sphinx-build must run in a subprocess so that changed source code is
re-imported.

This issue was introduced in commit d57f117 / a commit without a PR & review.

Related: sphinx-doc#31 (comment)
Closes: sphinx-doc#148

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
return42 added a commit to return42/sphinx-autobuild that referenced this issue May 30, 2024
To update changes to the doc strings (autodoc) in the source code in the HTML
output, the sphinx-build must not run in the same process as the server /
sphinx-build must run in a subprocess so that changed source code is
re-imported.

This issue was introduced in commit d57f117 / a commit without a PR & review.

Related: sphinx-doc#31 (comment)
Closes: sphinx-doc#148

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
return42 added a commit to return42/sphinx-autobuild that referenced this issue May 30, 2024
To update changes to the doc strings (autodoc) in the source code in the HTML
output, the sphinx-build must not run in the same process as the server /
sphinx-build must run in a subprocess so that changed source code is
re-imported.

This issue was introduced in commit d57f117 / a commit without a PR & review.

Related: sphinx-doc#31 (comment)
Closes: sphinx-doc#148

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
@return42
Copy link

return42 commented May 30, 2024

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 #164 to fix two issues I have found.


Update: #158 might also related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants