summaryrefslogtreecommitdiff
path: root/tools/perf/tests/shell/lib/setup_python.sh
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2026-09-25 23:19:39 -0700
committerArnaldo Carvalho de Melo <acme@redhat.com>2026-09-26 20:49:28 +0200
commit1331150d7d68f447fce2e209f316a1f83c5fe9f7 (patch)
treedba4a937e6ada9d76b2d0530e657c4ff99bb4599 /tools/perf/tests/shell/lib/setup_python.sh
parentdb5a60750133d1789c1254fcae55dbf542ef0aa6 (diff)
downloadlinux-next-1331150d7d68f447fce2e209f316a1f83c5fe9f7.tar.gz
linux-next-1331150d7d68f447fce2e209f316a1f83c5fe9f7.zip
perf test: Clean up mypy and pylint issues in shell test libraries
Clean up mypy type errors and pylint errors/warnings in tools/perf/tests/shell/lib/ (attr.py, perf_json_output_lint.py, and perf_metric_validation.py): - Fix E0606 (possibly-used-before-assignment) in perf_metric_validation.py by importing sys at module level. - Add type annotations for stack, second_results, collectlist, get_bounds(), and main() in perf_metric_validation.py. - Avoid assigning -1 to list[int] expected_items in perf_json_output_lint.py, rename shadowing variables, and remove redundant lambdas. - Remove unnecessary semicolons, use lazy logging arguments, specify exception types and file encodings, and initialize module-level logger in attr.py. Also update tools/perf/tests/shell/lib/setup_python.sh to: - Avoid x-prefix string comparisons. - Export PYTHON and resolve PYTHONPATH and PERF_EXEC_PATH from BASH_SOURCE[0], ../../../python (for nested test directories such as coresight/), and the directory containing the perf binary so out-of-tree builds and standalone perf python scripts work seamlessly. Assisted-by: Antigravity:gemini-3.1-pro Signed-off-by: Ian Rogers <irogers@google.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/tests/shell/lib/setup_python.sh')
-rw-r--r--tools/perf/tests/shell/lib/setup_python.sh29
1 files changed, 25 insertions, 4 deletions
diff --git a/tools/perf/tests/shell/lib/setup_python.sh b/tools/perf/tests/shell/lib/setup_python.sh
index 2173215a0517..758834f8dcf8 100644
--- a/tools/perf/tests/shell/lib/setup_python.sh
+++ b/tools/perf/tests/shell/lib/setup_python.sh
@@ -1,29 +1,50 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
-if [ "x$PYTHON" = "x" ]
+if [ -z "$PYTHON" ]
then
python3 --version >/dev/null 2>&1 && PYTHON=python3
fi
-if [ "x$PYTHON" = "x" ]
+if [ -z "$PYTHON" ]
then
python --version >/dev/null 2>&1 && PYTHON=python
fi
-if [ "x$PYTHON" = "x" ]
+if [ -z "$PYTHON" ]
then
echo Skipping test, python not detected please set environment variable PYTHON.
exit 2
fi
+export PYTHON
-# Set PYTHONPATH to find the in-tree built perf.so first, avoiding system-wide perf.so
+# Set PYTHONPATH to find the built perf.so and standalone scripts first,
+# avoiding system-wide perf.so
if [ -n "$PERF_EXEC_PATH" ] && [ -d "$PERF_EXEC_PATH/python" ]; then
PYTHONPATH_DIR="$PERF_EXEC_PATH/python"
+elif [ -n "${BASH_SOURCE[0]}" ] && [ -d "$(dirname "${BASH_SOURCE[0]}")/../../../python" ]; then
+ PYTHONPATH_DIR="$(dirname "${BASH_SOURCE[0]}")/../../../python"
+elif [ -d "$(dirname "$0")/../../../python" ]; then
+ PYTHONPATH_DIR="$(dirname "$0")/../../../python"
elif [ -d "$(dirname "$0")/../../python" ]; then
PYTHONPATH_DIR="$(dirname "$0")/../../python"
elif [ -d "$(dirname "$0")/../python" ]; then
PYTHONPATH_DIR="$(dirname "$0")/../python"
fi
+if [ -n "${BASH_SOURCE[0]}" ] && [ -d "$(dirname "${BASH_SOURCE[0]}")/../../../python" ]; then
+ SRC_PYTHON_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../../python" && pwd)"
+ export PYTHONPATH="$SRC_PYTHON_DIR${PYTHONPATH:+:$PYTHONPATH}"
+ if [ -z "$PERF_EXEC_PATH" ] || [ ! -f "$PERF_EXEC_PATH/python/perf_live.py" ]; then
+ PERF_EXEC_PATH="$(dirname "$SRC_PYTHON_DIR")"
+ export PERF_EXEC_PATH
+ fi
+fi
+
if [ -n "$PYTHONPATH_DIR" ]; then
export PYTHONPATH="$PYTHONPATH_DIR${PYTHONPATH:+:$PYTHONPATH}"
fi
+
+PERF_BIN=$(which perf 2>/dev/null || true)
+if [ -n "$PERF_BIN" ] && [ -d "$(dirname "$PERF_BIN")/python" ]; then
+ PERF_BIN_PYTHON="$(dirname "$PERF_BIN")/python"
+ export PYTHONPATH="$PERF_BIN_PYTHON${PYTHONPATH:+:$PYTHONPATH}"
+fi