From 700d19c2ae1cfad2972896fc77720dcf00160ccc Mon Sep 17 00:00:00 2001 From: PranjalManhgaye Date: Mon, 9 Mar 2026 00:00:54 +0530 Subject: [PATCH] systemtests: fix Python bindings version + robustness (fixes #584) - Activate /home/precice/venv at runtime via ENV VIRTUAL_ENV and PATH in python_bindings, fenics_adapter, nutils_adapter Docker stages - Set PRECICE_TUTORIALS_NO_VENV=1 in component templates so run scripts skip creating .venv and use the Docker image's version - Add sanity check: fail fast with clear error if precice not importable when PRECICE_TUTORIALS_NO_VENV is set - Changelog: note that ubuntu_2204 is fixed by template change alone (uses pip install --user, no venv) Made-with: Cursor --- changelog-entries/584.md | 1 + tools/tests/component-templates/fenics-adapter.yaml | 5 ++++- tools/tests/component-templates/nutils-adapter.yaml | 5 ++++- tools/tests/component-templates/python-bindings.yaml | 5 ++++- tools/tests/dockerfiles/ubuntu_2404/Dockerfile | 8 +++++++- 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 changelog-entries/584.md diff --git a/changelog-entries/584.md b/changelog-entries/584.md new file mode 100644 index 000000000..c6ffe836f --- /dev/null +++ b/changelog-entries/584.md @@ -0,0 +1 @@ +- Fix Python bindings version being ignored in system tests (fixes [#584](https://github.com/precice/tutorials/issues/584)): Permanently activate `/home/precice/venv` in the `python_bindings`, `fenics_adapter`, and `nutils_adapter` Docker stages via `VIRTUAL_ENV` and `PATH`; set `PRECICE_TUTORIALS_NO_VENV=1` in component templates so tutorial run scripts skip creating their own venv and use the version installed by the Docker image. Add a sanity check before running to fail fast with a clear error if precice is not importable when the escape hatch is set. Ubuntu 22.04 uses `pip install --user` (no venv) and is fixed by the template change alone. diff --git a/tools/tests/component-templates/fenics-adapter.yaml b/tools/tests/component-templates/fenics-adapter.yaml index 220a52525..550c209e2 100644 --- a/tools/tests/component-templates/fenics-adapter.yaml +++ b/tools/tests/component-templates/fenics-adapter.yaml @@ -5,12 +5,15 @@ build: - {{key}}={{value}} {% endfor %} target: fenics_adapter +environment: + - PRECICE_TUTORIALS_NO_VENV=1 depends_on: prepare: condition: service_completed_successfully volumes: - {{ run_directory }}:/runs command: > - /bin/bash -c "id && + /bin/bash -c "id && + [ -n \"$$PRECICE_TUTORIALS_NO_VENV\" ] && (python3 -c 'import precice' || { echo 'ERROR: PRECICE_TUTORIALS_NO_VENV set but precice not found. Check Docker image.'; exit 1; }) ; cd '/runs/{{ tutorial_folder }}/{{ case_folder }}' && {{ run }} | tee system-tests_{{ case_folder }}.log 2>&1" diff --git a/tools/tests/component-templates/nutils-adapter.yaml b/tools/tests/component-templates/nutils-adapter.yaml index 5893c65a7..0b2f6ec44 100644 --- a/tools/tests/component-templates/nutils-adapter.yaml +++ b/tools/tests/component-templates/nutils-adapter.yaml @@ -5,12 +5,15 @@ build: - {{key}}={{value}} {% endfor %} target: nutils_adapter +environment: + - PRECICE_TUTORIALS_NO_VENV=1 depends_on: prepare: condition: service_completed_successfully volumes: - {{ run_directory }}:/runs command: > - /bin/bash -c "id && + /bin/bash -c "id && + [ -n \"$$PRECICE_TUTORIALS_NO_VENV\" ] && (python3 -c 'import precice' || { echo 'ERROR: PRECICE_TUTORIALS_NO_VENV set but precice not found. Check Docker image.'; exit 1; }) ; cd '/runs/{{ tutorial_folder }}/{{ case_folder }}' && {{ run }} | tee system-tests_{{ case_folder }}.log 2>&1" diff --git a/tools/tests/component-templates/python-bindings.yaml b/tools/tests/component-templates/python-bindings.yaml index 3cd65d274..e8be1c887 100644 --- a/tools/tests/component-templates/python-bindings.yaml +++ b/tools/tests/component-templates/python-bindings.yaml @@ -5,12 +5,15 @@ build: - {{key}}={{value}} {% endfor %} target: python_bindings +environment: + - PRECICE_TUTORIALS_NO_VENV=1 depends_on: prepare: condition: service_completed_successfully volumes: - {{ run_directory }}:/runs command: > - /bin/bash -c "id && + /bin/bash -c "id && + [ -n \"$$PRECICE_TUTORIALS_NO_VENV\" ] && (python3 -c 'import precice' || { echo 'ERROR: PRECICE_TUTORIALS_NO_VENV set but precice not found. Check Docker image.'; exit 1; }) ; cd '/runs/{{ tutorial_folder }}/{{ case_folder }}' && {{ run }} | tee system-tests_{{ case_folder }}.log 2>&1" diff --git a/tools/tests/dockerfiles/ubuntu_2404/Dockerfile b/tools/tests/dockerfiles/ubuntu_2404/Dockerfile index e87599880..0f55a60f4 100644 --- a/tools/tests/dockerfiles/ubuntu_2404/Dockerfile +++ b/tools/tests/dockerfiles/ubuntu_2404/Dockerfile @@ -91,7 +91,9 @@ WORKDIR /home/precice RUN python3 -m venv /home/precice/venv && \ . /home/precice/venv/bin/activate && \ pip3 install git+https://github.com/precice/python-bindings.git@${PYTHON_BINDINGS_REF} && \ - pip3 install matplotlib + pip3 install matplotlib +ENV VIRTUAL_ENV="/home/precice/venv" +ENV PATH="/home/precice/venv/bin:$PATH" FROM precice_dependecies AS fenics_adapter COPY --from=python_bindings /home/precice/.local /home/precice/.local @@ -105,6 +107,8 @@ ARG FENICS_ADAPTER_REF RUN python3 -m venv --system-site-packages /home/precice/venv && \ . /home/precice/venv/bin/activate && \ pip3 install git+https://github.com/precice/fenics-adapter.git@${FENICS_ADAPTER_REF} +ENV VIRTUAL_ENV="/home/precice/venv" +ENV PATH="/home/precice/venv/bin:$PATH" FROM precice_dependecies AS nutils_adapter @@ -114,6 +118,8 @@ USER precice RUN python3 -m venv /home/precice/venv && \ . /home/precice/venv/bin/activate && \ pip3 install nutils +ENV VIRTUAL_ENV="/home/precice/venv" +ENV PATH="/home/precice/venv/bin:$PATH" FROM precice_dependecies AS calculix_adapter