You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.6 KiB
Bash
63 lines
1.6 KiB
Bash
5 years ago
|
#!/usr/bin/env bash
|
||
|
# shellcheck disable=SC2230
|
||
|
# vim:ts=4:sts=4:sw=4:et
|
||
|
#
|
||
|
# Author: Hari Sekhon
|
||
|
# Date: 2019-09-27 17:54:37 +0100 (Fri, 27 Sep 2019)
|
||
|
#
|
||
2 years ago
|
# https://github.com/HariSekhon/DevOps-Bash-tools
|
||
5 years ago
|
#
|
||
|
# License: see accompanying Hari Sekhon LICENSE file
|
||
|
#
|
||
|
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
|
||
|
#
|
||
2 years ago
|
# https://www.linkedin.com/in/HariSekhon
|
||
5 years ago
|
#
|
||
|
|
||
|
# Shows the path to Python libraries given as arguments
|
||
|
#
|
||
5 years ago
|
# There is a better version of this in the adjacent DevOps Python Tools repo called python_find_library_path.py
|
||
5 years ago
|
|
||
|
set -euo pipefail
|
||
|
[ -n "${DEBUG:-}" ] && set -x
|
||
|
|
||
|
python="${PYTHON:-python}"
|
||
1 year ago
|
python="$(type -P "$python" || die "'$python' not found")"
|
||
5 years ago
|
|
||
5 years ago
|
find_python_sys_path(){
|
||
|
cat <<EOF |
|
||
|
from __future__ import print_function
|
||
5 years ago
|
# more likely to be right than \$USER
|
||
|
import getpass
|
||
5 years ago
|
import os
|
||
5 years ago
|
import sys
|
||
5 years ago
|
user = getpass.getuser()
|
||
5 years ago
|
for path in sys.path:
|
||
5 years ago
|
# don't return local /Users/\$USER/Library/Python/2.7/lib/python/site-packages
|
||
|
# as that is not the source of sys
|
||
5 years ago
|
if user in path:
|
||
|
continue
|
||
5 years ago
|
if 'Python.framework' in path:
|
||
|
path = path.rsplit('{}lib{}'.format(os.sep, os.sep))[0]
|
||
|
print(path)
|
||
|
break
|
||
|
elif path.endswith('/site-packages'):
|
||
5 years ago
|
print(path)
|
||
|
break
|
||
|
EOF
|
||
5 years ago
|
"$python" #|
|
||
|
#sed 's,/python/*[[:digit:].]*/site-packages,,'
|
||
5 years ago
|
}
|
||
|
|
||
|
if [ $# -eq 0 ]; then
|
||
|
find_python_sys_path
|
||
|
fi
|
||
|
|
||
5 years ago
|
for arg; do
|
||
5 years ago
|
if [ "$arg" = "sys" ]; then
|
||
|
find_python_sys_path
|
||
|
else
|
||
|
"$python" -c "from __future__ import print_function; import $arg; print($arg.__file__)"
|
||
|
fi
|
||
5 years ago
|
done
|