Skip to content

Recreate virtual environments when changing packages #1855

Open
@gcurtis

Description

@gcurtis

Ensure that Python and Ruby virtual environments get deleted and recreated whenever a shared library is added or removed.

Both Python and Ruby virtual environments create symlinks or set environment variables that point to a specific version of their interpreter. This means they got locked to a specific interpreter and become stale whenever a Devbox package is added/removed/patched, which leads to a couple common bugs:

  • If a package is changed to have patch_glibc: true, the virtual environment will continue to use the unpatched interpreter.
  • If a package adds or removes a shared library, the interpreter’s shared library dependencies get out-of-sync with the user’s application dependencies.

Example

To give an example for the second bullet point, say that a user adds the OpenSSL libraries to their Devbox Python project:

$ devbox add openssl@latest --outputs out,dev
$ devbox shell
(devbox) $ pip install <some_python_package>
(devbox) $ python app.py

Everything works fine, but the user didn't realize that pip install <some_python_package> built a C extension that linked against OpenSSL. Later on they decide they don’t need OpenSSL anymore and remove it from Devbox:

$ devbox rm openssl
$ devbox shell
(devbox) $ python app.py
# crash!

Their app no longer works because some_python_package's C extension was linked against the OpenSSL libraries in Devbox’s lib directory, and now they’re gone.

This is difficult for users to debug because the crash originates from within one of their app's Python dependencies. The error message also tends to be a cryptic linker error, which is hard to understand unless you're familiar with the subtleties of dynamic linking on Linux.

If we destroy virtual environments whenever a package is added or removed, pip/bundler will reinstall dependencies, which will ensure that the virtual environment is in sync with the Devbox environment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingglibcRelated to linking against glibclinkerRelated to linking (ld, ld.so or dyld)linuxLinux systemspythonSupport for Python, pip, Poetry, etc.rubySupport for Ruby, gems, Bundler, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions