Search in sources :

Example 1 with PyPackageManager

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;
}
Also used : PyPackage(com.jetbrains.python.packaging.PyPackage) HashMap(java.util.HashMap) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PyPackageManager(com.jetbrains.python.packaging.PyPackageManager) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PyPackageManager

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());
        }
    }
}
Also used : ProjectSdksModel(com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) AbstractCreateVirtualEnvDialog(com.jetbrains.python.sdk.AbstractCreateVirtualEnvDialog) PyPackageManager(com.jetbrains.python.packaging.PyPackageManager) ConfigurationException(com.intellij.openapi.options.ConfigurationException) PyDetectedSdk(com.jetbrains.python.sdk.PyDetectedSdk) PyDetectedSdk(com.jetbrains.python.sdk.PyDetectedSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData)

Aggregations

PyPackageManager (com.jetbrains.python.packaging.PyPackageManager)2 ExecutionException (com.intellij.execution.ExecutionException)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 SdkAdditionalData (com.intellij.openapi.projectRoots.SdkAdditionalData)1 ProjectSdksModel (com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel)1 PyPackage (com.jetbrains.python.packaging.PyPackage)1 AbstractCreateVirtualEnvDialog (com.jetbrains.python.sdk.AbstractCreateVirtualEnvDialog)1 PyDetectedSdk (com.jetbrains.python.sdk.PyDetectedSdk)1 PythonSdkAdditionalData (com.jetbrains.python.sdk.PythonSdkAdditionalData)1 HashMap (java.util.HashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 NotNull (org.jetbrains.annotations.NotNull)1