Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Dev Containers - Python virtual environment not activated when postCreateCommand runs #1122

Closed
apgrucza opened this issue Jun 8, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@apgrucza
Copy link
Contributor

apgrucza commented Jun 8, 2023

Current Behavior (bug)

The Python virtual environment is not activated by the time that VS Code runs the postCreateCommand action. This is because the Python virtual environment is created on demand, rather than during the Docker build phase.

To reproduce:

  1. Run devbox create --template python-pip
  2. Run cd python-pip
  3. Run devbox generate devcontainer
  4. Add the following to .devcontainer/devcontainer.json: "postCreateCommand": "which python"
  5. Run code .
  6. In the popup window, click Reopen in Container

When the Configuring... terminal window appears, the path shown is not to the Python virtual environment:
/code/.devbox/virtenv/.wrappers/bin/python

Expected Behavior (fix)

The terminal window should show this path:
/home/devbox/.local/state/devbox/v-933c2/python310Packages.pip/.venv/bin/python

Currently devbox install does not create the Python virtual environment, but devbox run does. So, a workaround is to modify the Dockerfile by changing

RUN devbox install

to

RUN devbox run -- echo "Installing packages"

A proper solution would be to change devbox install to (optionally?) do the extra initialisation required, or to provide a separate devbox command to do this.

Additional context
Output of devbox version -v:

Version:     0.5.4
Platform:    linux_amd64
Commit:      92bb293af46fe6869648c20e4a6476dc83df0092
Commit Time: 2023-06-01T21:35:06Z
Go Version:  go1.20.4
Launcher:    0.2.0
@apgrucza apgrucza added the bug Something isn't working label Jun 8, 2023
@mohsenari
Copy link
Collaborator

mohsenari commented Jun 14, 2023

@apgrucza Apologies for late response on this and thanks for reporting it. This is an interesting case. I think the fix can be as simple as changing what happens in the CLI when devbox install is called to make sure the python plugin that sets up virtualenv gets called as well.
But that might defeat the purpose of an "install" command. I'll try reproducing this and will make a PR to fix the use case.

@mohsenari
Copy link
Collaborator

mohsenari commented Jul 29, 2023

with the release of 0.5.10 I think this fix is in, and the template is changed to devbox run -- echo "Installed Packages" instead of devbox install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants