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

Fix hot reloading for Python 3.9 #182

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sphinx_autobuild/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def __init__(
self.paths = [Path(path).resolve(strict=True) for path in paths]
self.ignore = ignore_filter
self.change_callback = change_callback
self.flag = asyncio.Event()
self.should_exit = asyncio.Event()

@asynccontextmanager
async def lifespan(self, _app) -> AbstractAsyncContextManager[None]:
self.flag = asyncio.Event()
self.should_exit = asyncio.Event()
task = asyncio.create_task(self.main())
yield
self.should_exit.set()
Expand Down
16 changes: 12 additions & 4 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

def test_application(tmp_path):
src_dir = tmp_path / "docs"
index_file = src_dir / "index.rst"
out_dir = tmp_path / "build"
shutil.copytree(ROOT / "docs", tmp_path / "docs")
out_dir.mkdir(parents=True, exist_ok=True)
Expand All @@ -24,9 +25,16 @@ def test_application(tmp_path):
[str(src_dir), str(out_dir)], url_host=url_host, pre_build_commands=[]
)
app = _create_app([src_dir], ignore_handler, builder, out_dir, url_host)
client = TestClient(app)

builder(changed_paths=())
with TestClient(app) as client:
builder(changed_paths=())

response = client.get("/")
assert response.status_code == 200
response = client.get("/")
assert response.status_code == 200

with client.websocket_connect("/websocket-reload") as websocket:
with index_file.open("a") as f:
f.write("hello")

data = websocket.receive_text()
assert data == "refresh"
Loading