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
This commit is contained in:
Alexey Katsman
2026-08-14 09:15:05 +00:00
committed by intellij-monorepo-bot
parent 2c2c805f8d
commit bc06d18dc3
@@ -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)