本文整理汇总了Java中com.jetbrains.python.sdk.PythonSdkType.getVirtualEnvRoot方法的典型用法代码示例。如果您正苦于以下问题:Java PythonSdkType.getVirtualEnvRoot方法的具体用法?Java PythonSdkType.getVirtualEnvRoot怎么用?Java PythonSdkType.getVirtualEnvRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jetbrains.python.sdk.PythonSdkType
的用法示例。
在下文中一共展示了PythonSdkType.getVirtualEnvRoot方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findVirtualEnvLibDir
import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
public static VirtualFile findVirtualEnvLibDir(Sdk sdk) {
VirtualFile[] classVFiles = sdk.getRootProvider().getFiles(OrderRootType.CLASSES);
String homePath = sdk.getHomePath();
if (homePath != null) {
File root = PythonSdkType.getVirtualEnvRoot(homePath);
if (root != null) {
File libRoot = new File(root, "lib");
File[] versionRoots = libRoot.listFiles();
if (versionRoots != null && versionRoots.length == 1) {
libRoot = versionRoots[0];
}
for (VirtualFile file : classVFiles) {
if (FileUtil.pathsEqual(file.getPath(), libRoot.getPath())) {
return file;
}
}
}
}
return null;
}
示例2: isValidSdkPath
import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
@Override
public boolean isValidSdkPath(@NotNull File file) {
if (!super.isValidSdkPath(file)) return false;
return PythonSdkType.getVirtualEnvRoot(file.getPath()) != null;
}
示例3: configureProject
import com.jetbrains.python.sdk.PythonSdkType; //导入方法依赖的package包/类
public void configureProject(final Project project, @NotNull final VirtualFile baseDir, Ref<Module> moduleRef) {
// it it a virtualenv?
final PythonSdkType sdkType = PythonSdkType.getInstance();
//find virtualEnv in project directory
final List<String> candidates = new ArrayList<String>();
if (project == null) return;
final VirtualFile rootDir = project.getBaseDir();
if (rootDir != null)
candidates.addAll(VirtualEnvSdkFlavor.findInDirectory(rootDir));
if (!candidates.isEmpty()) {
String filePath = candidates.get(0);
if (StringUtil.startsWithChar(filePath, '~')) {
final String home = SystemProperties.getUserHome();
filePath = home + filePath.substring(1);
}
final Sdk virtualEnvSdk = SdkConfigurationUtil.createAndAddSDK(filePath, sdkType);
if (virtualEnvSdk != null) {
SdkConfigurationUtil.setDirectoryProjectSdk(project, virtualEnvSdk);
SdkAdditionalData additionalData = virtualEnvSdk.getSdkAdditionalData();
if (additionalData == null) {
additionalData = new PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(virtualEnvSdk.getHomePath()));
((ProjectJdkImpl)virtualEnvSdk).setSdkAdditionalData(additionalData);
}
((PythonSdkAdditionalData) additionalData).associateWithProject(project);
return;
}
return;
}
final Sdk existingSdk = ProjectRootManager.getInstance(project).getProjectSdk();
if (existingSdk != null && existingSdk.getSdkType() == sdkType) return; // SdkConfigurationUtil does the same
final File executableFile = PythonSdkType.findExecutableFile(new File(project.getBasePath(), "bin"), "python");
if (executableFile != null) {
final File virtualEnvRoot = PythonSdkType.getVirtualEnvRoot(executableFile.getPath());
if (virtualEnvRoot != null) {
// yes, an unknown virtualenv; set it up as SDK
final Sdk sdk = SdkConfigurationUtil.createAndAddSDK(executableFile.getPath(), sdkType);
if (sdk != null) {
SdkConfigurationUtil.setDirectoryProjectSdk(project, sdk);
return;
}
}
}
// default
SdkConfigurationUtil.configureDirectoryProjectSdk(project, new PreferredSdkComparator(), sdkType);
}