]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-132038: Make perf version check in test_perf_profiler more robust (#132039)
authorItamar Oren <itamarost@gmail.com>
Thu, 3 Apr 2025 17:37:08 +0000 (10:37 -0700)
committerGitHub <noreply@github.com>
Thu, 3 Apr 2025 17:37:08 +0000 (18:37 +0100)
Should work also if the version string includes a commit hash, like `perf version 6.12.9.g242e6068fd5c`

Lib/test/test_perf_profiler.py

index 43e5a7e114b317f503ca63791bc3180c6bc70305..1922d8e0bab2165022d0f9382e17f42da714c67f 100644 (file)
@@ -493,7 +493,8 @@ class TestPerfProfiler(unittest.TestCase, TestPerfProfilerMixin):
 
 def _is_perf_version_at_least(major, minor):
     # The output of perf --version looks like "perf version 6.7-3" but
-    # it can also be perf version "perf version 5.15.143"
+    # it can also be perf version "perf version 5.15.143", or even include
+    # a commit hash in the version string, like "6.12.9.g242e6068fd5c"
     try:
         output = subprocess.check_output(["perf", "--version"], text=True)
     except (subprocess.CalledProcessError, FileNotFoundError):
@@ -501,7 +502,7 @@ def _is_perf_version_at_least(major, minor):
     version = output.split()[2]
     version = version.split("-")[0]
     version = version.split(".")
-    version = tuple(map(int, version))
+    version = tuple(map(int, version[:2]))
     return version >= (major, minor)