ensure-venv.sh 1.1 KB

123456789101112131415161718192021222324252627
  1. #!/bin/bash
  2. # optionally opt out of virtualenv creation
  3. # WARNING: this will be removed (most likely renamed) soon!
  4. if [ "x$SENTRY_NO_VIRTUALENV_CREATION" == "x1" ]; then
  5. exit 0
  6. fi
  7. if [ -n "$VIRTUAL_ENV" ]; then
  8. # we're enforcing that virtualenv be in .venv, since future tooling e.g. venv-update will rely on this.
  9. if [ "$VIRTUAL_ENV" != "${PWD}/.venv" ]; then
  10. echo "You're in a virtualenv, but it's not in the expected location (${PWD}/.venv)"
  11. exit 1
  12. fi
  13. # TODO: when direnv lands, make the check strictly match .python-version.
  14. if ! python -c "import sys; sys.exit(sys.version_info[:2] != (2, 7))"; then
  15. echo "Your virtualenv's python version isn't 2.7. You'll need to recreate it with the correct python version."
  16. exit 1
  17. fi
  18. else
  19. if [ ! -f ".venv/bin/activate" ]; then
  20. echo "You don't seem to have a virtualenv. Please create one by running: python -m virtualenv .venv"
  21. exit 1
  22. fi
  23. echo "You have a virtualenv, but it doesn't seem to be activated. Please run: source .venv/bin/activate"
  24. exit 1
  25. fi