forked from twitter-archive/commons
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pants.multi
executable file
·71 lines (61 loc) · 2.3 KB
/
pants.multi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# ==================================================================================================
# Copyright 2012 Twitter, Inc.
# --------------------------------------------------------------------------------------------------
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this work except in compliance with the License.
# You may obtain a copy of the License in the LICENSE file, or at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==================================================================================================
MY_DIR=$(dirname $0)
PANTS_EXE=$MY_DIR/src/python/twitter/pants/bin/pants_exe.py
function run_pants_bare {
echo Activating $1
VIRTUALENV=$MY_DIR/.python/$1
ACTIVATE=$VIRTUALENV/bin/activate
shift 1
source $ACTIVATE
PYTHONPATH=$MY_DIR/src/python python $PANTS_EXE "$@"
rv=$?
deactivate
return $rv
}
if ! [ -d $MY_DIR/.python/bootstrap ]; then
if ! $MY_DIR/build-support/python/setup.sh; then
echo Failed to bootstrap your Python environment\!
exit 1
fi
run_pants_bare bootstrap src/python/twitter/pants:pants
mv $MY_DIR/dist/pants.pex $MY_DIR/.python/bootstrap/pants.pex
fi
DEFAULT_PYTHON=$(ls $MY_DIR/.python | egrep -v '^(bin|bootstrap)$' | head -1)
if [ -z "$DEFAULT_PYTHON" ]; then
echo No python interpreters found\! Bootstrapping...
$MY_DIR/.python/bootstrap/pants.pex goal setup -vx -ldebug --no-pantsrc
fi
DEFAULT_PYTHON=$(ls $MY_DIR/.python | egrep -v '^(bin|bootstrap)$' | head -1)
if [ -z "$DEFAULT_PYTHON" ]; then
echo No python interpreters found\!
exit 1
fi
PY=${PY:-$DEFAULT_PYTHON}
if ! [ -f $MY_DIR/.python/$PY/bin/activate ]; then
echo Could not find a virtual environment for $PY\!
exit 1
fi
PANTS_PEX=$MY_DIR/.python/$PY/pants.pex
if ! [ -f $PANTS_PEX ]; then
if ! run_pants_bare $PY src/python/twitter/pants:pants; then
echo Failed to build pants for $PY
exit 1
fi
mv -f $MY_DIR/dist/pants.pex $PANTS_PEX
fi
$MY_DIR/.python/bin/$PY $PANTS_PEX "$@"