PY-86007 Run the Hatch CLI from the first existing parent folder in the path.

Initially, the ~/PycharmProjects folder does not exist. When we create the first project at ~/PycharmProjects/PythonProject, we can’t run Hatch from its parent folder and have to detect the actual root path instead.

GitOrigin-RevId: 89024b6c442ee46051bc0492609eab5928807ded
This commit is contained in:
Vitaly Legchilkin
2026-01-15 21:42:28 +00:00
committed by intellij-monorepo-bot
parent 8ca39f99c0
commit 898ca7f779
@@ -72,7 +72,7 @@ class HatchViewModel<P : PathHolder>(
val projectPath = projectPathFlows.projectPathWithDefault.first()
val hatchExecutablePath = (hatchExecutable as? BinOnEel)?.path
?: return@withContext Result.failure(HatchUIError.HatchExecutablePathIsNotValid(hatchExecutable.toString()))
val hatchWorkingDirectory = if (projectPath.isDirectory()) projectPath else projectPath.parent
val hatchWorkingDirectory = generateSequence(projectPath) { it.parent }.firstOrNull { it.isDirectory() }
val hatchService = hatchWorkingDirectory.getHatchService(hatchExecutablePath).getOr { return@withContext it }
val hatchEnvironments = hatchService.findVirtualEnvironments().getOr { return@withContext it }