Poetry user install error on Gitpod workspace restart
Description
Everything works fine when spinning up a fresh new workspace with gitpod. This is because the init part in .gitpod.yml is run.
However, on workspace restarts (such as closing the tab and then reopening that workspace after some time), poetry install would show ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv. for every single package.
Steps to Reproduce
- Click the
open in gitpodbutton in the README (or just spin up a new workspace using https://gitpod.io/#/github.com/python-discord/sir-lancebot) - Optionally wait until the initialization jobs have completed
- Close the workspace
- Wait until the workspace times out. Can be 60 min to 180 min (see gitpod docs on that)
- Reopen workspace
- Wait for a few seconds and the terminal will show tracebacks for the aforementioned
poetry installerror for every single package
Expected Behaviour
Ideally, when restarting a workspace poetry install (the whole command part of .gitpod.yml) should not throw any errors. If it did, new workspace installs should throw the same error, if any.
Actual Behaviour
Startup tasks for new workspaces run successfully.
When reopening a temporarily suspended workspace, a traceback with ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv. is shown when the .gitpod.yml commands are run (before and commands to be specific).
Known Impacted Platforms
N/A; gitpod is a webapp, AFAIK.
Possible Solutions
According to their documentation on start up tasks for .gitpod.yml
- for new workspaces: all three of
before,init,commandare executed - for workspace restarts: only
beforeandcommandare executed
This is not ideal because the command that solves the error export PIP_USER=false is inside the init key, meaning that command isn't run before command key is run on workspace restarts.
The solution is to put that export command into the command key (of .gitpod.yml) so that that command is guaranteed to run regardless of whether it's a new workspace or an existing one:
tasks:
- name: "Python Environment"
before: "pyenv install 3.9.6 && pyenv global 3.9.6"
init: "pip install poetry"
command: "export PIP_USER=false && poetry install && poetry run pre-commit install"
Would you like to implement a fix?
Note: For high-priority or critical bugs, fixes may be implemented by staff.
I'd like to implement the bug fix
Hi there! Thanks for bringing this up, I had no idea that my implementation would cause this.
yeah, it's easily missed. But it's good to keep the export with the poetry install so doesn't matter what order of the tasks are run, poetry install won't fail with the user install error. By the way you can always test it out in your browser by appending gitpod.io/#/ to the start of the repo URL :)