Skip to content

Commit 2ca03a6

Browse files
authored
Update ./pants script (#80)
latest script from https://static.pantsbuild.org/setup/pants
1 parent a54cd30 commit 2ca03a6

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

pants

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,19 @@ function set_supported_python_versions {
168168
fi
169169
}
170170

171+
function check_python_exe_compatible_version {
172+
local python_exe="$1"
173+
local major_minor_version
174+
major_minor_version="$(get_python_major_minor_version "${python_exe}")"
175+
for valid_version in "${supported_python_versions_int[@]}"; do
176+
if [[ "${major_minor_version}" == "${valid_version}" ]]; then
177+
echo "${python_exe}" && return 0
178+
fi
179+
done
180+
}
181+
171182
function determine_default_python_exe {
172-
for version in "${supported_python_versions_decimal[@]}"; do
183+
for version in "${supported_python_versions_decimal[@]}" "3" ""; do
173184
local interpreter_path
174185
interpreter_path="$(command -v "python${version}")"
175186
if [[ -z "${interpreter_path}" ]]; then
@@ -179,7 +190,9 @@ function determine_default_python_exe {
179190
if [[ "$("${interpreter_path}" --version 2>&1 > /dev/null)" == "pyenv: python${version}"* ]]; then
180191
continue
181192
fi
182-
echo "${interpreter_path}" && return 0
193+
if [[ -n "$(check_python_exe_compatible_version "${interpreter_path}")" ]]; then
194+
echo "${interpreter_path}" && return 0
195+
fi
183196
done
184197
}
185198

@@ -188,25 +201,19 @@ function determine_python_exe {
188201
set_supported_python_versions "${pants_version}"
189202
local requirement_str="For \`pants_version = \"${pants_version}\"\`, Pants requires Python ${supported_message} to run."
190203

191-
local python_bin_name
204+
local python_exe
192205
if [[ "${PYTHON_BIN_NAME}" != 'unspecified' ]]; then
193-
python_bin_name="${PYTHON_BIN_NAME}"
206+
python_exe="$(get_exe_path_or_die "${PYTHON_BIN_NAME}")" || exit 1
207+
if [[ -z "$(check_python_exe_compatible_version "${python_exe}")" ]]; then
208+
die "Invalid Python interpreter version for ${python_exe}. ${requirement_str}"
209+
fi
194210
else
195-
python_bin_name="$(determine_default_python_exe)"
196-
if [[ -z "${python_bin_name}" ]]; then
211+
python_exe="$(determine_default_python_exe)"
212+
if [[ -z "${python_exe}" ]]; then
197213
die "No valid Python interpreter found. ${requirement_str} Please check that a valid interpreter is installed and on your \$PATH."
198214
fi
199215
fi
200-
local python_exe
201-
python_exe="$(get_exe_path_or_die "${python_bin_name}")" || exit 1
202-
local major_minor_version
203-
major_minor_version="$(get_python_major_minor_version "${python_exe}")"
204-
for valid_version in "${supported_python_versions_int[@]}"; do
205-
if [[ "${major_minor_version}" == "${valid_version}" ]]; then
206-
echo "${python_exe}" && return 0
207-
fi
208-
done
209-
die "Invalid Python interpreter version for ${python_exe}. ${requirement_str}"
216+
echo "${python_exe}"
210217
}
211218

212219
function compute_sha256 {

0 commit comments

Comments
 (0)