-
Notifications
You must be signed in to change notification settings - Fork 30
/
pants
executable file
·110 lines (93 loc) · 3.96 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
# =============================== NOTE ===============================
# This pants bootstrap script comes from the pantsbuild/setup
# project and is intended to be checked into your code repository so
# that any developer can check out your code and be building it with
# pants with no prior setup needed.
#
# You can learn more here: https://pantsbuild.github.io/setup
# ====================================================================
set -eou pipefail
PYTHON=${PYTHON:-$(which python2.7)}
PANTS_HOME="${PANTS_HOME:-${XDG_CACHE_HOME:-$HOME/.cache}/pants/setup}"
PANTS_BOOTSTRAP="${PANTS_HOME}/bootstrap-$(uname -s)-$(uname -m)"
VENV_VERSION=${VENV_VERSION:-16.0.0}
# This requirement is installed before pantsbuild.pants to hack around
# interpreters that have newer setuptools already installed, effectively
# re-installing an older setuptools and pinning low to a version known to be
# ingestable by both pants and pex for all reasonable versions of pants.
# See:
# https://github.com/pantsbuild/pants/issues/3948
# https://github.com/pantsbuild/setup/issues/14
# https://github.com/pantsbuild/setup/issues/19
SETUPTOOLS_REQUIREMENT="setuptools==5.4.1"
VENV_PACKAGE=virtualenv-${VENV_VERSION}
VENV_TARBALL=${VENV_PACKAGE}.tar.gz
# The high-level flow:
# 1.) Grab pants version from pants.ini or default to latest.
# 2.) Check for a venv via a naming/path convention and execute if found.
# 3.) Otherwise create venv and re-exec self.
#
# After that pants itself will handle making sure any requested plugins
# are installed and up to date.
function tempdir {
mktemp -d "$1"/pants.XXXXXX
}
# TODO(John Sirois): GC race loser tmp dirs leftover from bootstrap_XXX
# functions. Any tmp dir w/o a symlink pointing to it can go.
function bootstrap_venv {
if [[ ! -d "${PANTS_BOOTSTRAP}/${VENV_PACKAGE}" ]]
then
(
mkdir -p "${PANTS_BOOTSTRAP}"
staging_dir=$(tempdir "${PANTS_BOOTSTRAP}")
cd "${staging_dir}"
curl -LO https://pypi.io/packages/source/v/virtualenv/${VENV_TARBALL}
tar -xzf ${VENV_TARBALL}
ln -s "${staging_dir}/${VENV_PACKAGE}" "${staging_dir}/latest"
mv "${staging_dir}/latest" "${PANTS_BOOTSTRAP}/${VENV_PACKAGE}"
) 1>&2
fi
echo "${PANTS_BOOTSTRAP}/${VENV_PACKAGE}"
}
function bootstrap_pants {
pants_requirement="pantsbuild.pants"
pants_version=$(
grep -E "^[[:space:]]*pants_version" pants.ini 2>/dev/null | \
cut -f2 -d: | tr -d " "
)
if [[ -n "${pants_version}" ]]
then
pants_requirement="${pants_requirement}==${pants_version}"
else
pants_version="unspecified"
fi
if [[ ! -d "${PANTS_BOOTSTRAP}/${pants_version}" ]]
then
(
# NB: We setup the virtualenv with no setuptools to ensure our
# ${SETUPTOOLS_REQUIREMENT} wins.
venv_path="$(bootstrap_venv)"
staging_dir=$(tempdir "${PANTS_BOOTSTRAP}")
"${PYTHON}" "${venv_path}/virtualenv.py" --no-setuptools --no-download \
"${staging_dir}/install"
"${staging_dir}/install/bin/pip" install -U pip
"${staging_dir}/install/bin/pip" install "${SETUPTOOLS_REQUIREMENT}"
"${staging_dir}/install/bin/pip" install "${pants_requirement}"
ln -s "${staging_dir}/install" "${staging_dir}/${pants_version}"
mv "${staging_dir}/${pants_version}" "${PANTS_BOOTSTRAP}/${pants_version}"
) 1>&2
fi
echo "${PANTS_BOOTSTRAP}/${pants_version}"
}
# Ensure we operate from the context of the ./pants buildroot.
cd "$(cd "$(dirname ${BASH_SOURCE[0]})" && pwd -P)"
pants_dir=$(bootstrap_pants)
# We set the env var no_proxy to '*', to work around an issue with urllib using non
# async-signal-safe syscalls after we fork a process that has already spawned threads.
#
# See https://blog.phusion.nl/2017/10/13/why-ruby-app-servers-break-on-macos-high-sierra-and-what-can-be-done-about-it/
export no_proxy=*
exec "${pants_dir}/bin/python" "${pants_dir}/bin/pants" "$@"