mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-26373 Fixed separators handling in new virtualenv dialog for Windows
We store the default virtualenv location in the system-independent format so we have to convert to system-dependent separators when we show this path in the UI.
This commit is contained in:
@@ -18,6 +18,9 @@ package com.jetbrains.python.packaging;
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.SystemIndependent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -28,7 +31,7 @@ public class PyPackageService implements
|
||||
public volatile Map<String, Boolean> sdkToUsersite = ContainerUtil.newConcurrentMap();
|
||||
public volatile List<String> additionalRepositories = ContainerUtil.createConcurrentList();
|
||||
public volatile Map<String, String> PY_PACKAGES = ContainerUtil.newConcurrentMap();
|
||||
public volatile String virtualEnvBasePath;
|
||||
@SystemIndependent public volatile String virtualEnvBasePath;
|
||||
public volatile Boolean PYPI_REMOVED = false;
|
||||
|
||||
public long LAST_TIME_CHECKED = 0;
|
||||
@@ -76,11 +79,13 @@ public class PyPackageService implements
|
||||
return ServiceManager.getService(PyPackageService.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@SystemIndependent
|
||||
public String getVirtualEnvBasePath() {
|
||||
return virtualEnvBasePath;
|
||||
}
|
||||
|
||||
public void setVirtualEnvBasePath(String virtualEnvBasePath) {
|
||||
public void setVirtualEnvBasePath(@NotNull @SystemIndependent String virtualEnvBasePath) {
|
||||
this.virtualEnvBasePath = virtualEnvBasePath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ import com.jetbrains.python.sdk.createSdkByGenerateTask
|
||||
import com.jetbrains.python.sdk.findBaseSdks
|
||||
import com.jetbrains.python.sdk.flavors.VirtualEnvSdkFlavor
|
||||
import icons.PythonIcons
|
||||
import org.jetbrains.annotations.SystemDependent
|
||||
import org.jetbrains.annotations.SystemIndependent
|
||||
import org.jetbrains.jps.model.serialization.PathMacroUtil
|
||||
import java.awt.BorderLayout
|
||||
import java.io.File
|
||||
@@ -60,7 +62,7 @@ class PyAddNewVirtualEnvPanel(private val project: Project?,
|
||||
private const val VIRTUALENV_ROOT_DIR_MACRO_NAME = "VIRTUALENV_ROOT_DIR"
|
||||
}
|
||||
|
||||
var newProjectPath: String? = newProjectPath
|
||||
private var newProjectPath: String? = newProjectPath
|
||||
set(value) {
|
||||
field = value
|
||||
pathField.text = defaultBasePath
|
||||
@@ -146,7 +148,7 @@ class PyAddNewVirtualEnvPanel(private val project: Project?,
|
||||
private fun findProjectFromFocus(): Project? =
|
||||
CommonDataKeys.PROJECT.getData(DataManager.getInstance().dataContextFromFocus.resultSync)
|
||||
|
||||
private var defaultBasePath: String
|
||||
private var defaultBasePath: @SystemDependent String
|
||||
get() {
|
||||
val pathMap = ExpandMacroToPathMap().apply {
|
||||
addMacroExpand(PathMacroUtil.PROJECT_DIR_MACRO_NAME, projectBasePath)
|
||||
@@ -156,31 +158,34 @@ class PyAddNewVirtualEnvPanel(private val project: Project?,
|
||||
defaultVirtualEnvRoot != userHome -> defaultVirtualEnvRoot
|
||||
else -> "$${PathMacroUtil.PROJECT_DIR_MACRO_NAME}$/venv"
|
||||
}
|
||||
val rawSavedPath = PyPackageService.getInstance().virtualEnvBasePath ?: defaultPath
|
||||
val rawSavedPath = PyPackageService.getInstance().getVirtualEnvBasePath() ?: defaultPath
|
||||
val savedPath = pathMap.substitute(rawSavedPath, true)
|
||||
return when {
|
||||
val path = when {
|
||||
FileUtil.isAncestor(projectBasePath, savedPath, true) -> savedPath
|
||||
else -> "$savedPath/${PathUtil.getFileName(projectBasePath)}"
|
||||
}
|
||||
return FileUtil.toSystemDependentName(path)
|
||||
}
|
||||
set(value) {
|
||||
val path = FileUtil.toSystemIndependentName(value)
|
||||
val pathMap = ReplacePathToMacroMap().apply {
|
||||
addMacroReplacement(projectBasePath, PathMacroUtil.PROJECT_DIR_MACRO_NAME)
|
||||
addMacroReplacement(defaultVirtualEnvRoot, VIRTUALENV_ROOT_DIR_MACRO_NAME)
|
||||
}
|
||||
val pathToSave = when {
|
||||
FileUtil.isAncestor(projectBasePath, value, true) -> value.trimEnd { !it.isLetter() }
|
||||
else -> PathUtil.getParentPath(value)
|
||||
FileUtil.isAncestor(projectBasePath, path, true) -> path.trimEnd { !it.isLetter() }
|
||||
else -> PathUtil.getParentPath(path)
|
||||
}
|
||||
PyPackageService.getInstance().virtualEnvBasePath = pathMap.substitute(pathToSave, true)
|
||||
val substituted = pathMap.substitute(pathToSave, true)
|
||||
PyPackageService.getInstance().setVirtualEnvBasePath(substituted)
|
||||
}
|
||||
|
||||
private val defaultVirtualEnvRoot: String
|
||||
private val defaultVirtualEnvRoot: @SystemIndependent String
|
||||
get() = VirtualEnvSdkFlavor.getDefaultLocation()?.path ?: userHome
|
||||
|
||||
private val projectBasePath: String
|
||||
private val projectBasePath: @SystemIndependent String
|
||||
get() = newProjectPath ?: project?.basePath ?: userHome
|
||||
|
||||
private val userHome: String
|
||||
private val userHome: @SystemIndependent String
|
||||
get() = FileUtil.toSystemIndependentName(SystemProperties.getUserHome())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user