Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#12660] fix(mcp-server): Invoke isort/black console scripts and pin their versions (#12661)

Qi Yu3604c670b27d
diff --git a/mcp-server/build.gradle.kts b/mcp-server/build.gradle.kts
index fe773fcf62..9bc51ad8e6 100644
--- a/mcp-server/build.gradle.kts
+++ b/mcp-server/build.gradle.kts
@@ -39,13 +39,21 @@ fun getUvExecutable(): String {
}
}
-val venvPython = when {
+// The formatters are invoked through their console scripts rather than `python -m <tool>`:
+// isort 9 no longer ships an `__main__` module, so `python -m isort` cannot be executed.
+fun venvExecutable(name: String): String = when {
System.getProperty("os.name").contains("win", ignoreCase = true) ->
- venvDir.resolve("Scripts/python.exe").absolutePath
+ venvDir.resolve("Scripts/$name.exe").absolutePath
else ->
- venvDir.resolve("bin/python").absolutePath
+ venvDir.resolve("bin/$name").absolutePath
}
+val venvPython = venvExecutable("python")
+
+// Pinned so that a new formatter release cannot change the outcome of the format check in CI.
+val blackRequirement = "black==26.5.1"
+val isortRequirement = "isort==9.0.0"
+
tasks {
register<Exec>("installUv") {
group = "python"
@@ -160,7 +168,7 @@ tasks {
workingDir(pythonProjectDir)
doFirst {
- commandLine(getUvExecutable(), "pip", "install", "--python", venvPython, "black", "isort")
+ commandLine(getUvExecutable(), "pip", "install", "--python", venvPython, blackRequirement, isortRequirement)
}
doLast {
@@ -213,13 +221,13 @@ tasks {
// Apply isort
exec {
workingDir = pythonProjectDir
- commandLine(venvPython, "-m", "isort", "mcp_server", "tests")
+ commandLine(venvExecutable("isort"), "mcp_server", "tests")
}
// Apply Black
exec {
workingDir = pythonProjectDir
- commandLine(venvPython, "-m", "black", "mcp_server", "tests")
+ commandLine(venvExecutable("black"), "mcp_server", "tests")
}
logger.lifecycle("Python formatting applied (isort + Black)")
@@ -234,8 +242,10 @@ tasks {
doLast {
val isortExitCode = exec {
workingDir = pythonProjectDir
- commandLine(venvPython, "-m", "isort", "--check", "mcp_server", "tests")
- isIgnoreExitValue = false
+ commandLine(venvExecutable("isort"), "--check", "mcp_server", "tests")
+ // Let the exit code reach the check below, so the failure is reported with the message
+ // that names the tool instead of a bare Gradle ExecException.
+ isIgnoreExitValue = true
}.exitValue
if (isortExitCode != 0) {
@@ -244,8 +254,10 @@ tasks {
val blackExitCode = exec {
workingDir = pythonProjectDir
- commandLine(venvPython, "-m", "black", "--check", "mcp_server", "tests")
- isIgnoreExitValue = false
+ commandLine(venvExecutable("black"), "--check", "mcp_server", "tests")
+ // Let the exit code reach the check below, so the failure is reported with the message
+ // that names the tool instead of a bare Gradle ExecException.
+ isIgnoreExitValue = true
}.exitValue
if (blackExitCode != 0) {