Closed aittalam closed 2 weeks ago
Hello there! I've been looking into possible options here, I want to present a possible solution I created this PR (I'll create a proper PR with all the comments after we decided if we like it)
I've replaced the volume
in docker-compose with a sync
directive. It's based on the example uv
has on their repo
I've applied the following changes:
backend/.venv
I've tested the flow described in the issue and the container works as expected. Please have a look into it as it changes your flow (your current terminal won't be detached)
PS: I have found though, that even having the .venv
ignored, running the tests syncs some files inside the container (I assume that the test will create some temp files that get deleted, because I wasn't able to find them after running pytest
Hi there @aittalam , do you think we can close this one after https://github.com/mozilla-ai/lumigator/pull/323?
Yes @agpituk , thanks! There is a follow-up to this I have tracked in https://github.com/mozilla-ai/lumigator/issues/375
Describe the bug In developer mode, the lumigator folder is mounted on the backend container. The fastapi server automatically reloads whenever any change in the backend folder is detected, so developers can update code in their IDE and see changes reflected immediately on the backend server.
Since the introduction of uv, the backend python environment is stored in
/mzai/lumigator/python/mzai/backend/.venv
and is generated automatically when the backend is deployed with docker compose via themake local-up
command. Things work properly until the environment is updated locally (e.g. on laptop) via e.g.uv sync
oruv run pytest
: when the command is run, the previous .venv (which points to a python interpreter which does not exist on laptop) is rebuilt and thus updated on the backend too. At that point, fastapi reloads the server but then -probably because it finds a .venv which is now unsuitable for the backend- shuts down the server.System Information (please complete the following information):
To Reproduce
Expected behavior One should be able to run tests without breaking the backend or, more precisely, i.e. without updating the
.venv
that is used in the backend. This has another advantage, i.e. that by preserving the backend venv in place we wouldn't have to re-download dependencies every time we domake local-up
.This could be attained by running pytest in an isolated environment:
SQLALCHEMY_DATABASE_URL=sqlite:///local.db uv run --isolated pytest
I think updating documentation making the dependency between local and backend environments for developers more explicit and adding the above command for tests would already be a reasonable fix.