use of com.jetbrains.python.packaging.PyPackageManager in project intellij-community by JetBrains.
the class VFSTestFrameworkListener method checkTestFrameworksInstalled.
@NotNull
private Map<String, Boolean> checkTestFrameworksInstalled(@Nullable Sdk sdk, @NotNull String... testPackageNames) {
final Map<String, Boolean> result = new HashMap<>();
if (sdk == null || StringUtil.isEmptyOrSpaces(sdk.getHomePath())) {
LOG.info("Searching test runner in empty sdk");
return result;
}
final PyPackageManager manager = PyPackageManager.getInstance(sdk);
final boolean refreshed = PyPackageUtil.updatePackagesSynchronouslyWithGuard(manager, myIsUpdating);
if (refreshed) {
final List<PyPackage> packages = manager.getPackages();
if (packages != null) {
for (String name : testPackageNames) {
result.put(name, PyPackageUtil.findPackage(packages, name) != null);
}
}
}
return result;
}
use of com.jetbrains.python.packaging.PyPackageManager in project intellij-community by JetBrains.
the class PyStudyDirectoryProjectGenerator method createAndAddVirtualEnv.
public void createAndAddVirtualEnv(Project project, PyNewProjectSettings settings) {
final ProjectSdksModel model = PyConfigurableInterpreterList.getInstance(project).getModel();
final String baseSdk = getBaseSdk(project);
if (baseSdk != null) {
final PyPackageManager packageManager = PyPackageManager.getInstance(new PyDetectedSdk(baseSdk));
try {
final String path = packageManager.createVirtualEnv(project.getBasePath() + "/.idea/VirtualEnvironment", false);
AbstractCreateVirtualEnvDialog.setupVirtualEnvSdk(path, true, new AbstractCreateVirtualEnvDialog.VirtualEnvCallback() {
@Override
public void virtualEnvCreated(Sdk createdSdk, boolean associateWithProject) {
settings.setSdk(createdSdk);
model.addSdk(createdSdk);
try {
model.apply();
} catch (ConfigurationException exception) {
LOG.error("Error adding created virtual env " + exception.getMessage());
}
if (associateWithProject) {
SdkAdditionalData additionalData = createdSdk.getSdkAdditionalData();
if (additionalData == null) {
additionalData = new PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(createdSdk.getHomePath()));
((ProjectJdkImpl) createdSdk).setSdkAdditionalData(additionalData);
}
((PythonSdkAdditionalData) additionalData).associateWithNewProject();
}
}
});
} catch (ExecutionException e) {
LOG.warn("Failed to create virtual env " + e.getMessage());
}
}
}
Aggregations