diff --git a/python/src/com/jetbrains/python/projectModel/BaseProjectModelService.kt b/python/src/com/jetbrains/python/projectModel/BaseProjectModelService.kt index 7c10a53b6afe..63e0c1bb9064 100644 --- a/python/src/com/jetbrains/python/projectModel/BaseProjectModelService.kt +++ b/python/src/com/jetbrains/python/projectModel/BaseProjectModelService.kt @@ -124,6 +124,8 @@ abstract class BaseProjectModelService { /** * Removes the default IJ module created for the root of the project * (that's going to be replaced with a module belonging to a specific project management system). + * + * @see com.intellij.platform.PlatformProjectConfigurator */ fun removeFakeModuleEntity(project: Project, storage: MutableEntityStorage) { val virtualFileUrlManager = project.workspaceModel.getVirtualFileUrlManager() diff --git a/python/testSrc/com/jetbrains/python/projectModel/uv/PyUvOpenIntegrationTest.kt b/python/testSrc/com/jetbrains/python/projectModel/uv/PyUvOpenIntegrationTest.kt index 7f02a5d73719..8f7d9a82d9c6 100644 --- a/python/testSrc/com/jetbrains/python/projectModel/uv/PyUvOpenIntegrationTest.kt +++ b/python/testSrc/com/jetbrains/python/projectModel/uv/PyUvOpenIntegrationTest.kt @@ -4,6 +4,7 @@ package com.jetbrains.python.projectModel.uv import com.intellij.openapi.components.service import com.intellij.openapi.externalSystem.testFramework.fixtures.multiProjectFixture import com.intellij.platform.testFramework.assertion.collectionAssertion.CollectionAssertions +import com.intellij.platform.testFramework.assertion.moduleAssertion.ContentRootAssertions import com.intellij.platform.testFramework.assertion.moduleAssertion.DependencyAssertions import com.intellij.platform.testFramework.assertion.moduleAssertion.ModuleAssertions import com.intellij.testFramework.common.timeoutRunBlocking @@ -74,6 +75,33 @@ class PyUvOpenIntegrationTest { } } + @Test + fun `manually syncing a not recognized project removes its fake top-level module`() = timeoutRunBlocking(timeout = 20.seconds) { + val projectPath = testRoot.resolve("project") + + projectPath.createFile("pyproject.toml").writeText(""" + [project] + name = "myproject" + """.trimIndent()) + + multiprojectFixture.openProject(projectPath).useProjectAsync { project -> + // Nothing was linked automatically. There is only the module created by PlatformProjectConfigurator. + ModuleAssertions.assertModules(project, "project") + ContentRootAssertions.assertContentRoots(project, "project", listOf(projectPath)) + CollectionAssertions.assertEqualsUnordered(emptyList(), project.service().getLinkedProjects()) + + multiprojectFixture.awaitProjectConfiguration(project) { + UvProjectModelService.linkAllProjectModelRoots(project, project.basePath!!) + UvProjectModelService.syncAllProjectModelRoots(project) + } + + // Now there is only the module owned by Uv + ModuleAssertions.assertModules(project, "myproject") + CollectionAssertions.assertEqualsUnordered(listOf(projectPath), project.service().getLinkedProjects()) + ContentRootAssertions.assertContentRoots(project, "myproject", listOf(projectPath)) + } + } + @Test fun `test monorepo without top-level pyproject-toml and with sibling path dependency`() = timeoutRunBlocking(timeout = 20.seconds) { val projectPath = testRoot.resolve("project")