Add support for a $sitedir/venv directory and activate it when found.

Review Request #13056 — Created May 19, 2023 and submitted

Information

Review Board
release-5.0.x

Reviewers

As part of an effort to move toward encouraging virtualenv-based
management of Review Board installs, this change updates our WSGI
entrypoint and our auto-generated configurations to detect and
sanity-check a virtualenv setup and activate it if available.

reviewboard/wsgi.py now looks to see if we have a $sitedir/venv
directory. If it exists, and we're not already in a virtualenv, it will
make sure the right files are present and then activate it. If anything
is missing, a RuntimeError will be raised with instructions, helping
admins sort out the issue.

Validation checks for the presence of an activate_this.py (which is
created by virtualenv but not python -m venv) and a pythonX.Y
binary matching the currently-executing Python version.

Environment variables are built from the new state, ensuring
subprocesses will see the correct versions of binaries and packages.

This also adds a $sitedir/bin to $PATH, giving us a place to put
executables like p4 without placing them in system directories.

Tested with both a global Python and a virtualenv-backed install.
Verified that the venv directory was present for a virtualenv-backed
install, and that its environment was properly used in a default Apache,
uWSGI, and Gunicorn setup.

Tested pruning some of the virtualenv dir to hit the WSGI error checks.
Verified the resulting errors.

Summary ID
Add support for a $sitedir/venv directory and activate it when found.
As part of an effort to move toward encouraging virtualenv-based management of Review Board installs, this change updates our WSGI entrypoint and our auto-generated configurations to detect and sanity-check a virtualenv setup and activate it if available. `reviewboard/wsgi.py` now looks to see if we have a `$sitedir/venv` directory. If it exists, and we're not already in a virtualenv, it will make sure the right files are present and then activate it. If anything is missing, a `RuntimeError` will be raised with instructions, helping admins sort out the issue. Validation checks for the presence of an `activate_this.py` (which is created by `virtualenv` but not `python -m venv`) and a `pythonX.Y` binary matching the currently-executing Python version. Environment variables are built from the new state, ensuring subprocesses will see the correct versions of binaries and packages. This also adds a `$sitedir/bin` to `$PATH`, giving us a place to put executables like `p4` without placing them in system directories.
8e4f7a5ca4bf3e4ef389af98d7c6ffcf578c3625
Description From Last Updated

Instead of "recreate" I think we should explicitly say they should delete the old one and create a new one …

daviddavid
david
  1. 
      
  2. reviewboard/wsgi.py (Diff revision 1)
     
     
     
    Show all issues

    Instead of "recreate" I think we should explicitly say they should delete the old one and create a new one with virtualenv.

  3. 
      
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-5.0.x (8897ac0)