forked from apache/aurora
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pants
executable file
·72 lines (54 loc) · 1.76 KB
/
pants
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
72
#!/usr/bin/env bash
PANTS_ROOT=$(dirname "$0")
PANTS_VERSION=$(cat "$PANTS_ROOT/.pantsversion")
if [[ -e "$PANTS_ROOT/pants.pex" ]]; then
cat <<EOF | PANTS_ROOT="$PANTS_ROOT" PANTS_VERSION=$PANTS_VERSION python
from contextlib import closing
import json
import os
import sys
import zipfile
with closing(zipfile.ZipFile(os.path.join(os.environ['PANTS_ROOT'], 'pants.pex'))) as zf:
pex_info = json.loads(zf.read('PEX-INFO'))
for requirement, _, _ in pex_info['requirements']:
if '==' in requirement:
req, version = requirement.split('==', 2)
if req == 'twitter.pants' and version == os.environ['PANTS_VERSION']:
sys.exit(0)
sys.exit(1)
EOF
if [ $? -eq 0 ]; then
exec "$PANTS_ROOT/pants.pex" "$@"
fi
fi
PANTS_TEMP=$(mktemp -d /tmp/pants.XXXXXX)
./build-support/virtualenv "$PANTS_TEMP/tcp"
pushd "$PANTS_TEMP"
source tcp/bin/activate
pip install twitter.common.python==0.2.0
PYTHON_VERBOSE=1 PEX_VERBOSE=1 python <<EOF
from twitter.common.python.fetcher import Fetcher, PyPIFetcher
from twitter.common.python.http import Crawler
from twitter.common.python.obtainer import Obtainer
from twitter.common.python.pex_builder import PEXBuilder
from twitter.common.python.resolver import Resolver
from twitter.common.python.translator import Translator
pb = PEXBuilder()
resolver = Resolver(crawler=Crawler(), fetchers=[PyPIFetcher()])
req = 'twitter.pants==$PANTS_VERSION'
pb.add_requirement(req)
for dist in resolver.resolve(req):
pb.add_distribution(dist)
pb.info.entry_point = 'twitter.pants.bin.pants_exe:main'
pb.build('dist/pants.pex')
EOF
BUILD_SUCCESS=$?
deactivate
popd
if [ $BUILD_SUCCESS -ne 0 ]; then
echo 'Failed to build pants.'
exit 1
fi
cp -f -- "$PANTS_TEMP/dist/pants.pex" "$PANTS_ROOT"
rm -rf "$PANTS_TEMP"
exec "$PANTS_ROOT/pants.pex" "$@"