From bc06d18dc342f8fe66a0f19bcc3c90591f988433 Mon Sep 17 00:00:00 2001 From: Alexey Katsman Date: Wed, 12 Aug 2026 15:08:08 +0200 Subject: [PATCH] PY-91384 Don't probe /usr/bin/python3 without the command line tools /usr/bin/python3 on macOS is an xcrun stub rather than an interpreter. Executing it while the Xcode Command Line Tools are absent makes macOS raise its own "command line developer tools" installer dialog - at startup, and again on every detection refresh roughly ten minutes apart. /usr/bin is therefore scanned only when MacPythonSdkFlavor reports the tools are installed, matching what the legacy flavor path behind the python.use.system.legacy.provider registry key already did. (cherry picked from commit f0b3f35c21d0d6d2162482f8c9953a647bd65a16) IJ-MR-218249 GitOrigin-RevId: e2f664b69314418462923da6296b39cf67e4bba0 --- .../impl/providers/MacSystemPythonProvider.kt | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/python/services/system-python/src/com/intellij/python/community/services/systemPython/impl/providers/MacSystemPythonProvider.kt b/python/services/system-python/src/com/intellij/python/community/services/systemPython/impl/providers/MacSystemPythonProvider.kt index 15e67c838cdf..f1ee51e49423 100644 --- a/python/services/system-python/src/com/intellij/python/community/services/systemPython/impl/providers/MacSystemPythonProvider.kt +++ b/python/services/system-python/src/com/intellij/python/community/services/systemPython/impl/providers/MacSystemPythonProvider.kt @@ -7,6 +7,7 @@ import com.intellij.python.community.services.systemPython.SystemPythonProvider import com.jetbrains.python.PyToolUIInfo import com.jetbrains.python.PythonBinary import com.jetbrains.python.errorProcessing.PyResult +import com.jetbrains.python.sdk.flavors.MacPythonSdkFlavor import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import java.nio.file.Path @@ -15,11 +16,14 @@ import java.nio.file.Path internal class MacSystemPythonProvider : SystemPythonProvider { private val directories = listOf( - Path.of("/usr/bin"), Path.of("/usr/local/bin"), - Path.of("/usr/local/Cellar/python"), - Path.of("/Library/Frameworks/Python.framework/Versions"), - Path.of("/System/Library/Frameworks/Python.framework/Versions"), + Path.of("/usr/local/Cellar/python/bin"), + Path.of("/Library/Frameworks/Python.framework/Versions/bin"), + Path.of("/System/Library/Frameworks/Python.framework/Versions/bin"), + ) + + private val xcodePythonDirectories = listOf( + Path.of("/usr/bin"), ) // Patterns to match Python executable filenames @@ -35,8 +39,15 @@ internal class MacSystemPythonProvider : SystemPythonProvider { return PyResult.success(emptySet()) } + val directoriesToSearch = buildList { + addAll(directories) + if (MacPythonSdkFlavor.areCommandLineDeveloperToolsAvailable()) { + addAll(xcodePythonDirectories) + } + } + val pythons = withContext(Dispatchers.IO) { - return@withContext collectPythonsInPaths(directories, names) + return@withContext collectPythonsInPaths(directoriesToSearch, names) } return PyResult.success(pythons)