Skip to content

[Bug]: Dev Containers - Tools do not run inside the Python virtual environment #1123

@apgrucza

Description

@apgrucza

Current Behavior (bug)

Tools other than Python (e.g. GNU Make) do not run inside the Python virtual environment. This is because the wrapper scripts in .devbox/virtenv/.wrappers/bin detect a mismatch in the shell environment hash and then reset the environment with devbox shellenv.

To reproduce:

  1. Run devbox create --template python-pip
  2. Run cd python-pip
  3. Run devbox add gnumake@4.3
  4. Run printf "which_python:\n\twhich python\n" > Makefile
  5. Run devbox generate devcontainer
  6. Run code .
  7. In the popup window, click Reopen in Container
  8. Once the dev container is ready, open a terminal window and run make which_python

The path shown is not to the Python virtual environment:
/code/.devbox/virtenv/.wrappers/bin/python

Expected Behavior (fix)

The output should show this path:
/code/.devbox/virtenv/python310Packages.pip/.venv/bin/python

Currently the shell environment hash mismatch occurs because devbox shell --print-env and devbox shellenv give slightly different results. The former includes __DEVBOX_VERSION_CHECK="1" and the latter does not. So, a (fragile) workaround is to modify the Dockerfile by changing

RUN devbox shellenv --init-hook >> ~/.profile

to

RUN __DEVBOX_VERSION_CHECK="1" devbox shellenv --init-hook >> ~/.profile

A proper solution would be to ensure that the shell and shellenv commands return identical environments.

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 

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions