From 2b3812da08b5b566ec519811e4e655c7bd54e8cb Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Thu, 18 Jun 2026 16:55:22 +0200 Subject: [PATCH] cleanup [python]: rename `Tool` to `PyProjectManager` (cherry picked from commit fc0c4714d6431c915d4197969e1eda97b57a0cf6) GitOrigin-RevId: 3c9781741f0eb0125ece7097a2f9e2cf53241063 --- .../resources/intellij.python.hatch.xml | 2 +- ...{HatchTool.kt => HatchPyProjectManager.kt} | 4 +- ...j.python.community.impl.poetry.backend.xml | 2 +- ...oetryTool.kt => PoetryPyProjectManager.kt} | 4 +- .../resources/intellij.python.pyproject.xml | 2 +- .../workspaceBridge/workspaceTools.kt | 58 +++++++++---------- .../spi/{Tool.kt => PyProjectManager.kt} | 4 +- .../pyproject/model/spi/package-info.java | 2 +- .../resources/intellij.python.uv.backend.xml | 2 +- .../{UvTool.kt => UvPyProjectManager.kt} | 4 +- 10 files changed, 42 insertions(+), 42 deletions(-) rename python/python-hatch/src/com/intellij/python/hatch/impl/{HatchTool.kt => HatchPyProjectManager.kt} (92%) rename python/python-poetry/backend/src/com/intellij/python/community/impl/poetry/backend/{PoetryTool.kt => PoetryPyProjectManager.kt} (93%) rename python/python-pyproject/src/com/intellij/python/pyproject/model/spi/{Tool.kt => PyProjectManager.kt} (91%) rename python/python-uv/backend/src/com/intellij/python/uv/backend/{UvTool.kt => UvPyProjectManager.kt} (98%) diff --git a/python/python-hatch/resources/intellij.python.hatch.xml b/python/python-hatch/resources/intellij.python.hatch.xml index 5455062d8a77..37cb8eb22c15 100644 --- a/python/python-hatch/resources/intellij.python.hatch.xml +++ b/python/python-hatch/resources/intellij.python.hatch.xml @@ -19,7 +19,7 @@ implementation="com.intellij.python.hatch.sdk.evolution.HatchSelectSdkProvider"/> - + diff --git a/python/python-hatch/src/com/intellij/python/hatch/impl/HatchTool.kt b/python/python-hatch/src/com/intellij/python/hatch/impl/HatchPyProjectManager.kt similarity index 92% rename from python/python-hatch/src/com/intellij/python/hatch/impl/HatchTool.kt rename to python/python-hatch/src/com/intellij/python/hatch/impl/HatchPyProjectManager.kt index d078e9c2d5d3..5a425a327a10 100644 --- a/python/python-hatch/src/com/intellij/python/hatch/impl/HatchTool.kt +++ b/python/python-hatch/src/com/intellij/python/hatch/impl/HatchPyProjectManager.kt @@ -8,7 +8,7 @@ import com.intellij.python.pyproject.model.internal.pyProjectToml.TomlDependency import com.intellij.python.pyproject.model.spi.ProjectName import com.intellij.python.pyproject.model.spi.ProjectStructureInfo import com.intellij.python.pyproject.model.spi.PyProjectTomlProject -import com.intellij.python.pyproject.model.spi.Tool +import com.intellij.python.pyproject.model.spi.PyProjectManager import com.jetbrains.python.PyToolUIInfo import com.jetbrains.python.venvReader.Directory import org.apache.tuweni.toml.TomlTable @@ -18,7 +18,7 @@ import org.jetbrains.annotations.ApiStatus val HATCH_TOOL_ID: ToolId = ToolId("hatch") val HATCH_UI_INFO: PyToolUIInfo = PyToolUIInfo("Hatch", PythonHatchIcons.Logo) -internal class HatchTool : Tool { +internal class HatchPyProjectManager : PyProjectManager { override val id: ToolId = HATCH_TOOL_ID override val ui: PyToolUIInfo = HATCH_UI_INFO diff --git a/python/python-poetry/backend/resources/intellij.python.community.impl.poetry.backend.xml b/python/python-poetry/backend/resources/intellij.python.community.impl.poetry.backend.xml index 195c8cf8d685..501bf25cb069 100644 --- a/python/python-poetry/backend/resources/intellij.python.community.impl.poetry.backend.xml +++ b/python/python-poetry/backend/resources/intellij.python.community.impl.poetry.backend.xml @@ -9,6 +9,6 @@ - + \ No newline at end of file diff --git a/python/python-poetry/backend/src/com/intellij/python/community/impl/poetry/backend/PoetryTool.kt b/python/python-poetry/backend/src/com/intellij/python/community/impl/poetry/backend/PoetryPyProjectManager.kt similarity index 93% rename from python/python-poetry/backend/src/com/intellij/python/community/impl/poetry/backend/PoetryTool.kt rename to python/python-poetry/backend/src/com/intellij/python/community/impl/poetry/backend/PoetryPyProjectManager.kt index 450f872ce4af..82487b06a9e4 100644 --- a/python/python-poetry/backend/src/com/intellij/python/community/impl/poetry/backend/PoetryTool.kt +++ b/python/python-poetry/backend/src/com/intellij/python/community/impl/poetry/backend/PoetryPyProjectManager.kt @@ -10,12 +10,12 @@ import com.intellij.python.pyproject.model.internal.pyProjectToml.TomlDependency import com.intellij.python.pyproject.model.spi.ProjectName import com.intellij.python.pyproject.model.spi.ProjectStructureInfo import com.intellij.python.pyproject.model.spi.PyProjectTomlProject -import com.intellij.python.pyproject.model.spi.Tool +import com.intellij.python.pyproject.model.spi.PyProjectManager import com.jetbrains.python.PyToolUIInfo import com.jetbrains.python.venvReader.Directory import org.apache.tuweni.toml.TomlTable -internal class PoetryTool : Tool { +internal class PoetryPyProjectManager : PyProjectManager { override val id: ToolId = POETRY_TOOL_ID override val ui: PyToolUIInfo = POETRY_UI_INFO diff --git a/python/python-pyproject/resources/intellij.python.pyproject.xml b/python/python-pyproject/resources/intellij.python.pyproject.xml index 58da3803d14d..dd032acb7e81 100644 --- a/python/python-pyproject/resources/intellij.python.pyproject.xml +++ b/python/python-pyproject/resources/intellij.python.pyproject.xml @@ -33,7 +33,7 @@ - diff --git a/python/python-pyproject/src/com/intellij/python/pyproject/model/internal/workspaceBridge/workspaceTools.kt b/python/python-pyproject/src/com/intellij/python/pyproject/model/internal/workspaceBridge/workspaceTools.kt index a78cdd50800c..128ae210d2aa 100644 --- a/python/python-pyproject/src/com/intellij/python/pyproject/model/internal/workspaceBridge/workspaceTools.kt +++ b/python/python-pyproject/src/com/intellij/python/pyproject/model/internal/workspaceBridge/workspaceTools.kt @@ -39,7 +39,7 @@ import com.intellij.python.pyproject.model.internal.pyProjectToml.FSWalkInfoWith import com.intellij.python.pyproject.model.internal.pyProjectToml.getDependenciesFromToml import com.intellij.python.pyproject.model.spi.ProjectName import com.intellij.python.pyproject.model.spi.PyProjectTomlProject -import com.intellij.python.pyproject.model.spi.Tool +import com.intellij.python.pyproject.model.spi.PyProjectManager import com.intellij.python.pyproject.model.spi.WorkspaceName import com.intellij.python.pyproject.model.spi.plus import com.intellij.workspaceModel.ide.legacyBridge.LegacyBridgeJpsEntitySourceFactory @@ -59,7 +59,7 @@ private val logger = fileLogger() /** Collect all excluded folder paths from the workspace model. */ internal fun collectExcludedPaths(project: Project): Set { return project.workspaceModel.currentSnapshot.entities() - .flatMap { cr -> cr.excludedUrls.asSequence().mapNotNull { it.url.toPath() } } + .flatMap { cr -> cr.excludedUrls.asSequence().map { it.url.toPath() } } .toSet() } @@ -447,10 +447,10 @@ private suspend fun generatePyProjectTomlEntries( existingPythonNames: Map, allModuleNames: Set, ): Set = withContext(Dispatchers.Default) { - val tools = Tool.EP.extensionList - val rawEntries = parseRawEntries(fsInfo, tools) + val pyProjectManagers = PyProjectManager.EP.extensionList + val rawEntries = parseRawEntries(fsInfo, pyProjectManagers) val entries = assignNames(rawEntries, existingPythonNames, allModuleNames) - resolveDependencies(entries, tools) + resolveDependencies(entries, pyProjectManagers) return@withContext entries.toSet() } @@ -465,44 +465,44 @@ private data class RawEntry( ) /** Parse pyproject.toml files into raw entries with natural names (no dedup). */ -private suspend fun parseRawEntries(fsInfo: FSWalkInfoWithToml, tools: List): List { +private suspend fun parseRawEntries(fsInfo: FSWalkInfoWithToml, pyProjectManagers: List): List { val rawEntries = ArrayList() for ((tomlFile, toml) in fsInfo.tomlFiles.entries.sortedBy { it.key }) { - val participatedTools = mutableSetOf() + val participatedManagers = mutableSetOf() val root = tomlFile.parent var projectNameAsString = toml.project?.name if (projectNameAsString == null) { - val toolAndName = tools.getNameFromEP(toml) - if (toolAndName != null) { - projectNameAsString = toolAndName.second - participatedTools.add(toolAndName.first.id) + val managerAndName = pyProjectManagers.getNameFromEP(toml) + if (managerAndName != null) { + projectNameAsString = managerAndName.second + participatedManagers.add(managerAndName.first.id) } } if (projectNameAsString == null) { projectNameAsString = root.name } - val sourceRootsAndTools = tools.flatMap { tool -> tool.getSrcRoots(toml.toml, root).map { Pair(tool, it) } }.toSet() + val sourceRootsAndTools = pyProjectManagers.flatMap { tool -> tool.getSrcRoots(toml.toml, root).map { Pair(tool, it) } }.toSet() val sourceRoots = sourceRootsAndTools.map { it.second }.toSet() + findSrc(root) - participatedTools.addAll(sourceRootsAndTools.map { it.first.id }) - if (participatedTools.isEmpty()) { - for (tool in tools) { + participatedManagers.addAll(sourceRootsAndTools.map { it.first.id }) + if (participatedManagers.isEmpty()) { + for (tool in pyProjectManagers) { if (toml.toml.contains("tool.${tool.id.id}")) { - participatedTools.add(tool.id) + participatedManagers.add(tool.id) } } } - if (participatedTools.isEmpty()) { + if (participatedManagers.isEmpty()) { toml.toml.getString("build-system.build-backend")?.let { buildBackend -> - tools.firstOrNull { it.id.id in buildBackend }?.let { buildTool -> - participatedTools.add(buildTool.id) + pyProjectManagers.firstOrNull { it.id.id in buildBackend }?.let { buildTool -> + participatedManagers.add(buildTool.id) } } } - val relationsWithTools: MutableSet = participatedTools.mapTo(mutableSetOf()) { + val relationsWithTools: MutableSet = participatedManagers.mapTo(mutableSetOf()) { PyProjectTomlToolRelation.SimpleRelation(it) } - rawEntries.add(RawEntry(tomlFile, root, projectNameAsString, participatedTools, toml, sourceRoots, relationsWithTools)) + rawEntries.add(RawEntry(tomlFile, root, projectNameAsString, participatedManagers, toml, sourceRoots, relationsWithTools)) } return rawEntries } @@ -576,25 +576,25 @@ private fun assignNames( } /** Resolve inter-module dependencies and workspace membership from tools. */ -private suspend fun resolveDependencies(entries: List, tools: List) { +private suspend fun resolveDependencies(entries: List, pyProjectManagers: List) { val entriesByName = entries.associateBy { it.name } val namesByDir = entries.associate { Pair(it.root, it.name) } val allNames = entriesByName.keys - var dependencies = getDependenciesFromToml(entriesByName, namesByDir, tools.flatMap { it.getTomlDependencySpecifications() }) - for (tool in tools) { - val toolSpecificInfo = tool.getProjectStructure(entriesByName, namesByDir) + var dependencies = getDependenciesFromToml(entriesByName, namesByDir, pyProjectManagers.flatMap { it.getTomlDependencySpecifications() }) + for (pyProjectManager in pyProjectManagers) { + val toolSpecificInfo = pyProjectManager.getProjectStructure(entriesByName, namesByDir) if (toolSpecificInfo != null) { dependencies += toolSpecificInfo.dependencies for (entityName in toolSpecificInfo.dependencies.map.keys) { val entity = entriesByName[entityName] ?: error("returned broken name $entityName") - entity.relationsWithTools.add(PyProjectTomlToolRelation.SimpleRelation(tool.id)) + entity.relationsWithTools.add(PyProjectTomlToolRelation.SimpleRelation(pyProjectManager.id)) } } val workspaceMembers = toolSpecificInfo?.membersToWorkspace ?: emptyMap() for ((member, workspace) in workspaceMembers) { - entriesByName[member]!!.relationsWithTools.add(PyProjectTomlToolRelation.WorkspaceMember(tool.id, workspace)) - entriesByName[workspace]!!.relationsWithTools.add(PyProjectTomlToolRelation.SimpleRelation(tool.id)) + entriesByName[member]!!.relationsWithTools.add(PyProjectTomlToolRelation.WorkspaceMember(pyProjectManager.id, workspace)) + entriesByName[workspace]!!.relationsWithTools.add(PyProjectTomlToolRelation.SimpleRelation(pyProjectManager.id)) } } for ((name, deps) in dependencies.map) { @@ -605,7 +605,7 @@ private suspend fun resolveDependencies(entries: List.getNameFromEP(projectToml: PyProjectToml): Pair? = +private suspend fun Iterable.getNameFromEP(projectToml: PyProjectToml): Pair? = withContext(Dispatchers.Default) { firstNotNullOfOrNull { tool -> tool.getProjectName(projectToml.toml)?.let { Pair(tool, it) } } } diff --git a/python/python-pyproject/src/com/intellij/python/pyproject/model/spi/Tool.kt b/python/python-pyproject/src/com/intellij/python/pyproject/model/spi/PyProjectManager.kt similarity index 91% rename from python/python-pyproject/src/com/intellij/python/pyproject/model/spi/Tool.kt rename to python/python-pyproject/src/com/intellij/python/pyproject/model/spi/PyProjectManager.kt index 7de88bf62c4c..79dcb836b2e8 100644 --- a/python/python-pyproject/src/com/intellij/python/pyproject/model/spi/Tool.kt +++ b/python/python-pyproject/src/com/intellij/python/pyproject/model/spi/PyProjectManager.kt @@ -8,9 +8,9 @@ import com.jetbrains.python.PyToolUIInfo import com.jetbrains.python.venvReader.Directory import org.apache.tuweni.toml.TomlTable -interface Tool { +interface PyProjectManager { companion object { - internal val EP = ExtensionPointName.create("com.intellij.python.pyproject.model.tool") + internal val EP = ExtensionPointName.create("com.intellij.python.pyproject.model.pyprojectmanager") } val id: ToolId diff --git a/python/python-pyproject/src/com/intellij/python/pyproject/model/spi/package-info.java b/python/python-pyproject/src/com/intellij/python/pyproject/model/spi/package-info.java index 9b46f78f588f..6b61b73a6219 100644 --- a/python/python-pyproject/src/com/intellij/python/pyproject/model/spi/package-info.java +++ b/python/python-pyproject/src/com/intellij/python/pyproject/model/spi/package-info.java @@ -1,5 +1,5 @@ /** - * Implement {@link com.intellij.python.pyproject.model.spi.Tool} and register it + * Implement {@link com.intellij.python.pyproject.model.spi.PyProjectManager} and register it */ @ApiStatus.Internal package com.intellij.python.pyproject.model.spi; diff --git a/python/python-uv/backend/resources/intellij.python.uv.backend.xml b/python/python-uv/backend/resources/intellij.python.uv.backend.xml index 62c8d68aae4f..de08f5ab8aa2 100644 --- a/python/python-uv/backend/resources/intellij.python.uv.backend.xml +++ b/python/python-uv/backend/resources/intellij.python.uv.backend.xml @@ -13,6 +13,6 @@ - + diff --git a/python/python-uv/backend/src/com/intellij/python/uv/backend/UvTool.kt b/python/python-uv/backend/src/com/intellij/python/uv/backend/UvPyProjectManager.kt similarity index 98% rename from python/python-uv/backend/src/com/intellij/python/uv/backend/UvTool.kt rename to python/python-uv/backend/src/com/intellij/python/uv/backend/UvPyProjectManager.kt index 4419ffec5333..0f2de9bcd5cc 100644 --- a/python/python-uv/backend/src/com/intellij/python/uv/backend/UvTool.kt +++ b/python/python-uv/backend/src/com/intellij/python/uv/backend/UvPyProjectManager.kt @@ -11,7 +11,7 @@ import com.intellij.python.pyproject.model.spi.ProjectDependencies import com.intellij.python.pyproject.model.spi.ProjectName import com.intellij.python.pyproject.model.spi.ProjectStructureInfo import com.intellij.python.pyproject.model.spi.PyProjectTomlProject -import com.intellij.python.pyproject.model.spi.Tool +import com.intellij.python.pyproject.model.spi.PyProjectManager import com.intellij.python.uv.common.UV_TOOL_ID import com.intellij.python.uv.common.UV_UI_INFO import com.intellij.util.concurrency.annotations.RequiresBackgroundThread @@ -28,7 +28,7 @@ import java.nio.file.PathMatcher import kotlin.io.path.relativeTo -internal class UvTool : Tool { +internal class UvPyProjectManager : PyProjectManager { override val id: ToolId = UV_TOOL_ID