Check if python is available while checking for git, rustc and cargo (#376)

This commit is contained in:
fmoko 2020-04-30 09:21:17 +02:00 committed by GitHub
commit 071b51d588
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,6 +30,22 @@ else
exit 1 exit 1
fi fi
# Look up python installations, starting with 3 with a fallback of 2
if [ -x "$(command -v python3)" ]
then
PY="$(command -v python3)"
elif [ -x "$(command -v python)" ]
then
PY="$(command -v python)"
elif [ -x "$(command -v python2)" ]
then
PY="$(command -v python2)"
else
echo "ERROR: No working python installation was found"
echo "Please install python and add it to the PATH variable"
exit 1
fi
# Function that compares two versions strings v1 and v2 given in arguments (e.g 1.31 and 1.33.0). # Function that compares two versions strings v1 and v2 given in arguments (e.g 1.31 and 1.33.0).
# Returns 1 if v1 > v2, 0 if v1 == v2, 2 if v1 < v2. # Returns 1 if v1 > v2, 0 if v1 == v2, 2 if v1 < v2.
function vercomp() { function vercomp() {
@ -86,7 +102,7 @@ Path=${1:-rustlings/}
echo "Cloning Rustlings at $Path..." echo "Cloning Rustlings at $Path..."
git clone -q https://github.com/rust-lang/rustlings $Path git clone -q https://github.com/rust-lang/rustlings $Path
Version=$(curl -s https://api.github.com/repos/rust-lang/rustlings/releases/latest | python -c "import json,sys;obj=json.load(sys.stdin);print(obj['tag_name']);") Version=$(curl -s https://api.github.com/repos/rust-lang/rustlings/releases/latest | ${PY} -c "import json,sys;obj=json.load(sys.stdin);print(obj['tag_name']);")
CargoBin="${CARGO_HOME:-$HOME/.cargo}/bin" CargoBin="${CARGO_HOME:-$HOME/.cargo}/bin"
echo "Checking out version $Version..." echo "Checking out version $Version..."