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 84 forks source link

Fix hot reloading for Python 3.9 #182

Open MtkN1 opened 4 weeks ago

MtkN1 commented 4 weeks ago

Fixes #178

Move asyncio.Event creation to lifespan

This PR moves the creation of the asyncio.Event from RebuildServer.__init__ to the Starlette lifespan to ensure it's created within the event loop context. This resolves the error we were seeing due to the event loop not being available during initialization.

Added a rebuild test

[!WARNING] Tests fail erratically.

There's a high probability that executing lifespan in the test code is causing pytest command to randomly fail after successful test runs. Please retry the CI. It's truly random: FATAL: exception not rethrown. I suspect this is due to the interaction between Starlette's TestClient, anyio threads, or related dependencies, but haven't found a solution yet.

nox > Running session test-3.10
nox > Creating virtual environment (virtualenv) using python3.10 in .nox/test-3-10
nox > python -m pip install -e '.[test]'
nox > pytest 
============================= test session starts ==============================
platform linux -- Python 3.10.15, pytest-8.3.3, pluggy-1.5.0
rootdir: /home/runner/work/sphinx-autobuild/sphinx-autobuild
configfile: pyproject.toml
plugins: anyio-4.6.2.post1
collected 7 items

tests/test_application.py .                                              [ 14%]
tests/test_ignore.py ......                                              [100%]

============================== 7 passed in 1.55s ===============================
FATAL: exception not rethrown
nox > Command pytest  failed with exit code -6
nox > Session test-3.10 failed.

While I'm satisfied with the test code itself, should I consider removing the test? Manual testing has been successful.