xixuan | ebdb0a8 | 2017-04-28 11:25:02 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | # |
| 6 | # Find the virtualenv repo to use. |
| 7 | # |
| 8 | # This is meant to be sourced in scripts that need virtualenv. The |
| 9 | # sourcing script should cd into the directory containing this script |
| 10 | # first. This script defines functions for performing common tasks: |
| 11 | # |
| 12 | # exec_python_module -- Execute Python module inside of virtualenv |
| 13 | set -eu |
| 14 | |
| 15 | realpath() { |
| 16 | readlink -f -- "$1" |
| 17 | } |
| 18 | |
| 19 | readonly venv_repo=$(realpath ../../../../infra_virtualenv) |
| 20 | readonly create_script=$(realpath "${venv_repo}/bin/create_venv") |
| 21 | readonly venv_home=$(realpath ../venv) |
| 22 | readonly reqs_file=$(realpath "${venv_home}/requirements.txt") |
| 23 | |
| 24 | exec_python_module() { |
| 25 | venvdir=$("${create_script}" "$reqs_file") |
| 26 | export PYTHONPATH=${venv_home} |
| 27 | exec "${venvdir}/bin/python" -m "$@" |
| 28 | } |