Skip to content

Commit cd75e9b

Browse files
authored
Convert to using python binary directly instead of alternatives (#42)
* Fix: Remove debug statements, change single bracket to double bracket * Fix: Add missing bits from previous merge * Fix: Remove alternatives, changing branches was a pain * Fix: Replace python3 with python executable
1 parent b2c3629 commit cd75e9b

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

pyperf/pyperf_run

+34-30
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
PATH="${PATH}:/usr/local/bin"
1919
export PATH
2020
python_pkgs=""
21-
python_exec=""
21+
python_exec="python3"
22+
install_pip=0
2223
PYTHON_VERSION=""
2324
PYPERF_VERSION="1.11.0"
2425
#
@@ -132,12 +133,23 @@ generate_csv_file()
132133

133134
pip3_install()
134135
{
135-
if [ $to_no_pkg_install -eq 0 ]; then
136-
pip3 -q install $1
137-
if [ $? -ne 0 ]; then
138-
exit_out "pip3 install of $1 failed." 1
136+
if [ $to_no_pkg_install -eq 1 ]; then
137+
return
138+
fi
139+
140+
$python_exec -m pip --version
141+
if [[ $? -ne 0 ]]; then
142+
if [[ $install_pip -eq 1 ]]; then
143+
$python_exec -m ensurepip || exit_out "Failed to install pip." 1
144+
else
145+
exit_out "Pip is not available, exiting out" 1
139146
fi
140147
fi
148+
149+
$python_exec -m pip install -q $1
150+
if [[ $? -ne 0 ]]; then
151+
exit_out "Pip not available for install of $1 failed." 1
152+
fi
141153
}
142154
#
143155
# Variables set by general setup.
@@ -222,11 +234,12 @@ source test_tools/general_setup "$@"
222234
ARGUMENT_LIST=(
223235
"pyperf_version"
224236
"python_exec"
225-
"python_pkgs"
237+
"python_pkgs"
226238
)
227239

228240
NO_ARGUMENTS=(
229-
"usage"
241+
"usage"
242+
"install_pip"
230243
)
231244

232245
# read arguments
@@ -254,6 +267,10 @@ while [[ $# -gt 0 ]]; do
254267
python_pkgs=$2
255268
shift 2
256269
;;
270+
--install_pip)
271+
install_pip=1
272+
shift 1
273+
;;
257274
--usage)
258275
usage $0
259276
;;
@@ -271,27 +288,15 @@ while [[ $# -gt 0 ]]; do
271288
done
272289

273290
if [ $to_pbench -eq 0 ]; then
274-
rm -rf pyperformance
275-
PYTHON_VERSION=$(python3 --version | awk '{ print $2 }')
276-
python3 -m pip install pyperformance==$PYPERF_VERSION
277-
if [ $? -ne 0 ]; then
278-
exit_out "python3 -m pip install pyperformance==$PYPERF_VERSION: failed" 1
279-
fi
280-
cd pyperformance
291+
PYTHON_VERSION=$($python_exec --version | awk '{ print $2 }')
281292
if [[ ${python_pkgs} != "" ]]; then
282293
pkg_list=`echo $python_pkgs | sed "s/,/ /g"`
283294
test_tools/package_install --packages "$python_pkgs" --no_packages $to_no_pkg_install
284295
fi
285-
if [[ $python_exec != "" ]]; then
286-
if [[ ! -f $python_exec ]]; then
287-
exit_out "Error: Designated python executable, $python_exec, not present"
288-
fi
289-
#
290-
# Remove the existing (if any) default python.
291-
#
292-
alternatives --remove-all python
293-
alternatives --install /usr/bin/python python $python_exec 1
296+
if ! command -v $python_exec; then
297+
exit_out "Error: Designated python executable, $python_exec, not present"
294298
fi
299+
pip3_install "pyperformance==$PYPERF_VERSION"
295300
pip3_install psutil
296301
pip3_install packaging
297302
pip3_install pyparsing
@@ -303,16 +308,15 @@ if [ $to_pbench -eq 0 ]; then
303308
mkdir python_results
304309

305310
pyresults=python_results/pyperf_out_$(date "+%Y.%m.%d-%H.%M.%S")
306-
pwd > /tmp/dave_debug
307-
echo python3 -m pyperformance run --output ${pyresults}.json >> /tmp/dave_debug
308-
python3 -m pyperformance run --output ${pyresults}.json
311+
312+
$python_exec -m pyperformance run --output ${pyresults}.json
309313
if [ $? -ne 0 ]; then
310-
exit_out "Failed: python3 -m pyperformance run --output ${pyresults}.json" 1
314+
exit_out "Failed: $python_exec -m pyperformance run --output ${pyresults}.json" 1
311315
fi
312-
echo python3 -m pyperf dump ${pyresults}.json >> /tmp/dave_debug
313-
python3 -m pyperf dump ${pyresults}.json > ${pyresults}.results
316+
317+
$python_exec -m pyperf dump ${pyresults}.json > ${pyresults}.results
314318
if [ $? -ne 0 ]; then
315-
echo "Failed: python3 -m pyperf dump ${pyresults}.json > ${pyresults}.results" 1
319+
echo "Failed: $python_exec -m pyperf dump ${pyresults}.json > ${pyresults}.results" 1
316320
echo Failed > test_results_report
317321
else
318322
echo Ran > test_results_report

0 commit comments

Comments
 (0)