forked from HariSekhon/DevOps-Bash-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.sh
More file actions
71 lines (61 loc) · 2.19 KB
/
Copy pathpython.sh
File metadata and controls
71 lines (61 loc) · 2.19 KB
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
#!/usr/bin/env bash
# shellcheck disable=SC2230
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: circa 2006 (forked from .bashrc)
#
# https://github.com/harisekhon/bash-tools
#
# 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
#
# https://www.linkedin.com/in/harisekhon
#
# ============================================================================ #
# P y t h o n
# ============================================================================ #
bash_tools="${bash_tools:-$(dirname "${BASH_SOURCE[0]}")/..}"
# shellcheck disable=SC1090
. "$bash_tools/.bash.d/os_detection.sh"
# silence those annoying Python 2 cryptography warnings that mess up our programs outputs
export PYTHONWARNINGS=ignore::UserWarning
if ! type add_PATHS &>/dev/null ; then
# shellcheck disable=SC1090
. "$bash_tools/.bash.d/paths.sh"
fi
# see the effect of inserting a path like so
# PYTHONPATH=/path/to/blah pythonpath
pythonpath(){
python -c 'from __future__ import print_function; import sys; [print(_) for _ in sys.path if _]'
}
# enable this to avoid creating .pyc files (sometimes they trip you up executing outdated python code)
# export PYTHONDONTWRITEBYTECODE=1
if isMac; then
# try to find pip in brew installed Python versions since it is
# not in /System/Library/Frameworks/Python.framework/Versions/2.7/bin
for dir in /usr/local/Cellar/python*; do
if [ -d "$dir" ]; then
add_PATH "$dir/bin"
fi
done
fi
if [ -d ~/Library/Python ]; then
for x in ~/Library/Python/*/bin; do
[ -d "$x" ] || continue
add_PATH "$x"
done
fi
alias lspythonbin='ls -d ~/Library/Python/*/bin/* 2>/dev/null'
alias llpythonbin='ls -ld ~/Library/Python/*/bin/* 2>/dev/null'
alias lspybin=lspythonbin
alias llpybin=llpythonbin
# RHEL8 has split python2 / python3 and removed default 'python' :-(
if ! type -P python &>/dev/null; then
if type -P python2 &>/dev/null; then
python(){ python2 "$@"; }
elif type -P python3 &>/dev/null; then
python(){ python3 "$@"; }
fi
fi