blob: 87972d2bb5b3690a40cc08acfd8ec1639443de7c [file] [log] [blame]
xixuanebdb0a82017-04-28 11:25:02 -07001#!/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
13set -eu
14
15realpath() {
16 readlink -f -- "$1"
17}
18
19readonly venv_repo=$(realpath ../../../../infra_virtualenv)
20readonly create_script=$(realpath "${venv_repo}/bin/create_venv")
21readonly venv_home=$(realpath ../venv)
22readonly reqs_file=$(realpath "${venv_home}/requirements.txt")
23
24exec_python_module() {
25 venvdir=$("${create_script}" "$reqs_file")
26 export PYTHONPATH=${venv_home}
27 exec "${venvdir}/bin/python" -m "$@"
28}