2
2
3
3
set -e
4
4
5
- PYTHON=${1:- " /usr/local/python/bin/python3" }
6
- USERNAME=${2-" automatic" }
5
+ PYTHON=${1:- " /usr/local/python/bin/python3" } # "/usr/local/bin/python" or "/usr/local/python/bin/python3"
6
+ PYTHON_INSTALL_PATH=${2:- " /usr/local/python" } # "/usr/local/" or "/usr/local/python"
7
+ USERNAME=${3-" automatic" }
8
+ INSTALL_PIPX_TOOLS=${4:- " true" }
9
+ export PIPX_HOME=${5:- " /usr/local/pipx" } # "/usr/local/py-utils" "/usr/local/share/pipx"
10
+ UPDATE_RC=${6:- " true" }
11
+
12
+ DEFAULT_UTILS=(
13
+ " autopep8"
14
+ " bandit"
15
+ # "black"
16
+ " flake8"
17
+ # "isort"
18
+ " mypy"
19
+ " pycodestyle"
20
+ " pydocstyle"
21
+ " pylint"
22
+ " pytest"
23
+ " twine"
24
+ " yapf"
25
+ )
7
26
8
27
if [ " ${USERNAME} " = " automatic" ]; then
9
28
USERNAME=" "
@@ -39,6 +58,16 @@ function sudoUserIf() {
39
58
fi
40
59
}
41
60
61
+ updaterc () {
62
+ if [ " ${UPDATE_RC} " = " true" ]; then
63
+ if [[ " $( cat /etc/bash.bashrc) " != * " $1 " * ]]; then
64
+ echo -e " $1 " >> /etc/bash.bashrc
65
+ fi
66
+ fi
67
+ }
68
+
69
+ export DEBIAN_FRONTEND=noninteractive
70
+
42
71
if ! ${PYTHON} --version > /dev/null; then
43
72
echo " You need to install Python before installing packages"
44
73
exit 1
@@ -48,3 +77,44 @@ installPythonPackage "pip" "latest"
48
77
installPythonPackage " setuptools" " latest"
49
78
installPythonPackage " art" " latest"
50
79
installPythonPackage " nox" " latest"
80
+
81
+ if [ " ${INSTALL_PIPX_TOOLS} " != " true" ]; then
82
+ exit 0
83
+ fi
84
+
85
+ export PIPX_BIN_DIR=" ${PIPX_HOME} /bin"
86
+ export PATH=" ${PYTHON_INSTALL_PATH} /bin:${PIPX_BIN_DIR} :${PATH} "
87
+
88
+ if ! grep -e ' ^pipx:' < /etc/group > /dev/null 2>&1 ; then
89
+ groupadd --system pipx
90
+ fi
91
+ usermod --append --groups pipx ${USERNAME}
92
+ umask 0002
93
+ mkdir --parents ${PIPX_BIN_DIR}
94
+ chown :pipx ${PIPX_HOME} ${PIPX_BIN_DIR}
95
+ chmod g+s ${PIPX_HOME} ${PIPX_BIN_DIR}
96
+
97
+ export PYTHONUSERBASE=/tmp/pip-tmp
98
+ export PIP_CACHE_DIR=/tmp/pip-tmp/cache
99
+ pipx_path=" "
100
+ if ! type pipx > /dev/null 2>&1 ; then
101
+ pip3 install --disable-pip-version-check --no-cache-dir --user pipx 2>&1
102
+ /tmp/pip-tmp/bin/pipx install --pip-args=--no-cache-dir pipx
103
+ pipx_path=$PYTHONUSERBASE " /bin/"
104
+ fi
105
+ for util in " ${DEFAULT_UTILS[@]} " ; do
106
+ if ! type ${util} > /dev/null 2>&1 ; then
107
+ ${pipx_path} pipx install --system-site-packages --pip-args ' --no-cache-dir --force-reinstall' ${util}
108
+ else
109
+ echo " ${util} already installed. Skipping."
110
+ fi
111
+ done
112
+ rm -rf /tmp/pip-tmp
113
+
114
+ updaterc " $(
115
+ cat << EOF
116
+ export PIPX_HOME="${PIPX_HOME} "
117
+ export PIPX_BIN_DIR="${PIPX_BIN_DIR} "
118
+ if [[ "\$ {PATH}" != *"\$ {PIPX_BIN_DIR}"* ]]; then export PATH="\$ {PATH}:\$ {PIPX_BIN_DIR}"; fi
119
+ EOF
120
+ ) "
0 commit comments