From 20302b1c88aaadcb6352a61635c7887cf68058b2 Mon Sep 17 00:00:00 2001 From: Marnik Bercx Date: Mon, 28 Aug 2023 22:26:01 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20`append=5Fdeactivate=5Ftex?= =?UTF-8?q?t`=20for=20`venv`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From Python 3.10, the `VIRTUAL_ENV_PROMPT` environment variable is also set and unset in the `activate` script. Since our current (obviously rather fragile) approach to adding text to the `deactivate` function in the `activate` script relies on replacing `VIRTUAL_ENV`, this would break and give the following error: ``` deactivate:31: command not found: _PROMPT ``` when activating or deactivating the environment. Here we switch to replacing the `deactivate () {` line in the `activate` script that. That should be more robust unless the function definition syntax is changed. --- aiida_project/commands/main.py | 5 ++++- aiida_project/project/venv.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/aiida_project/commands/main.py b/aiida_project/commands/main.py index bc70f2b..fdcd450 100644 --- a/aiida_project/commands/main.py +++ b/aiida_project/commands/main.py @@ -24,7 +24,10 @@ eval "$(_VERDI_COMPLETE={shell}_source verdi)" """ -DEACTIVATE_AIIDA_SH = "unset AIIDA_PATH" +DEACTIVATE_AIIDA_SH = """ +# Added by `aiida-project` +unset AIIDA_PATH +""" app = typer.Typer(pretty_exceptions_show_locals=False) diff --git a/aiida_project/project/venv.py b/aiida_project/project/venv.py index 5971c85..df98dd4 100644 --- a/aiida_project/project/venv.py +++ b/aiida_project/project/venv.py @@ -38,8 +38,8 @@ def append_deactivate_text(self, text): with Path(self.venv_path, "bin", "activate").open("w") as handle: handle.write( contents.replace( - "unset VIRTUAL_ENV", - f"unset VIRTUAL_ENV\n{text}\n", + "deactivate () {", + "deactivate () {" + f"\n{text}\n", ) )