Skip to content

Commit

Permalink
🐛 Fix append_deactivate_text for venv
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mbercx committed Aug 28, 2023
1 parent 9ebc3f8 commit 20302b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion aiida_project/commands/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions aiida_project/project/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
)

Expand Down

0 comments on commit 20302b1

Please sign in to comment.