Skip to content

Commit

Permalink
Merge pull request #519 from matthew-brett/python-on-macos
Browse files Browse the repository at this point in the history
Try PYTHON_EXE and python3 if no python
  • Loading branch information
mattip authored Dec 8, 2023
2 parents 14c305a + e64bc44 commit 0714f52
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions common_utils.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# Utilities for both OSX and Docker Linux
# Python should be on the PATH
# python or python3 should be on the PATH

# Only source common_utils once
if [ -n "$COMMON_UTILS_SOURCED" ]; then
Expand Down Expand Up @@ -78,20 +78,31 @@ function stop_spinner {
>&2 echo "Building libraries finished."
}

function any_python {
for cmd in $PYTHON_EXE python3 python; do
if [ -n "$(type -t $cmd)" ]; then
echo $cmd
return
fi
done
echo "Could not find python or python3"
exit 1
}

function abspath {
# Can work with any Python; need not be our installed Python.
python -c "import os.path; print(os.path.abspath('$1'))"
$(any_python) -c "import os.path; print(os.path.abspath('$1'))"
}

function relpath {
# Path of first input relative to second (or $PWD if not specified)
# Can work with any Python; need not be our installed Python.
python -c "import os.path; print(os.path.relpath('$1','${2:-$PWD}'))"
$(any_python) -c "import os.path; print(os.path.relpath('$1','${2:-$PWD}'))"
}

function realpath {
# Can work with any Python; need not be our installed Python.
python -c "import os; print(os.path.realpath('$1'))"
$(any_python) -c "import os; print(os.path.realpath('$1'))"
}

function lex_ver {
Expand Down Expand Up @@ -405,13 +416,13 @@ function pip_opts {
function get_os {
# Report OS as given by uname
# Use any Python that comes to hand.
python -c 'import platform; print(platform.uname()[0])'
$(any_python) -c 'import platform; print(platform.uname()[0])'
}

function get_platform {
# Report platform as given by uname
# Use any Python that comes to hand.
python -c 'import platform; print(platform.uname()[4])'
$(any_python) -c 'import platform; print(platform.uname()[4])'
}

if [ "$(get_platform)" == x86_64 ] || \
Expand Down

0 comments on commit 0714f52

Please sign in to comment.